core.js
1.61 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
function specifierIncluded(specifier) {
var parts = specifier.split(' ');
var op = parts.length > 1 ? parts[0] : '=';
var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.');
for (var i = 0; i < 3; ++i) {
var cur = parseInt(current[i] || 0, 10);
var ver = parseInt(versionParts[i] || 0, 10);
if (cur === ver) {
continue; // eslint-disable-line no-restricted-syntax, no-continue
}
if (op === '<') {
return cur < ver;
} else if (op === '>=') {
return cur >= ver;
}
return false;
}
return op === '>=';
}
function matchesRange(range) {
var specifiers = range.split(/ ?&& ?/);
if (specifiers.length === 0) { return false; }
for (var i = 0; i < specifiers.length; ++i) {
if (!specifierIncluded(specifiers[i])) { return false; }
}
return true;
}
function versionIncluded(specifierValue) {
if (typeof specifierValue === 'boolean') { return specifierValue; }
if (specifierValue && typeof specifierValue === 'object') {
for (var i = 0; i < specifierValue.length; ++i) {
if (matchesRange(specifierValue[i])) { return true; }
}
return false;
}
return matchesRange(specifierValue);
}
var data = require('./core.json');
var core = {};
for (var mod in data) { // eslint-disable-line no-restricted-syntax
if (Object.prototype.hasOwnProperty.call(data, mod)) {
core[mod] = versionIncluded(data[mod]);
}
}
module.exports = core;