forked from Rughalt/D35E
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsemver.js
42 lines (38 loc) · 1.51 KB
/
semver.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
42
export class SemanticVersion {
static re = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
constructor() {
this.major = 0;
this.minor = 0;
this.patch = 0;
this.preRelease = "";
this.buildMetaData = "";
}
static fromString(str) {
if (str.match(this.re)) {
let result = new this();
result.major = parseInt(RegExp.$1);
result.minor = parseInt(RegExp.$2);
result.patch = parseInt(RegExp.$3);
result.preRelease = RegExp.$4 || "";
result.buildMetaData = RegExp.$5 || "";
return result;
}
return null;
}
isHigherThan(otherVersion) {
if (this.major > otherVersion.major) return true;
if (this.major === otherVersion.major && this.minor > otherVersion.minor) return true;
if (this.major === otherVersion.major
&& this.minor === otherVersion.minor
&& this.patch > otherVersion.patch) return true;
return false;
}
isLowerThan(otherVersion) {
if (this.major < otherVersion.major) return true;
if (this.major === otherVersion.major && this.minor < otherVersion.minor) return true;
if (this.major === otherVersion.major
&& this.minor === otherVersion.minor
&& this.patch < otherVersion.patch) return true;
return false;
}
}