smartversion/ts/index.ts

60 lines
1.2 KiB
TypeScript
Raw Normal View History

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