smartversion/ts/index.ts

59 lines
1.3 KiB
TypeScript
Raw Normal View History

import * as plugins from './smartversion.plugins';
2017-08-17 14:15:47 +00:00
import { SemVer } from 'semver';
2017-08-17 14:15:47 +00:00
export class SmartVersion {
semver: SemVer;
versionString: string;
2017-08-17 14:15:47 +00:00
update = {
patch: () => {
this.semver.patch = this.semver.patch + 1;
2017-08-17 14:15:47 +00:00
},
minor: () => {
this.semver.minor = this.semver.minor + 1;
2017-08-17 14:15:47 +00:00
},
major: () => {
this.semver.major = this.semver.major + 1;
2017-08-17 14:15:47 +00:00
}
};
2017-08-17 14:15:47 +00:00
constructor(semVerStringArg: string) {
this.semver = new plugins.semver.SemVer(semVerStringArg);
this.versionString = this.semver.version;
2017-08-17 14:15:47 +00:00
}
get major() {
return this.semver.major;
2017-08-17 14:15:47 +00:00
}
get minor() {
return this.semver.minor;
2017-08-17 14:15:47 +00:00
}
get patch() {
return this.semver.patch;
2017-08-17 14:15:47 +00:00
}
greaterThan(smartVersionArg: SmartVersion) {
return this.greaterThanString(smartVersionArg.versionString);
}
/**
* compares the version of this against a string
*/
greaterThanString(versionStringArg) {
return plugins.semver.gt(this.versionString, versionStringArg);
2017-08-18 08:58:00 +00:00
}
lessThan(smartVersionArg: SmartVersion) {
return this.lessThanString(smartVersionArg.versionString);
}
/**
* compares the version of this against a string
*/
lessThanString(versionStringArg) {
return plugins.semver.lt(this.versionString, versionStringArg);
2017-08-18 08:58:00 +00:00
}
2017-08-17 14:15:47 +00:00
}