-
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Refactor] deprecated
lib/core.js
now uses is-core-module
- Loading branch information
Showing
1 changed file
with
3 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,12 @@ | ||
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); | ||
} | ||
'use strict'; | ||
|
||
var isCoreModule = require('is-core-module'); | ||
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]); | ||
core[mod] = isCoreModule(mod); | ||
} | ||
} | ||
module.exports = core; |