update to support compare functions
This commit is contained in:
parent
ea6fc17f21
commit
79b0448444
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,6 +1,7 @@
|
|||||||
import { SemVer } from 'semver';
|
import { SemVer } from 'semver';
|
||||||
export declare class SmartVersion {
|
export declare class SmartVersion {
|
||||||
semver: SemVer;
|
semver: SemVer;
|
||||||
|
versionString: string;
|
||||||
update: {
|
update: {
|
||||||
patch: () => void;
|
patch: () => void;
|
||||||
minor: () => void;
|
minor: () => void;
|
||||||
@ -10,4 +11,6 @@ export declare class SmartVersion {
|
|||||||
readonly major: number;
|
readonly major: number;
|
||||||
readonly minor: number;
|
readonly minor: number;
|
||||||
readonly patch: number;
|
readonly patch: number;
|
||||||
|
greaterThanString(versionStringArg: any): boolean;
|
||||||
|
lessThanString(versionStringArg: any): boolean;
|
||||||
}
|
}
|
||||||
|
9
dist/index.js
vendored
9
dist/index.js
vendored
@ -15,6 +15,7 @@ class SmartVersion {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.semver = new plugins.semver.SemVer(semVerStringArg);
|
this.semver = new plugins.semver.SemVer(semVerStringArg);
|
||||||
|
this.versionString = this.semver.version;
|
||||||
}
|
}
|
||||||
get major() {
|
get major() {
|
||||||
return this.semver.major;
|
return this.semver.major;
|
||||||
@ -25,6 +26,12 @@ class SmartVersion {
|
|||||||
get patch() {
|
get patch() {
|
||||||
return this.semver.patch;
|
return this.semver.patch;
|
||||||
}
|
}
|
||||||
|
greaterThanString(versionStringArg) {
|
||||||
|
return plugins.semver.gt(this.versionString, versionStringArg);
|
||||||
|
}
|
||||||
|
lessThanString(versionStringArg) {
|
||||||
|
return plugins.semver.lt(this.versionString, versionStringArg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exports.SmartVersion = SmartVersion;
|
exports.SmartVersion = SmartVersion;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290Ijoi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M7SUFFRCxpQkFBaUIsQ0FBRSxnQkFBZ0I7UUFDakMsTUFBTSxDQUFDLE9BQU8sQ0FBQyxNQUFNLENBQUMsRUFBRSxDQUFDLElBQUksQ0FBQyxhQUFhLEVBQUUsZ0JBQWdCLENBQUMsQ0FBQTtJQUNoRSxDQUFDO0lBRUQsY0FBYyxDQUFFLGdCQUFnQjtRQUM5QixNQUFNLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQyxFQUFFLENBQUMsSUFBSSxDQUFDLGFBQWEsRUFBRSxnQkFBZ0IsQ0FBQyxDQUFBO0lBQ2hFLENBQUM7Q0FFRjtBQXhDRCxvQ0F3Q0MifQ==
|
12
test/test.ts
12
test/test.ts
@ -7,4 +7,16 @@ tap.test('should create a valid SmartVersion', async () => {
|
|||||||
expect(localSmartVersion).to.be.instanceof(smartversion.SmartVersion)
|
expect(localSmartVersion).to.be.instanceof(smartversion.SmartVersion)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
tap.test('should correctly classify greater and less than', async () => {
|
||||||
|
// tslint:disable-next-line:no-unused-expression
|
||||||
|
expect(localSmartVersion.greaterThanString('4.0.0')).to.be.false
|
||||||
|
// tslint:disable-next-line:no-unused-expression
|
||||||
|
expect(localSmartVersion.greaterThanString('3.0.0')).to.be.true
|
||||||
|
// tslint:disable-next-line:no-unused-expression
|
||||||
|
expect(localSmartVersion.lessThanString('v4.0.0')).to.be.true
|
||||||
|
// tslint:disable-next-line:no-unused-expression
|
||||||
|
expect(localSmartVersion.lessThanString('v3.0.0')).to.be.false
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
tap.start()
|
tap.start()
|
||||||
|
10
ts/index.ts
10
ts/index.ts
@ -4,6 +4,7 @@ import { SemVer } from 'semver'
|
|||||||
|
|
||||||
export class SmartVersion {
|
export class SmartVersion {
|
||||||
semver: SemVer
|
semver: SemVer
|
||||||
|
versionString: string
|
||||||
update = {
|
update = {
|
||||||
patch: () => {
|
patch: () => {
|
||||||
this.semver.patch = this.semver.patch + 1
|
this.semver.patch = this.semver.patch + 1
|
||||||
@ -18,6 +19,7 @@ export class SmartVersion {
|
|||||||
|
|
||||||
constructor (semVerStringArg: string) {
|
constructor (semVerStringArg: string) {
|
||||||
this.semver = new plugins.semver.SemVer(semVerStringArg)
|
this.semver = new plugins.semver.SemVer(semVerStringArg)
|
||||||
|
this.versionString = this.semver.version
|
||||||
}
|
}
|
||||||
|
|
||||||
get major () {
|
get major () {
|
||||||
@ -32,4 +34,12 @@ export class SmartVersion {
|
|||||||
return this.semver.patch
|
return this.semver.patch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
greaterThanString (versionStringArg) {
|
||||||
|
return plugins.semver.gt(this.versionString, versionStringArg)
|
||||||
|
}
|
||||||
|
|
||||||
|
lessThanString (versionStringArg) {
|
||||||
|
return plugins.semver.lt(this.versionString, versionStringArg)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user