1 | var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
|
---|
2 |
|
---|
3 | function specifierIncluded(specifier) {
|
---|
4 | var parts = specifier.split(' ');
|
---|
5 | var op = parts.length > 1 ? parts[0] : '=';
|
---|
6 | var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.');
|
---|
7 |
|
---|
8 | for (var i = 0; i < 3; ++i) {
|
---|
9 | var cur = parseInt(current[i] || 0, 10);
|
---|
10 | var ver = parseInt(versionParts[i] || 0, 10);
|
---|
11 | if (cur === ver) {
|
---|
12 | continue; // eslint-disable-line no-restricted-syntax, no-continue
|
---|
13 | }
|
---|
14 | if (op === '<') {
|
---|
15 | return cur < ver;
|
---|
16 | } else if (op === '>=') {
|
---|
17 | return cur >= ver;
|
---|
18 | } else {
|
---|
19 | return false;
|
---|
20 | }
|
---|
21 | }
|
---|
22 | return op === '>=';
|
---|
23 | }
|
---|
24 |
|
---|
25 | function matchesRange(range) {
|
---|
26 | var specifiers = range.split(/ ?&& ?/);
|
---|
27 | if (specifiers.length === 0) { return false; }
|
---|
28 | for (var i = 0; i < specifiers.length; ++i) {
|
---|
29 | if (!specifierIncluded(specifiers[i])) { return false; }
|
---|
30 | }
|
---|
31 | return true;
|
---|
32 | }
|
---|
33 |
|
---|
34 | function versionIncluded(specifierValue) {
|
---|
35 | if (typeof specifierValue === 'boolean') { return specifierValue; }
|
---|
36 | if (specifierValue && typeof specifierValue === 'object') {
|
---|
37 | for (var i = 0; i < specifierValue.length; ++i) {
|
---|
38 | if (matchesRange(specifierValue[i])) { return true; }
|
---|
39 | }
|
---|
40 | return false;
|
---|
41 | }
|
---|
42 | return matchesRange(specifierValue);
|
---|
43 | }
|
---|
44 |
|
---|
45 | var data = require('./core.json');
|
---|
46 |
|
---|
47 | var core = {};
|
---|
48 | for (var mod in data) { // eslint-disable-line no-restricted-syntax
|
---|
49 | if (Object.prototype.hasOwnProperty.call(data, mod)) {
|
---|
50 | core[mod] = versionIncluded(data[mod]);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | module.exports = core;
|
---|