mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-19 20:40:02 +00:00
Split out the parsing of semantic version strings
This commit is contained in:
parent
34ae1387a5
commit
026a27c1ab
35
boot/boot.js
35
boot/boot.js
@ -344,14 +344,35 @@ $tw.utils.resolvePath = function(sourcepath,rootpath) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Returns true if the `actual` version is greater than or equal to the `required` version. Both are in `x.y.z` format.
|
Parse a semantic version string into its constituent parts
|
||||||
*/
|
*/
|
||||||
$tw.utils.checkVersions = function(required,actual) {
|
$tw.utils.parseVersion = function(version) {
|
||||||
var targetVersion = required.split("."),
|
var match = /^((\d+)\.(\d+)\.(\d+))(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?$/.exec(version);
|
||||||
currVersion = actual.split("."),
|
if(match) {
|
||||||
diff = [parseInt(targetVersion[0],10) - parseInt(currVersion[0],10),
|
return {
|
||||||
parseInt(targetVersion[1],10) - parseInt(currVersion[1],10),
|
version: match[1],
|
||||||
parseInt(targetVersion[2],10) - parseInt(currVersion[2],10)];
|
major: parseInt(match[2],10),
|
||||||
|
minor: parseInt(match[3],10),
|
||||||
|
patch: parseInt(match[4],10),
|
||||||
|
prerelease: match[5],
|
||||||
|
build: match[6]
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Returns true if the version string A is greater than the version string B
|
||||||
|
*/
|
||||||
|
$tw.utils.checkVersions = function(versionStringA,versionStringB) {
|
||||||
|
var versionA = $tw.utils.parseVersion(versionStringA),
|
||||||
|
versionB = $tw.utils.parseVersion(versionStringB),
|
||||||
|
diff = [
|
||||||
|
versionA.major - versionB.major,
|
||||||
|
versionA.minor - versionB.minor,
|
||||||
|
versionA.patch - versionB.patch
|
||||||
|
];
|
||||||
return (diff[0] > 0) ||
|
return (diff[0] > 0) ||
|
||||||
(diff[0] === 0 && diff[1] > 0) ||
|
(diff[0] === 0 && diff[1] > 0) ||
|
||||||
(diff[0] === 0 && diff[1] === 0 && diff[2] > 0);
|
(diff[0] === 0 && diff[1] === 0 && diff[2] > 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user