-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.js
41 lines (37 loc) · 1.17 KB
/
version.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Version class for checking release versions; adjusted from jskos-server
export default class Version {
constructor(version) {
if (version.startsWith("v")) {
version = version.slice(1)
}
this.version = version
const [major = 0, minor = 0, patch = 0] = version.split(".").map(v => parseInt(v))
this.major = major
this.minor = minor
this.patch = patch
}
gt(version) {
version = Version.from(version)
return this.major > version.major ||
(this.major == version.major && this.minor > version.minor) ||
(this.major == version.major && this.minor == version.minor && this.patch > version.patch)
}
gte(version) {
version = Version.from(version)
return this.major > version.major ||
(this.major == version.major && this.minor > version.minor) ||
(this.major == version.major && this.minor == version.minor && this.patch >= version.patch)
}
eq(version) {
return !this.lt(version) && !this.gt(version)
}
lt(version) {
return !this.gte(version)
}
lte(version) {
return !this.gt(version)
}
static from(version) {
return version instanceof Version ? version : new Version(version)
}
}