index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1682324647458, function(require, module, exports) {
  8. var concatMap = require('concat-map');
  9. var balanced = require('balanced-match');
  10. module.exports = expandTop;
  11. var escSlash = '\0SLASH'+Math.random()+'\0';
  12. var escOpen = '\0OPEN'+Math.random()+'\0';
  13. var escClose = '\0CLOSE'+Math.random()+'\0';
  14. var escComma = '\0COMMA'+Math.random()+'\0';
  15. var escPeriod = '\0PERIOD'+Math.random()+'\0';
  16. function numeric(str) {
  17. return parseInt(str, 10) == str
  18. ? parseInt(str, 10)
  19. : str.charCodeAt(0);
  20. }
  21. function escapeBraces(str) {
  22. return str.split('\\\\').join(escSlash)
  23. .split('\\{').join(escOpen)
  24. .split('\\}').join(escClose)
  25. .split('\\,').join(escComma)
  26. .split('\\.').join(escPeriod);
  27. }
  28. function unescapeBraces(str) {
  29. return str.split(escSlash).join('\\')
  30. .split(escOpen).join('{')
  31. .split(escClose).join('}')
  32. .split(escComma).join(',')
  33. .split(escPeriod).join('.');
  34. }
  35. // Basically just str.split(","), but handling cases
  36. // where we have nested braced sections, which should be
  37. // treated as individual members, like {a,{b,c},d}
  38. function parseCommaParts(str) {
  39. if (!str)
  40. return [''];
  41. var parts = [];
  42. var m = balanced('{', '}', str);
  43. if (!m)
  44. return str.split(',');
  45. var pre = m.pre;
  46. var body = m.body;
  47. var post = m.post;
  48. var p = pre.split(',');
  49. p[p.length-1] += '{' + body + '}';
  50. var postParts = parseCommaParts(post);
  51. if (post.length) {
  52. p[p.length-1] += postParts.shift();
  53. p.push.apply(p, postParts);
  54. }
  55. parts.push.apply(parts, p);
  56. return parts;
  57. }
  58. function expandTop(str) {
  59. if (!str)
  60. return [];
  61. // I don't know why Bash 4.3 does this, but it does.
  62. // Anything starting with {} will have the first two bytes preserved
  63. // but *only* at the top level, so {},a}b will not expand to anything,
  64. // but a{},b}c will be expanded to [a}c,abc].
  65. // One could argue that this is a bug in Bash, but since the goal of
  66. // this module is to match Bash's rules, we escape a leading {}
  67. if (str.substr(0, 2) === '{}') {
  68. str = '\\{\\}' + str.substr(2);
  69. }
  70. return expand(escapeBraces(str), true).map(unescapeBraces);
  71. }
  72. function identity(e) {
  73. return e;
  74. }
  75. function embrace(str) {
  76. return '{' + str + '}';
  77. }
  78. function isPadded(el) {
  79. return /^-?0\d/.test(el);
  80. }
  81. function lte(i, y) {
  82. return i <= y;
  83. }
  84. function gte(i, y) {
  85. return i >= y;
  86. }
  87. function expand(str, isTop) {
  88. var expansions = [];
  89. var m = balanced('{', '}', str);
  90. if (!m || /\$$/.test(m.pre)) return [str];
  91. var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
  92. var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
  93. var isSequence = isNumericSequence || isAlphaSequence;
  94. var isOptions = m.body.indexOf(',') >= 0;
  95. if (!isSequence && !isOptions) {
  96. // {a},b}
  97. if (m.post.match(/,.*\}/)) {
  98. str = m.pre + '{' + m.body + escClose + m.post;
  99. return expand(str);
  100. }
  101. return [str];
  102. }
  103. var n;
  104. if (isSequence) {
  105. n = m.body.split(/\.\./);
  106. } else {
  107. n = parseCommaParts(m.body);
  108. if (n.length === 1) {
  109. // x{{a,b}}y ==> x{a}y x{b}y
  110. n = expand(n[0], false).map(embrace);
  111. if (n.length === 1) {
  112. var post = m.post.length
  113. ? expand(m.post, false)
  114. : [''];
  115. return post.map(function(p) {
  116. return m.pre + n[0] + p;
  117. });
  118. }
  119. }
  120. }
  121. // at this point, n is the parts, and we know it's not a comma set
  122. // with a single entry.
  123. // no need to expand pre, since it is guaranteed to be free of brace-sets
  124. var pre = m.pre;
  125. var post = m.post.length
  126. ? expand(m.post, false)
  127. : [''];
  128. var N;
  129. if (isSequence) {
  130. var x = numeric(n[0]);
  131. var y = numeric(n[1]);
  132. var width = Math.max(n[0].length, n[1].length)
  133. var incr = n.length == 3
  134. ? Math.abs(numeric(n[2]))
  135. : 1;
  136. var test = lte;
  137. var reverse = y < x;
  138. if (reverse) {
  139. incr *= -1;
  140. test = gte;
  141. }
  142. var pad = n.some(isPadded);
  143. N = [];
  144. for (var i = x; test(i, y); i += incr) {
  145. var c;
  146. if (isAlphaSequence) {
  147. c = String.fromCharCode(i);
  148. if (c === '\\')
  149. c = '';
  150. } else {
  151. c = String(i);
  152. if (pad) {
  153. var need = width - c.length;
  154. if (need > 0) {
  155. var z = new Array(need + 1).join('0');
  156. if (i < 0)
  157. c = '-' + z + c.slice(1);
  158. else
  159. c = z + c;
  160. }
  161. }
  162. }
  163. N.push(c);
  164. }
  165. } else {
  166. N = concatMap(n, function(el) { return expand(el, false) });
  167. }
  168. for (var j = 0; j < N.length; j++) {
  169. for (var k = 0; k < post.length; k++) {
  170. var expansion = pre + N[j] + post[k];
  171. if (!isTop || isSequence || expansion)
  172. expansions.push(expansion);
  173. }
  174. }
  175. return expansions;
  176. }
  177. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  178. return __REQUIRE__(1682324647458);
  179. })()
  180. //miniprogram-npm-outsideDeps=["concat-map","balanced-match"]
  181. //# sourceMappingURL=index.js.map