-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsemver.js
40 lines (36 loc) · 799 Bytes
/
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
"use strict";
var reSemver =
/^v?((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?$/;
module.exports = {
parseSemver: function (version) {
var m = reSemver.exec(version) || [];
if (0 === m.length) {
return;
} else {
return {
semver: m[0],
version: m[1],
major: m[2],
minor: m[3],
patch: m[4],
release: m[5],
build: m[6],
};
}
},
stringifySemver: function (obj) {
var str = "";
str += obj.major || "0";
str += ".";
str += obj.minor || "0";
str += ".";
str += obj.patch || "0";
if (obj.release) {
str += "-" + obj.release;
}
if (obj.build) {
str += "+" + obj.build;
}
return str;
},
};