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 _minimatch = require("minimatch");
  40.  
  41. var _minimatch2 = _interopRequireDefault(_minimatch);
  42.  
  43. var _includes = require("lodash/includes");
  44.  
  45. var _includes2 = _interopRequireDefault(_includes);
  46.  
  47. var _isRegExp = require("lodash/isRegExp");
  48.  
  49. var _isRegExp2 = _interopRequireDefault(_isRegExp);
  50.  
  51. var _path = require("path");
  52.  
  53. var _path2 = _interopRequireDefault(_path);
  54.  
  55. var _slash = require("slash");
  56.  
  57. var _slash2 = _interopRequireDefault(_slash);
  58.  
  59. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  60.  
  61. function canCompile(filename, altExts) {
  62.   var exts = altExts || canCompile.EXTENSIONS;
  63.   var ext = _path2.default.extname(filename);
  64.   return (0, _includes2.default)(exts, ext);
  65. }
  66.  
  67. canCompile.EXTENSIONS = [".js", ".jsx", ".es6", ".es"];
  68.  
  69. function list(val) {
  70.   if (!val) {
  71.     return [];
  72.   } else if (Array.isArray(val)) {
  73.     return val;
  74.   } else if (typeof val === "string") {
  75.     return val.split(",");
  76.   } else {
  77.     return [val];
  78.   }
  79. }
  80.  
  81. function regexify(val) {
  82.   if (!val) {
  83.     return new RegExp(/.^/);
  84.   }
  85.  
  86.   if (Array.isArray(val)) {
  87.     val = new RegExp(val.map(_escapeRegExp2.default).join("|"), "i");
  88.   }
  89.  
  90.   if (typeof val === "string") {
  91.     val = (0, _slash2.default)(val);
  92.  
  93.     if ((0, _startsWith2.default)(val, "./") || (0, _startsWith2.default)(val, "*/")) val = val.slice(2);
  94.     if ((0, _startsWith2.default)(val, "**/")) val = val.slice(3);
  95.  
  96.     var regex = _minimatch2.default.makeRe(val, { nocase: true });
  97.     return new RegExp(regex.source.slice(1, -1), "i");
  98.   }
  99.  
  100.   if ((0, _isRegExp2.default)(val)) {
  101.     return val;
  102.   }
  103.  
  104.   throw new TypeError("illegal type for regexify");
  105. }
  106.  
  107. function arrayify(val, mapFn) {
  108.   if (!val) return [];
  109.   if (typeof val === "boolean") return arrayify([val], mapFn);
  110.   if (typeof val === "string") return arrayify(list(val), mapFn);
  111.  
  112.   if (Array.isArray(val)) {
  113.     if (mapFn) val = val.map(mapFn);
  114.     return val;
  115.   }
  116.  
  117.   return [val];
  118. }
  119.  
  120. function booleanify(val) {
  121.   if (val === "true" || val == 1) {
  122.     return true;
  123.   }
  124.  
  125.   if (val === "false" || val == 0 || !val) {
  126.     return false;
  127.   }
  128.  
  129.   return val;
  130. }
  131.  
  132. function shouldIgnore(filename) {
  133.   var ignore = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  134.   var only = arguments[2];
  135.  
  136.   filename = filename.replace(/\\/g, "/");
  137.  
  138.   if (only) {
  139.     for (var _iterator = only, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator3.default)(_iterator);;) {
  140.       var _ref;
  141.  
  142.       if (_isArray) {
  143.         if (_i >= _iterator.length) break;
  144.         _ref = _iterator[_i++];
  145.       } else {
  146.         _i = _iterator.next();
  147.         if (_i.done) break;
  148.         _ref = _i.value;
  149.       }
  150.  
  151.       var pattern = _ref;
  152.  
  153.       if (_shouldIgnore(pattern, filename)) return false;
  154.     }
  155.     return true;
  156.   } else if (ignore.length) {
  157.     for (var _iterator2 = ignore, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) {
  158.       var _ref2;
  159.  
  160.       if (_isArray2) {
  161.         if (_i2 >= _iterator2.length) break;
  162.         _ref2 = _iterator2[_i2++];
  163.       } else {
  164.         _i2 = _iterator2.next();
  165.         if (_i2.done) break;
  166.         _ref2 = _i2.value;
  167.       }
  168.  
  169.       var _pattern = _ref2;
  170.  
  171.       if (_shouldIgnore(_pattern, filename)) return true;
  172.     }
  173.   }
  174.  
  175.   return false;
  176. }
  177.  
  178. function _shouldIgnore(pattern, filename) {
  179.   if (typeof pattern === "function") {
  180.     return pattern(filename);
  181.   } else {
  182.     return pattern.test(filename);
  183.   }
  184. }
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