Add api to compare versions

This commit is contained in:
Ilya Ig. Petrov 2017-10-31 17:25:56 +05:00
parent 56a0daf635
commit b0f826dab6

View File

@ -198,10 +198,20 @@
}; };
const max = 2**16;
const versionToArray = (v) => [ ...v.split('.'), 0, 0, 0].slice(0,4);
const versionToInt = (v) => versionToArray(v)
.reverse()
.reduce((acc, vv, i) => acc + parseInt(vv)*(max**i), 0);
const compareVersions = (a, b) => versionToInt(a) - versionToInt(b);
window.apis = { window.apis = {
version: { version: {
ifMini: false, ifMini: false,
build: chrome.runtime.getManifest().version.replace(/\d+\.\d+\./g, ''), build: chrome.runtime.getManifest().version.replace(/\d+\.\d+\./g, ''),
isLeq: (a, b) => compareVersions(a, b) <= 0,
}, },
}; };