-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict"; | ||
|
||
let version = { | ||
'getLatest': (vPre, vNew) => { | ||
if (!vPre) | ||
return vNew; | ||
|
||
if (version.validate(vPre) && version.validate(vNew)) { | ||
let vNewNb = parseFloat(vNew); | ||
let vPreNb = parseFloat(vPre); | ||
|
||
if (vNewNb > vPreNb) | ||
return vNew; | ||
} | ||
return vPre; | ||
}, | ||
|
||
'isLatest': (vSrc, vCom) => { | ||
if (version.validate(vSrc) && version.validate(vCom)) { | ||
let vSrcNb = parseFloat(vSrc); | ||
let vComNb = parseFloat(vCom); | ||
|
||
if (vSrcNb > vComNb) | ||
return true; | ||
} | ||
return false; | ||
}, | ||
|
||
'validate': (ver) => { | ||
if (ver) { | ||
if (typeof ver !== 'string') | ||
ver = "" + ver; | ||
let matches = ver.match(/[0-9]+(.[0-9]+)?/); | ||
if (matches && matches.length > 0) { | ||
return true; | ||
} | ||
} | ||
return false | ||
} | ||
}; | ||
|
||
module.exports = version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"use strict"; | ||
let assert = require('assert'); | ||
let helper = require("../helper.js"); | ||
|
||
var utils = helper.requireModule('./lib/version'); | ||
|
||
describe("testing version", function () { | ||
|
||
|
||
let version1 = "1.0"; | ||
let version2 = "1.2"; | ||
let wrongVersion = "b.a.3"; | ||
|
||
it("testing getLatest", function (done) { | ||
let ver = utils.getLatest(version1, version2); | ||
assert.ok(ver); | ||
assert.equal(ver, version2); | ||
done(); | ||
}); | ||
it("testing getLatest with null version", function (done) { | ||
let ver = utils.getLatest(null, version2); | ||
assert.ok(ver); | ||
assert.equal(ver, version2); | ||
done(); | ||
}); | ||
it("testing getLatest with wrong version", function (done) { | ||
let ver = utils.getLatest(wrongVersion, version2); | ||
assert.ok(ver); | ||
assert.equal(ver, wrongVersion); | ||
done(); | ||
}); | ||
|
||
|
||
it("testing isLatest - false", function (done) { | ||
let ver = utils.isLatest(version1, version2); | ||
assert.ok(!ver); | ||
done(); | ||
}); | ||
it("testing isLatest - true", function (done) { | ||
let ver = utils.isLatest(version2, version1); | ||
assert.ok(ver); | ||
done(); | ||
}); | ||
it("testing isLatest with null", function (done) { | ||
let ver = utils.isLatest(null, version2); | ||
assert.ok(!ver); | ||
done(); | ||
}); | ||
|
||
|
||
it("testing validate not string", function (done) { | ||
let ver = utils.validate(1); | ||
assert.ok(ver); | ||
done(); | ||
}); | ||
it("testing validate null", function (done) { | ||
let ver = utils.validate(null); | ||
assert.ok(!ver); | ||
done(); | ||
}); | ||
}); |