1'use strict'; 2 3var hasOwn = require('hasown'); 4 5function specifierIncluded(current, specifier) { 6 var nodeParts = current.split('.'); 7 var parts = specifier.split(' '); 8 var op = parts.length > 1 ? parts[0] : '='; 9 var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.'); 10 11 for (var i = 0; i < 3; ++i) { 12 var cur = parseInt(nodeParts[i] || 0, 10); 13 var ver = parseInt(versionParts[i] || 0, 10); 14 if (cur === ver) { 15 continue; // eslint-disable-line no-restricted-syntax, no-continue 16 } 17 if (op === '<') { 18 return cur < ver; 19 } 20 if (op === '>=') { 21 return cur >= ver; 22 } 23 return false; 24 } 25 return op === '>='; 26} 27 28function matchesRange(current, range) { 29 var specifiers = range.split(/ ?&& ?/); 30 if (specifiers.length === 0) { 31 return false; 32 } 33 for (var i = 0; i < specifiers.length; ++i) { 34 if (!specifierIncluded(current, specifiers[i])) { 35 return false; 36 } 37 } 38 return true; 39} 40 41function versionIncluded(nodeVersion, specifierValue) { 42 if (typeof specifierValue === 'boolean') { 43 return specifierValue; 44 } 45 46 var current = typeof nodeVersion === 'undefined' 47 ? process.versions && process.versions.node 48 : nodeVersion; 49 50 if (typeof current !== 'string') { 51 throw new TypeError(typeof nodeVersion === 'undefined' ? 'Unable to determine current node version' : 'If provided, a valid node version is required'); 52 } 53 54 if (specifierValue && typeof specifierValue === 'object') { 55 for (var i = 0; i < specifierValue.length; ++i) { 56 if (matchesRange(current, specifierValue[i])) { 57 return true; 58 } 59 } 60 return false; 61 } 62 return matchesRange(current, specifierValue); 63} 64 65var data = require('./core.json'); 66 67module.exports = function isCore(x, nodeVersion) { 68 return hasOwn(data, x) && versionIncluded(nodeVersion, data[x]); 69}; 70