BVB Source Codes

reactide Show util.js Source code

Return Download reactide: download util.js Source code - Download reactide Source code - Type:.js
  1. "use strict";
  2.  
  3. exports.__esModule = true;
  4. exports.inspect = exports.inherits = undefined;
  5.  
  6. var _getIterator2 = require("babel-runtime/core-js/get-iterator");
  7.  
  8. var _getIterator3 = _interopRequireDefault(_getIterator2);
  9.  
  10. var _util = require("util");
  11.  
  12. Object.defineProperty(exports, "inherits", {
  13.   enumerable: true,
  14.   get: function get() {
  15.     return _util.inherits;
  16.   }
  17. });
  18. Object.defineProperty(exports, "inspect", {
  19.   enumerable: true,
  20.   get: function get() {
  21.     return _util.inspect;
  22.   }
  23. });
  24. exports.canCompile = canCompile;
  25. exports.list = list;
  26. exports.regexify = regexify;
  27. exports.arrayify = arrayify;
  28. exports.booleanify = booleanify;
  29. exports.shouldIgnore = shouldIgnore;
  30.  
  31. var _escapeRegExp = require("lodash/escapeRegExp");
  32.  
  33. var _escapeRegExp2 = _interopRequireDefault(_escapeRegExp);
  34.  
  35. var _startsWith = require("lodash/startsWith");
  36.  
  37. var _startsWith2 = _interopRequireDefault(_startsWith);
  38.  
  39. var _isBoolean = require("lodash/isBoolean");
  40.  
  41. var _isBoolean2 = _interopRequireDefault(_isBoolean);
  42.  
  43. var _minimatch = require("minimatch");
  44.  
  45. var _minimatch2 = _interopRequireDefault(_minimatch);
  46.  
  47. var _includes = require("lodash/includes");
  48.  
  49. var _includes2 = _interopRequireDefault(_includes);
  50.  
  51. var _isString = require("lodash/isString");
  52.  
  53. var _isString2 = _interopRequireDefault(_isString);
  54.  
  55. var _isRegExp = require("lodash/isRegExp");
  56.  
  57. var _isRegExp2 = _interopRequireDefault(_isRegExp);
  58.  
  59. var _path = require("path");
  60.  
  61. var _path2 = _interopRequireDefault(_path);
  62.  
  63. var _slash = require("slash");
  64.  
  65. var _slash2 = _interopRequireDefault(_slash);
  66.  
  67. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  68.  
  69. /**
  70.  * Test if a filename ends with a compilable extension.
  71.  */
  72.  
  73. function canCompile(filename, altExts) {
  74.   var exts = altExts || canCompile.EXTENSIONS;
  75.   var ext = _path2.default.extname(filename);
  76.   return (0, _includes2.default)(exts, ext);
  77. }
  78.  
  79. /**
  80.  * Default set of compilable extensions.
  81.  */
  82.  
  83. canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
  84.  
  85. /**
  86.  * Create an array from any value, splitting strings by ",".
  87.  */
  88.  
  89. function list(val) {
  90.   if (!val) {
  91.     return [];
  92.   } else if (Array.isArray(val)) {
  93.     return val;
  94.   } else if (typeof val === "string") {
  95.     return val.split(",");
  96.   } else {
  97.     return [val];
  98.   }
  99. }
  100.  
  101. /**
  102.  * Create a RegExp from a string, array, or regexp.
  103.  */
  104.  
  105. function regexify(val) {
  106.   if (!val) {
  107.     return new RegExp(/.^/);
  108.   }
  109.  
  110.   if (Array.isArray(val)) {
  111.     val = new RegExp(val.map(_escapeRegExp2.default).join("|"), "i");
  112.   }
  113.  
  114.   if (typeof val === "string") {
  115.     // normalise path separators
  116.     val = (0, _slash2.default)(val);
  117.  
  118.     // remove starting wildcards or relative separator if present
  119.     if ((0, _startsWith2.default)(val, "./") || (0, _startsWith2.default)(val, "*/")) val = val.slice(2);
  120.     if ((0, _startsWith2.default)(val, "**/")) val = val.slice(3);
  121.  
  122.     var regex = _minimatch2.default.makeRe(val, { nocase: true });
  123.     return new RegExp(regex.source.slice(1, -1), "i");
  124.   }
  125.  
  126.   if ((0, _isRegExp2.default)(val)) {
  127.     return val;
  128.   }
  129.  
  130.   throw new TypeError("illegal type for regexify");
  131. }
  132.  
  133. /**
  134.  * Create an array from a boolean, string, or array, mapped by and optional function.
  135.  */
  136.  
  137. function arrayify(val, mapFn) {
  138.   if (!val) return [];
  139.   if ((0, _isBoolean2.default)(val)) return arrayify([val], mapFn);
  140.   if ((0, _isString2.default)(val)) return arrayify(list(val), mapFn);
  141.  
  142.   if (Array.isArray(val)) {
  143.     if (mapFn) val = val.map(mapFn);
  144.     return val;
  145.   }
  146.  
  147.   return [val];
  148. }
  149.  
  150. /**
  151.  * Makes boolean-like strings into booleans.
  152.  */
  153.  
  154. function booleanify(val) {
  155.   if (val === "true" || val == 1) {
  156.     return true;
  157.   }
  158.  
  159.   if (val === "false" || val == 0 || !val) {
  160.     return false;
  161.   }
  162.  
  163.   return val;
  164. }
  165.  
  166. /**
  167.  * Tests if a filename should be ignored based on "ignore" and "only" options.
  168.  */
  169.  
  170. function shouldIgnore(filename) {
  171.   var ignore = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
  172.   var only = arguments[2];
  173.  
  174.   filename = (0, _slash2.default)(filename);
  175.  
  176.   if (only) {
  177.     for (var _iterator = only, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  178.       var _ref;
  179.  
  180.       if (_isArray) {
  181.         if (_i >= _iterator.length) break;
  182.         _ref = _iterator[_i++];
  183.       } else {
  184.         _i = _iterator.next();
  185.         if (_i.done) break;
  186.         _ref = _i.value;
  187.       }
  188.  
  189.       var pattern = _ref;
  190.  
  191.       if (_shouldIgnore(pattern, filename)) return false;
  192.     }
  193.     return true;
  194.   } else if (ignore.length) {
  195.     for (var _iterator2 = ignore, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
  196.       var _ref2;
  197.  
  198.       if (_isArray2) {
  199.         if (_i2 >= _iterator2.length) break;
  200.         _ref2 = _iterator2[_i2++];
  201.       } else {
  202.         _i2 = _iterator2.next();
  203.         if (_i2.done) break;
  204.         _ref2 = _i2.value;
  205.       }
  206.  
  207.       var _pattern = _ref2;
  208.  
  209.       if (_shouldIgnore(_pattern, filename)) return true;
  210.     }
  211.   }
  212.  
  213.   return false;
  214. }
  215.  
  216. /**
  217.  * Returns result of calling function with filename if pattern is a function.
  218.  * Otherwise returns result of matching pattern Regex with filename.
  219.  */
  220.  
  221. function _shouldIgnore(pattern, filename) {
  222.   if (typeof pattern === "function") {
  223.     return pattern(filename);
  224.   } else {
  225.     return pattern.test(filename);
  226.   }
  227. }
downloadutil.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top