underscript.semver
Compare versions. Each method compares a version you give it to a second version, current, which defaults to the version of UnderScript that is running. That makes it useful for checking if a feature exists.
meets and isBehind read naturally when current is UnderScript: “does UnderScript meet 0.65.0?” is meets('0.65.0'). The functions isNewer, isOlder, and atLeast describe the version you pass, compared to current, so the same question is answered by isOlder('0.65.0').
Syntax
underscript.semver.meets(version, current);
underscript.semver.isBehind(version, current);
underscript.semver.isNewer(version, current);
underscript.semver.isOlder(version, current);
underscript.semver.atLeast(version, current);
underscript.semver.compare(newer, current);
- meets
trueifcurrentisversionor newer. Whencurrentis UnderScript, that means UnderScript has everything fromversion.- isBehind
trueifcurrentis older thanversion. Whencurrentis UnderScript, that means UnderScript is too old.- isNewer
trueifversionis newer thancurrent. Same result asisBehind.- isOlder
trueifversionis older than, or the same as,current. Same result asmeets.- atLeast
trueifversionis newer than, or the same as,current- compare
trueifneweris newer thancurrent,falseif it is older, andundefinedif they are the same. Both versions are required.
Local builds of UnderScript count as newer than everything.
Examples
// Is UnderScript at least 0.65.0?
if (underscript.semver.meets('0.65.0')) {
// Use something added in 0.65.0
}
// Is UnderScript too old for my plugin?
if (underscript.semver.isBehind('0.65.0')) {
console.log('Please update UnderScript!');
}
underscript.semver.isNewer('1.2.0', '1.1.9'); // true