core.js 1.6 KB

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