1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var path = require('path');
|
8 | var path__default = _interopDefault(path);
|
9 | var estreeWalker = require('estree-walker');
|
10 | var util = _interopDefault(require('util'));
|
11 |
|
12 | const addExtension = function addExtension(filename, ext = '.js') {
|
13 | if (!path.extname(filename))
|
14 | filename += ext;
|
15 | return filename;
|
16 | };
|
17 |
|
18 | const extractors = {
|
19 | ArrayPattern(names, param) {
|
20 | for (const element of param.elements) {
|
21 | if (element)
|
22 | extractors[element.type](names, element);
|
23 | }
|
24 | },
|
25 | AssignmentPattern(names, param) {
|
26 | extractors[param.left.type](names, param.left);
|
27 | },
|
28 | Identifier(names, param) {
|
29 | names.push(param.name);
|
30 | },
|
31 | MemberExpression() { },
|
32 | ObjectPattern(names, param) {
|
33 | for (const prop of param.properties) {
|
34 | if (prop.type === 'RestElement') {
|
35 | extractors.RestElement(names, prop);
|
36 | }
|
37 | else {
|
38 | extractors[prop.value.type](names, prop.value);
|
39 | }
|
40 | }
|
41 | },
|
42 | RestElement(names, param) {
|
43 | extractors[param.argument.type](names, param.argument);
|
44 | }
|
45 | };
|
46 | const extractAssignedNames = function extractAssignedNames(param) {
|
47 | const names = [];
|
48 | extractors[param.type](names, param);
|
49 | return names;
|
50 | };
|
51 |
|
52 | const blockDeclarations = {
|
53 | const: true,
|
54 | let: true
|
55 | };
|
56 | class Scope {
|
57 | constructor(options = {}) {
|
58 | this.parent = options.parent;
|
59 | this.isBlockScope = !!options.block;
|
60 | this.declarations = Object.create(null);
|
61 | if (options.params) {
|
62 | options.params.forEach(param => {
|
63 | extractAssignedNames(param).forEach(name => {
|
64 | this.declarations[name] = true;
|
65 | });
|
66 | });
|
67 | }
|
68 | }
|
69 | addDeclaration(node, isBlockDeclaration, isVar) {
|
70 | if (!isBlockDeclaration && this.isBlockScope) {
|
71 |
|
72 |
|
73 | this.parent.addDeclaration(node, isBlockDeclaration, isVar);
|
74 | }
|
75 | else if (node.id) {
|
76 | extractAssignedNames(node.id).forEach(name => {
|
77 | this.declarations[name] = true;
|
78 | });
|
79 | }
|
80 | }
|
81 | contains(name) {
|
82 | return this.declarations[name] || (this.parent ? this.parent.contains(name) : false);
|
83 | }
|
84 | }
|
85 | const attachScopes = function attachScopes(ast, propertyName = 'scope') {
|
86 | let scope = new Scope();
|
87 | estreeWalker.walk(ast, {
|
88 | enter(node, parent) {
|
89 |
|
90 |
|
91 | if (/(Function|Class)Declaration/.test(node.type)) {
|
92 | scope.addDeclaration(node, false, false);
|
93 | }
|
94 |
|
95 | if (node.type === 'VariableDeclaration') {
|
96 | const kind = node.kind;
|
97 | const isBlockDeclaration = blockDeclarations[kind];
|
98 | node.declarations.forEach((declaration) => {
|
99 | scope.addDeclaration(declaration, isBlockDeclaration, true);
|
100 | });
|
101 | }
|
102 | let newScope;
|
103 |
|
104 | if (/Function/.test(node.type)) {
|
105 | newScope = new Scope({
|
106 | parent: scope,
|
107 | block: false,
|
108 | params: node.params
|
109 | });
|
110 |
|
111 |
|
112 | if (node.type === 'FunctionExpression' && node.id) {
|
113 | newScope.addDeclaration(node, false, false);
|
114 | }
|
115 | }
|
116 |
|
117 | if (node.type === 'BlockStatement' && !/Function/.test(parent.type)) {
|
118 | newScope = new Scope({
|
119 | parent: scope,
|
120 | block: true
|
121 | });
|
122 | }
|
123 |
|
124 | if (node.type === 'CatchClause') {
|
125 | newScope = new Scope({
|
126 | parent: scope,
|
127 | params: node.param ? [node.param] : [],
|
128 | block: true
|
129 | });
|
130 | }
|
131 | if (newScope) {
|
132 | Object.defineProperty(node, propertyName, {
|
133 | value: newScope,
|
134 | configurable: true
|
135 | });
|
136 | scope = newScope;
|
137 | }
|
138 | },
|
139 | leave(node) {
|
140 | if (node[propertyName])
|
141 | scope = scope.parent;
|
142 | }
|
143 | });
|
144 | return scope;
|
145 | };
|
146 |
|
147 | function createCommonjsModule(fn, module) {
|
148 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
149 | }
|
150 |
|
151 | var utils = createCommonjsModule(function (module, exports) {
|
152 | exports.isInteger = num => {
|
153 | if (typeof num === 'number') {
|
154 | return Number.isInteger(num);
|
155 | }
|
156 | if (typeof num === 'string' && num.trim() !== '') {
|
157 | return Number.isInteger(Number(num));
|
158 | }
|
159 | return false;
|
160 | };
|
161 | |
162 |
|
163 |
|
164 | exports.find = (node, type) => node.nodes.find(node => node.type === type);
|
165 | |
166 |
|
167 |
|
168 | exports.exceedsLimit = (min, max, step = 1, limit) => {
|
169 | if (limit === false)
|
170 | return false;
|
171 | if (!exports.isInteger(min) || !exports.isInteger(max))
|
172 | return false;
|
173 | return ((Number(max) - Number(min)) / Number(step)) >= limit;
|
174 | };
|
175 | |
176 |
|
177 |
|
178 | exports.escapeNode = (block, n = 0, type) => {
|
179 | let node = block.nodes[n];
|
180 | if (!node)
|
181 | return;
|
182 | if ((type && node.type === type) || node.type === 'open' || node.type === 'close') {
|
183 | if (node.escaped !== true) {
|
184 | node.value = '\\' + node.value;
|
185 | node.escaped = true;
|
186 | }
|
187 | }
|
188 | };
|
189 | |
190 |
|
191 |
|
192 | exports.encloseBrace = node => {
|
193 | if (node.type !== 'brace')
|
194 | return false;
|
195 | if ((node.commas >> 0 + node.ranges >> 0) === 0) {
|
196 | node.invalid = true;
|
197 | return true;
|
198 | }
|
199 | return false;
|
200 | };
|
201 | |
202 |
|
203 |
|
204 | exports.isInvalidBrace = block => {
|
205 | if (block.type !== 'brace')
|
206 | return false;
|
207 | if (block.invalid === true || block.dollar)
|
208 | return true;
|
209 | if ((block.commas >> 0 + block.ranges >> 0) === 0) {
|
210 | block.invalid = true;
|
211 | return true;
|
212 | }
|
213 | if (block.open !== true || block.close !== true) {
|
214 | block.invalid = true;
|
215 | return true;
|
216 | }
|
217 | return false;
|
218 | };
|
219 | |
220 |
|
221 |
|
222 | exports.isOpenOrClose = node => {
|
223 | if (node.type === 'open' || node.type === 'close') {
|
224 | return true;
|
225 | }
|
226 | return node.open === true || node.close === true;
|
227 | };
|
228 | |
229 |
|
230 |
|
231 | exports.reduce = nodes => nodes.reduce((acc, node) => {
|
232 | if (node.type === 'text')
|
233 | acc.push(node.value);
|
234 | if (node.type === 'range')
|
235 | node.type = 'text';
|
236 | return acc;
|
237 | }, []);
|
238 | |
239 |
|
240 |
|
241 | exports.flatten = (...args) => {
|
242 | const result = [];
|
243 | const flat = arr => {
|
244 | for (let i = 0; i < arr.length; i++) {
|
245 | let ele = arr[i];
|
246 | Array.isArray(ele) ? flat(ele, result) : ele !== void 0 && result.push(ele);
|
247 | }
|
248 | return result;
|
249 | };
|
250 | flat(args);
|
251 | return result;
|
252 | };
|
253 | });
|
254 | var utils_1 = utils.isInteger;
|
255 | var utils_2 = utils.find;
|
256 | var utils_3 = utils.exceedsLimit;
|
257 | var utils_4 = utils.escapeNode;
|
258 | var utils_5 = utils.encloseBrace;
|
259 | var utils_6 = utils.isInvalidBrace;
|
260 | var utils_7 = utils.isOpenOrClose;
|
261 | var utils_8 = utils.reduce;
|
262 | var utils_9 = utils.flatten;
|
263 |
|
264 | var stringify = (ast, options = {}) => {
|
265 | let stringify = (node, parent = {}) => {
|
266 | let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
267 | let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
268 | let output = '';
|
269 | if (node.value) {
|
270 | if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
271 | return '\\' + node.value;
|
272 | }
|
273 | return node.value;
|
274 | }
|
275 | if (node.value) {
|
276 | return node.value;
|
277 | }
|
278 | if (node.nodes) {
|
279 | for (let child of node.nodes) {
|
280 | output += stringify(child);
|
281 | }
|
282 | }
|
283 | return output;
|
284 | };
|
285 | return stringify(ast);
|
286 | };
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | var isNumber = function (num) {
|
295 | if (typeof num === 'number') {
|
296 | return num - num === 0;
|
297 | }
|
298 | if (typeof num === 'string' && num.trim() !== '') {
|
299 | return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
|
300 | }
|
301 | return false;
|
302 | };
|
303 |
|
304 | const toRegexRange = (min, max, options) => {
|
305 | if (isNumber(min) === false) {
|
306 | throw new TypeError('toRegexRange: expected the first argument to be a number');
|
307 | }
|
308 | if (max === void 0 || min === max) {
|
309 | return String(min);
|
310 | }
|
311 | if (isNumber(max) === false) {
|
312 | throw new TypeError('toRegexRange: expected the second argument to be a number.');
|
313 | }
|
314 | let opts = Object.assign({ relaxZeros: true }, options);
|
315 | if (typeof opts.strictZeros === 'boolean') {
|
316 | opts.relaxZeros = opts.strictZeros === false;
|
317 | }
|
318 | let relax = String(opts.relaxZeros);
|
319 | let shorthand = String(opts.shorthand);
|
320 | let capture = String(opts.capture);
|
321 | let wrap = String(opts.wrap);
|
322 | let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
|
323 | if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
|
324 | return toRegexRange.cache[cacheKey].result;
|
325 | }
|
326 | let a = Math.min(min, max);
|
327 | let b = Math.max(min, max);
|
328 | if (Math.abs(a - b) === 1) {
|
329 | let result = min + '|' + max;
|
330 | if (opts.capture) {
|
331 | return `(${result})`;
|
332 | }
|
333 | if (opts.wrap === false) {
|
334 | return result;
|
335 | }
|
336 | return `(?:${result})`;
|
337 | }
|
338 | let isPadded = hasPadding(min) || hasPadding(max);
|
339 | let state = { min, max, a, b };
|
340 | let positives = [];
|
341 | let negatives = [];
|
342 | if (isPadded) {
|
343 | state.isPadded = isPadded;
|
344 | state.maxLen = String(state.max).length;
|
345 | }
|
346 | if (a < 0) {
|
347 | let newMin = b < 0 ? Math.abs(b) : 1;
|
348 | negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
|
349 | a = state.a = 0;
|
350 | }
|
351 | if (b >= 0) {
|
352 | positives = splitToPatterns(a, b, state, opts);
|
353 | }
|
354 | state.negatives = negatives;
|
355 | state.positives = positives;
|
356 | state.result = collatePatterns(negatives, positives, opts);
|
357 | if (opts.capture === true) {
|
358 | state.result = `(${state.result})`;
|
359 | }
|
360 | else if (opts.wrap !== false && (positives.length + negatives.length) > 1) {
|
361 | state.result = `(?:${state.result})`;
|
362 | }
|
363 | toRegexRange.cache[cacheKey] = state;
|
364 | return state.result;
|
365 | };
|
366 | function collatePatterns(neg, pos, options) {
|
367 | let onlyNegative = filterPatterns(neg, pos, '-', false, options) || [];
|
368 | let onlyPositive = filterPatterns(pos, neg, '', false, options) || [];
|
369 | let intersected = filterPatterns(neg, pos, '-?', true, options) || [];
|
370 | let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
|
371 | return subpatterns.join('|');
|
372 | }
|
373 | function splitToRanges(min, max) {
|
374 | let nines = 1;
|
375 | let zeros = 1;
|
376 | let stop = countNines(min, nines);
|
377 | let stops = new Set([max]);
|
378 | while (min <= stop && stop <= max) {
|
379 | stops.add(stop);
|
380 | nines += 1;
|
381 | stop = countNines(min, nines);
|
382 | }
|
383 | stop = countZeros(max + 1, zeros) - 1;
|
384 | while (min < stop && stop <= max) {
|
385 | stops.add(stop);
|
386 | zeros += 1;
|
387 | stop = countZeros(max + 1, zeros) - 1;
|
388 | }
|
389 | stops = [...stops];
|
390 | stops.sort(compare);
|
391 | return stops;
|
392 | }
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | function rangeToPattern(start, stop, options) {
|
400 | if (start === stop) {
|
401 | return { pattern: start, count: [], digits: 0 };
|
402 | }
|
403 | let zipped = zip(start, stop);
|
404 | let digits = zipped.length;
|
405 | let pattern = '';
|
406 | let count = 0;
|
407 | for (let i = 0; i < digits; i++) {
|
408 | let [startDigit, stopDigit] = zipped[i];
|
409 | if (startDigit === stopDigit) {
|
410 | pattern += startDigit;
|
411 | }
|
412 | else if (startDigit !== '0' || stopDigit !== '9') {
|
413 | pattern += toCharacterClass(startDigit, stopDigit, options);
|
414 | }
|
415 | else {
|
416 | count++;
|
417 | }
|
418 | }
|
419 | if (count) {
|
420 | pattern += options.shorthand === true ? '\\d' : '[0-9]';
|
421 | }
|
422 | return { pattern, count: [count], digits };
|
423 | }
|
424 | function splitToPatterns(min, max, tok, options) {
|
425 | let ranges = splitToRanges(min, max);
|
426 | let tokens = [];
|
427 | let start = min;
|
428 | let prev;
|
429 | for (let i = 0; i < ranges.length; i++) {
|
430 | let max = ranges[i];
|
431 | let obj = rangeToPattern(String(start), String(max), options);
|
432 | let zeros = '';
|
433 | if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
|
434 | if (prev.count.length > 1) {
|
435 | prev.count.pop();
|
436 | }
|
437 | prev.count.push(obj.count[0]);
|
438 | prev.string = prev.pattern + toQuantifier(prev.count);
|
439 | start = max + 1;
|
440 | continue;
|
441 | }
|
442 | if (tok.isPadded) {
|
443 | zeros = padZeros(max, tok, options);
|
444 | }
|
445 | obj.string = zeros + obj.pattern + toQuantifier(obj.count);
|
446 | tokens.push(obj);
|
447 | start = max + 1;
|
448 | prev = obj;
|
449 | }
|
450 | return tokens;
|
451 | }
|
452 | function filterPatterns(arr, comparison, prefix, intersection, options) {
|
453 | let result = [];
|
454 | for (let ele of arr) {
|
455 | let { string } = ele;
|
456 |
|
457 | if (!intersection && !contains(comparison, 'string', string)) {
|
458 | result.push(prefix + string);
|
459 | }
|
460 |
|
461 | if (intersection && contains(comparison, 'string', string)) {
|
462 | result.push(prefix + string);
|
463 | }
|
464 | }
|
465 | return result;
|
466 | }
|
467 |
|
468 |
|
469 |
|
470 | function zip(a, b) {
|
471 | let arr = [];
|
472 | for (let i = 0; i < a.length; i++)
|
473 | arr.push([a[i], b[i]]);
|
474 | return arr;
|
475 | }
|
476 | function compare(a, b) {
|
477 | return a > b ? 1 : b > a ? -1 : 0;
|
478 | }
|
479 | function contains(arr, key, val) {
|
480 | return arr.some(ele => ele[key] === val);
|
481 | }
|
482 | function countNines(min, len) {
|
483 | return Number(String(min).slice(0, -len) + '9'.repeat(len));
|
484 | }
|
485 | function countZeros(integer, zeros) {
|
486 | return integer - (integer % Math.pow(10, zeros));
|
487 | }
|
488 | function toQuantifier(digits) {
|
489 | let [start = 0, stop = ''] = digits;
|
490 | if (stop || start > 1) {
|
491 | return `{${start + (stop ? ',' + stop : '')}}`;
|
492 | }
|
493 | return '';
|
494 | }
|
495 | function toCharacterClass(a, b, options) {
|
496 | return `[${a}${(b - a === 1) ? '' : '-'}${b}]`;
|
497 | }
|
498 | function hasPadding(str) {
|
499 | return /^-?(0+)\d/.test(str);
|
500 | }
|
501 | function padZeros(value, tok, options) {
|
502 | if (!tok.isPadded) {
|
503 | return value;
|
504 | }
|
505 | let diff = Math.abs(tok.maxLen - String(value).length);
|
506 | let relax = options.relaxZeros !== false;
|
507 | switch (diff) {
|
508 | case 0:
|
509 | return '';
|
510 | case 1:
|
511 | return relax ? '0?' : '0';
|
512 | case 2:
|
513 | return relax ? '0{0,2}' : '00';
|
514 | default: {
|
515 | return relax ? `0{0,${diff}}` : `0{${diff}}`;
|
516 | }
|
517 | }
|
518 | }
|
519 |
|
520 |
|
521 |
|
522 | toRegexRange.cache = {};
|
523 | toRegexRange.clearCache = () => (toRegexRange.cache = {});
|
524 |
|
525 |
|
526 |
|
527 | var toRegexRange_1 = toRegexRange;
|
528 |
|
529 | const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
530 | const transform = toNumber => {
|
531 | return value => toNumber === true ? Number(value) : String(value);
|
532 | };
|
533 | const isValidValue = value => {
|
534 | return typeof value === 'number' || (typeof value === 'string' && value !== '');
|
535 | };
|
536 | const isNumber$1 = num => Number.isInteger(+num);
|
537 | const zeros = input => {
|
538 | let value = `${input}`;
|
539 | let index = -1;
|
540 | if (value[0] === '-')
|
541 | value = value.slice(1);
|
542 | if (value === '0')
|
543 | return false;
|
544 | while (value[++index] === '0')
|
545 | ;
|
546 | return index > 0;
|
547 | };
|
548 | const stringify$1 = (start, end, options) => {
|
549 | if (typeof start === 'string' || typeof end === 'string') {
|
550 | return true;
|
551 | }
|
552 | return options.stringify === true;
|
553 | };
|
554 | const pad = (input, maxLength, toNumber) => {
|
555 | if (maxLength > 0) {
|
556 | let dash = input[0] === '-' ? '-' : '';
|
557 | if (dash)
|
558 | input = input.slice(1);
|
559 | input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
|
560 | }
|
561 | if (toNumber === false) {
|
562 | return String(input);
|
563 | }
|
564 | return input;
|
565 | };
|
566 | const toMaxLen = (input, maxLength) => {
|
567 | let negative = input[0] === '-' ? '-' : '';
|
568 | if (negative) {
|
569 | input = input.slice(1);
|
570 | maxLength--;
|
571 | }
|
572 | while (input.length < maxLength)
|
573 | input = '0' + input;
|
574 | return negative ? ('-' + input) : input;
|
575 | };
|
576 | const toSequence = (parts, options) => {
|
577 | parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
578 | parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
579 | let prefix = options.capture ? '' : '?:';
|
580 | let positives = '';
|
581 | let negatives = '';
|
582 | let result;
|
583 | if (parts.positives.length) {
|
584 | positives = parts.positives.join('|');
|
585 | }
|
586 | if (parts.negatives.length) {
|
587 | negatives = `-(${prefix}${parts.negatives.join('|')})`;
|
588 | }
|
589 | if (positives && negatives) {
|
590 | result = `${positives}|${negatives}`;
|
591 | }
|
592 | else {
|
593 | result = positives || negatives;
|
594 | }
|
595 | if (options.wrap) {
|
596 | return `(${prefix}${result})`;
|
597 | }
|
598 | return result;
|
599 | };
|
600 | const toRange = (a, b, isNumbers, options) => {
|
601 | if (isNumbers) {
|
602 | return toRegexRange_1(a, b, Object.assign({ wrap: false }, options));
|
603 | }
|
604 | let start = String.fromCharCode(a);
|
605 | if (a === b)
|
606 | return start;
|
607 | let stop = String.fromCharCode(b);
|
608 | return `[${start}-${stop}]`;
|
609 | };
|
610 | const toRegex = (start, end, options) => {
|
611 | if (Array.isArray(start)) {
|
612 | let wrap = options.wrap === true;
|
613 | let prefix = options.capture ? '' : '?:';
|
614 | return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
|
615 | }
|
616 | return toRegexRange_1(start, end, options);
|
617 | };
|
618 | const rangeError = (...args) => {
|
619 | return new RangeError('Invalid range arguments: ' + util.inspect(...args));
|
620 | };
|
621 | const invalidRange = (start, end, options) => {
|
622 | if (options.strictRanges === true)
|
623 | throw rangeError([start, end]);
|
624 | return [];
|
625 | };
|
626 | const invalidStep = (step, options) => {
|
627 | if (options.strictRanges === true) {
|
628 | throw new TypeError(`Expected step "${step}" to be a number`);
|
629 | }
|
630 | return [];
|
631 | };
|
632 | const fillNumbers = (start, end, step = 1, options = {}) => {
|
633 | let a = Number(start);
|
634 | let b = Number(end);
|
635 | if (!Number.isInteger(a) || !Number.isInteger(b)) {
|
636 | if (options.strictRanges === true)
|
637 | throw rangeError([start, end]);
|
638 | return [];
|
639 | }
|
640 |
|
641 | if (a === 0)
|
642 | a = 0;
|
643 | if (b === 0)
|
644 | b = 0;
|
645 | let descending = a > b;
|
646 | let startString = String(start);
|
647 | let endString = String(end);
|
648 | let stepString = String(step);
|
649 | step = Math.max(Math.abs(step), 1);
|
650 | let padded = zeros(startString) || zeros(endString) || zeros(stepString);
|
651 | let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
|
652 | let toNumber = padded === false && stringify$1(start, end, options) === false;
|
653 | let format = options.transform || transform(toNumber);
|
654 | if (options.toRegex && step === 1) {
|
655 | return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
|
656 | }
|
657 | let parts = { negatives: [], positives: [] };
|
658 | let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
|
659 | let range = [];
|
660 | let index = 0;
|
661 | while (descending ? a >= b : a <= b) {
|
662 | if (options.toRegex === true && step > 1) {
|
663 | push(a);
|
664 | }
|
665 | else {
|
666 | range.push(pad(format(a, index), maxLen, toNumber));
|
667 | }
|
668 | a = descending ? a - step : a + step;
|
669 | index++;
|
670 | }
|
671 | if (options.toRegex === true) {
|
672 | return step > 1
|
673 | ? toSequence(parts, options)
|
674 | : toRegex(range, null, Object.assign({ wrap: false }, options));
|
675 | }
|
676 | return range;
|
677 | };
|
678 | const fillLetters = (start, end, step = 1, options = {}) => {
|
679 | if ((!isNumber$1(start) && start.length > 1) || (!isNumber$1(end) && end.length > 1)) {
|
680 | return invalidRange(start, end, options);
|
681 | }
|
682 | let format = options.transform || (val => String.fromCharCode(val));
|
683 | let a = `${start}`.charCodeAt(0);
|
684 | let b = `${end}`.charCodeAt(0);
|
685 | let descending = a > b;
|
686 | let min = Math.min(a, b);
|
687 | let max = Math.max(a, b);
|
688 | if (options.toRegex && step === 1) {
|
689 | return toRange(min, max, false, options);
|
690 | }
|
691 | let range = [];
|
692 | let index = 0;
|
693 | while (descending ? a >= b : a <= b) {
|
694 | range.push(format(a, index));
|
695 | a = descending ? a - step : a + step;
|
696 | index++;
|
697 | }
|
698 | if (options.toRegex === true) {
|
699 | return toRegex(range, null, { wrap: false, options });
|
700 | }
|
701 | return range;
|
702 | };
|
703 | const fill = (start, end, step, options = {}) => {
|
704 | if (end == null && isValidValue(start)) {
|
705 | return [start];
|
706 | }
|
707 | if (!isValidValue(start) || !isValidValue(end)) {
|
708 | return invalidRange(start, end, options);
|
709 | }
|
710 | if (typeof step === 'function') {
|
711 | return fill(start, end, 1, { transform: step });
|
712 | }
|
713 | if (isObject(step)) {
|
714 | return fill(start, end, 0, step);
|
715 | }
|
716 | let opts = Object.assign({}, options);
|
717 | if (opts.capture === true)
|
718 | opts.wrap = true;
|
719 | step = step || opts.step || 1;
|
720 | if (!isNumber$1(step)) {
|
721 | if (step != null && !isObject(step))
|
722 | return invalidStep(step, opts);
|
723 | return fill(start, end, 1, step);
|
724 | }
|
725 | if (isNumber$1(start) && isNumber$1(end)) {
|
726 | return fillNumbers(start, end, step, opts);
|
727 | }
|
728 | return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
|
729 | };
|
730 | var fillRange = fill;
|
731 |
|
732 | const compile = (ast, options = {}) => {
|
733 | let walk = (node, parent = {}) => {
|
734 | let invalidBlock = utils.isInvalidBrace(parent);
|
735 | let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
736 | let invalid = invalidBlock === true || invalidNode === true;
|
737 | let prefix = options.escapeInvalid === true ? '\\' : '';
|
738 | let output = '';
|
739 | if (node.isOpen === true) {
|
740 | return prefix + node.value;
|
741 | }
|
742 | if (node.isClose === true) {
|
743 | return prefix + node.value;
|
744 | }
|
745 | if (node.type === 'open') {
|
746 | return invalid ? (prefix + node.value) : '(';
|
747 | }
|
748 | if (node.type === 'close') {
|
749 | return invalid ? (prefix + node.value) : ')';
|
750 | }
|
751 | if (node.type === 'comma') {
|
752 | return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
|
753 | }
|
754 | if (node.value) {
|
755 | return node.value;
|
756 | }
|
757 | if (node.nodes && node.ranges > 0) {
|
758 | let args = utils.reduce(node.nodes);
|
759 | let range = fillRange(...args, Object.assign({}, options, { wrap: false, toRegex: true }));
|
760 | if (range.length !== 0) {
|
761 | return args.length > 1 && range.length > 1 ? `(${range})` : range;
|
762 | }
|
763 | }
|
764 | if (node.nodes) {
|
765 | for (let child of node.nodes) {
|
766 | output += walk(child, node);
|
767 | }
|
768 | }
|
769 | return output;
|
770 | };
|
771 | return walk(ast);
|
772 | };
|
773 | var compile_1 = compile;
|
774 |
|
775 | const append = (queue = '', stash = '', enclose = false) => {
|
776 | let result = [];
|
777 | queue = [].concat(queue);
|
778 | stash = [].concat(stash);
|
779 | if (!stash.length)
|
780 | return queue;
|
781 | if (!queue.length) {
|
782 | return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
|
783 | }
|
784 | for (let item of queue) {
|
785 | if (Array.isArray(item)) {
|
786 | for (let value of item) {
|
787 | result.push(append(value, stash, enclose));
|
788 | }
|
789 | }
|
790 | else {
|
791 | for (let ele of stash) {
|
792 | if (enclose === true && typeof ele === 'string')
|
793 | ele = `{${ele}}`;
|
794 | result.push(Array.isArray(ele) ? append(item, ele, enclose) : (item + ele));
|
795 | }
|
796 | }
|
797 | }
|
798 | return utils.flatten(result);
|
799 | };
|
800 | const expand = (ast, options = {}) => {
|
801 | let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
|
802 | let walk = (node, parent = {}) => {
|
803 | node.queue = [];
|
804 | let p = parent;
|
805 | let q = parent.queue;
|
806 | while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
|
807 | p = p.parent;
|
808 | q = p.queue;
|
809 | }
|
810 | if (node.invalid || node.dollar) {
|
811 | q.push(append(q.pop(), stringify(node, options)));
|
812 | return;
|
813 | }
|
814 | if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
|
815 | q.push(append(q.pop(), ['{}']));
|
816 | return;
|
817 | }
|
818 | if (node.nodes && node.ranges > 0) {
|
819 | let args = utils.reduce(node.nodes);
|
820 | if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
|
821 | throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
|
822 | }
|
823 | let range = fillRange(...args, options);
|
824 | if (range.length === 0) {
|
825 | range = stringify(node, options);
|
826 | }
|
827 | q.push(append(q.pop(), range));
|
828 | node.nodes = [];
|
829 | return;
|
830 | }
|
831 | let enclose = utils.encloseBrace(node);
|
832 | let queue = node.queue;
|
833 | let block = node;
|
834 | while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
|
835 | block = block.parent;
|
836 | queue = block.queue;
|
837 | }
|
838 | for (let i = 0; i < node.nodes.length; i++) {
|
839 | let child = node.nodes[i];
|
840 | if (child.type === 'comma' && node.type === 'brace') {
|
841 | if (i === 1)
|
842 | queue.push('');
|
843 | queue.push('');
|
844 | continue;
|
845 | }
|
846 | if (child.type === 'close') {
|
847 | q.push(append(q.pop(), queue, enclose));
|
848 | continue;
|
849 | }
|
850 | if (child.value && child.type !== 'open') {
|
851 | queue.push(append(queue.pop(), child.value));
|
852 | continue;
|
853 | }
|
854 | if (child.nodes) {
|
855 | walk(child, node);
|
856 | }
|
857 | }
|
858 | return queue;
|
859 | };
|
860 | return utils.flatten(walk(ast));
|
861 | };
|
862 | var expand_1 = expand;
|
863 |
|
864 | var constants = {
|
865 | MAX_LENGTH: 1024 * 64,
|
866 |
|
867 | CHAR_0: '0',
|
868 | CHAR_9: '9',
|
869 |
|
870 | CHAR_UPPERCASE_A: 'A',
|
871 | CHAR_LOWERCASE_A: 'a',
|
872 | CHAR_UPPERCASE_Z: 'Z',
|
873 | CHAR_LOWERCASE_Z: 'z',
|
874 | CHAR_LEFT_PARENTHESES: '(',
|
875 | CHAR_RIGHT_PARENTHESES: ')',
|
876 | CHAR_ASTERISK: '*',
|
877 |
|
878 | CHAR_AMPERSAND: '&',
|
879 | CHAR_AT: '@',
|
880 | CHAR_BACKSLASH: '\\',
|
881 | CHAR_BACKTICK: '`',
|
882 | CHAR_CARRIAGE_RETURN: '\r',
|
883 | CHAR_CIRCUMFLEX_ACCENT: '^',
|
884 | CHAR_COLON: ':',
|
885 | CHAR_COMMA: ',',
|
886 | CHAR_DOLLAR: '$',
|
887 | CHAR_DOT: '.',
|
888 | CHAR_DOUBLE_QUOTE: '"',
|
889 | CHAR_EQUAL: '=',
|
890 | CHAR_EXCLAMATION_MARK: '!',
|
891 | CHAR_FORM_FEED: '\f',
|
892 | CHAR_FORWARD_SLASH: '/',
|
893 | CHAR_HASH: '#',
|
894 | CHAR_HYPHEN_MINUS: '-',
|
895 | CHAR_LEFT_ANGLE_BRACKET: '<',
|
896 | CHAR_LEFT_CURLY_BRACE: '{',
|
897 | CHAR_LEFT_SQUARE_BRACKET: '[',
|
898 | CHAR_LINE_FEED: '\n',
|
899 | CHAR_NO_BREAK_SPACE: '\u00A0',
|
900 | CHAR_PERCENT: '%',
|
901 | CHAR_PLUS: '+',
|
902 | CHAR_QUESTION_MARK: '?',
|
903 | CHAR_RIGHT_ANGLE_BRACKET: '>',
|
904 | CHAR_RIGHT_CURLY_BRACE: '}',
|
905 | CHAR_RIGHT_SQUARE_BRACKET: ']',
|
906 | CHAR_SEMICOLON: ';',
|
907 | CHAR_SINGLE_QUOTE: '\'',
|
908 | CHAR_SPACE: ' ',
|
909 | CHAR_TAB: '\t',
|
910 | CHAR_UNDERSCORE: '_',
|
911 | CHAR_VERTICAL_LINE: '|',
|
912 | CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF'
|
913 | };
|
914 |
|
915 |
|
916 |
|
917 |
|
918 | const { MAX_LENGTH, CHAR_BACKSLASH, CHAR_BACKTICK, CHAR_COMMA, CHAR_DOT, CHAR_LEFT_PARENTHESES, CHAR_RIGHT_PARENTHESES, CHAR_LEFT_CURLY_BRACE, CHAR_RIGHT_CURLY_BRACE, CHAR_LEFT_SQUARE_BRACKET, CHAR_RIGHT_SQUARE_BRACKET, CHAR_DOUBLE_QUOTE, CHAR_SINGLE_QUOTE, CHAR_NO_BREAK_SPACE, CHAR_ZERO_WIDTH_NOBREAK_SPACE } = constants;
|
919 |
|
920 |
|
921 |
|
922 | const parse = (input, options = {}) => {
|
923 | if (typeof input !== 'string') {
|
924 | throw new TypeError('Expected a string');
|
925 | }
|
926 | let opts = options || {};
|
927 | let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
928 | if (input.length > max) {
|
929 | throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
|
930 | }
|
931 | let ast = { type: 'root', input, nodes: [] };
|
932 | let stack = [ast];
|
933 | let block = ast;
|
934 | let prev = ast;
|
935 | let brackets = 0;
|
936 | let length = input.length;
|
937 | let index = 0;
|
938 | let depth = 0;
|
939 | let value;
|
940 | |
941 |
|
942 |
|
943 | const advance = () => input[index++];
|
944 | const push = node => {
|
945 | if (node.type === 'text' && prev.type === 'dot') {
|
946 | prev.type = 'text';
|
947 | }
|
948 | if (prev && prev.type === 'text' && node.type === 'text') {
|
949 | prev.value += node.value;
|
950 | return;
|
951 | }
|
952 | block.nodes.push(node);
|
953 | node.parent = block;
|
954 | node.prev = prev;
|
955 | prev = node;
|
956 | return node;
|
957 | };
|
958 | push({ type: 'bos' });
|
959 | while (index < length) {
|
960 | block = stack[stack.length - 1];
|
961 | value = advance();
|
962 | |
963 |
|
964 |
|
965 | if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
|
966 | continue;
|
967 | }
|
968 | |
969 |
|
970 |
|
971 | if (value === CHAR_BACKSLASH) {
|
972 | push({ type: 'text', value: (options.keepEscaping ? value : '') + advance() });
|
973 | continue;
|
974 | }
|
975 | |
976 |
|
977 |
|
978 | if (value === CHAR_RIGHT_SQUARE_BRACKET) {
|
979 | push({ type: 'text', value: '\\' + value });
|
980 | continue;
|
981 | }
|
982 | |
983 |
|
984 |
|
985 | if (value === CHAR_LEFT_SQUARE_BRACKET) {
|
986 | brackets++;
|
987 | let next;
|
988 | while (index < length && (next = advance())) {
|
989 | value += next;
|
990 | if (next === CHAR_LEFT_SQUARE_BRACKET) {
|
991 | brackets++;
|
992 | continue;
|
993 | }
|
994 | if (next === CHAR_BACKSLASH) {
|
995 | value += advance();
|
996 | continue;
|
997 | }
|
998 | if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
999 | brackets--;
|
1000 | if (brackets === 0) {
|
1001 | break;
|
1002 | }
|
1003 | }
|
1004 | }
|
1005 | push({ type: 'text', value });
|
1006 | continue;
|
1007 | }
|
1008 | |
1009 |
|
1010 |
|
1011 | if (value === CHAR_LEFT_PARENTHESES) {
|
1012 | block = push({ type: 'paren', nodes: [] });
|
1013 | stack.push(block);
|
1014 | push({ type: 'text', value });
|
1015 | continue;
|
1016 | }
|
1017 | if (value === CHAR_RIGHT_PARENTHESES) {
|
1018 | if (block.type !== 'paren') {
|
1019 | push({ type: 'text', value });
|
1020 | continue;
|
1021 | }
|
1022 | block = stack.pop();
|
1023 | push({ type: 'text', value });
|
1024 | block = stack[stack.length - 1];
|
1025 | continue;
|
1026 | }
|
1027 | |
1028 |
|
1029 |
|
1030 | if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
|
1031 | let open = value;
|
1032 | let next;
|
1033 | if (options.keepQuotes !== true) {
|
1034 | value = '';
|
1035 | }
|
1036 | while (index < length && (next = advance())) {
|
1037 | if (next === CHAR_BACKSLASH) {
|
1038 | value += next + advance();
|
1039 | continue;
|
1040 | }
|
1041 | if (next === open) {
|
1042 | if (options.keepQuotes === true)
|
1043 | value += next;
|
1044 | break;
|
1045 | }
|
1046 | value += next;
|
1047 | }
|
1048 | push({ type: 'text', value });
|
1049 | continue;
|
1050 | }
|
1051 | |
1052 |
|
1053 |
|
1054 | if (value === CHAR_LEFT_CURLY_BRACE) {
|
1055 | depth++;
|
1056 | let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
|
1057 | let brace = {
|
1058 | type: 'brace',
|
1059 | open: true,
|
1060 | close: false,
|
1061 | dollar,
|
1062 | depth,
|
1063 | commas: 0,
|
1064 | ranges: 0,
|
1065 | nodes: []
|
1066 | };
|
1067 | block = push(brace);
|
1068 | stack.push(block);
|
1069 | push({ type: 'open', value });
|
1070 | continue;
|
1071 | }
|
1072 | |
1073 |
|
1074 |
|
1075 | if (value === CHAR_RIGHT_CURLY_BRACE) {
|
1076 | if (block.type !== 'brace') {
|
1077 | push({ type: 'text', value });
|
1078 | continue;
|
1079 | }
|
1080 | let type = 'close';
|
1081 | block = stack.pop();
|
1082 | block.close = true;
|
1083 | push({ type, value });
|
1084 | depth--;
|
1085 | block = stack[stack.length - 1];
|
1086 | continue;
|
1087 | }
|
1088 | |
1089 |
|
1090 |
|
1091 | if (value === CHAR_COMMA && depth > 0) {
|
1092 | if (block.ranges > 0) {
|
1093 | block.ranges = 0;
|
1094 | let open = block.nodes.shift();
|
1095 | block.nodes = [open, { type: 'text', value: stringify(block) }];
|
1096 | }
|
1097 | push({ type: 'comma', value });
|
1098 | block.commas++;
|
1099 | continue;
|
1100 | }
|
1101 | |
1102 |
|
1103 |
|
1104 | if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
|
1105 | let siblings = block.nodes;
|
1106 | if (depth === 0 || siblings.length === 0) {
|
1107 | push({ type: 'text', value });
|
1108 | continue;
|
1109 | }
|
1110 | if (prev.type === 'dot') {
|
1111 | block.range = [];
|
1112 | prev.value += value;
|
1113 | prev.type = 'range';
|
1114 | if (block.nodes.length !== 3 && block.nodes.length !== 5) {
|
1115 | block.invalid = true;
|
1116 | block.ranges = 0;
|
1117 | prev.type = 'text';
|
1118 | continue;
|
1119 | }
|
1120 | block.ranges++;
|
1121 | block.args = [];
|
1122 | continue;
|
1123 | }
|
1124 | if (prev.type === 'range') {
|
1125 | siblings.pop();
|
1126 | let before = siblings[siblings.length - 1];
|
1127 | before.value += prev.value + value;
|
1128 | prev = before;
|
1129 | block.ranges--;
|
1130 | continue;
|
1131 | }
|
1132 | push({ type: 'dot', value });
|
1133 | continue;
|
1134 | }
|
1135 | |
1136 |
|
1137 |
|
1138 | push({ type: 'text', value });
|
1139 | }
|
1140 |
|
1141 | do {
|
1142 | block = stack.pop();
|
1143 | if (block.type !== 'root') {
|
1144 | block.nodes.forEach(node => {
|
1145 | if (!node.nodes) {
|
1146 | if (node.type === 'open')
|
1147 | node.isOpen = true;
|
1148 | if (node.type === 'close')
|
1149 | node.isClose = true;
|
1150 | if (!node.nodes)
|
1151 | node.type = 'text';
|
1152 | node.invalid = true;
|
1153 | }
|
1154 | });
|
1155 |
|
1156 | let parent = stack[stack.length - 1];
|
1157 | let index = parent.nodes.indexOf(block);
|
1158 |
|
1159 | parent.nodes.splice(index, 1, ...block.nodes);
|
1160 | }
|
1161 | } while (stack.length > 0);
|
1162 | push({ type: 'eos' });
|
1163 | return ast;
|
1164 | };
|
1165 | var parse_1 = parse;
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 | const braces = (input, options = {}) => {
|
1181 | let output = [];
|
1182 | if (Array.isArray(input)) {
|
1183 | for (let pattern of input) {
|
1184 | let result = braces.create(pattern, options);
|
1185 | if (Array.isArray(result)) {
|
1186 | output.push(...result);
|
1187 | }
|
1188 | else {
|
1189 | output.push(result);
|
1190 | }
|
1191 | }
|
1192 | }
|
1193 | else {
|
1194 | output = [].concat(braces.create(input, options));
|
1195 | }
|
1196 | if (options && options.expand === true && options.nodupes === true) {
|
1197 | output = [...new Set(output)];
|
1198 | }
|
1199 | return output;
|
1200 | };
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 | braces.parse = (input, options = {}) => parse_1(input, options);
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 |
|
1225 |
|
1226 |
|
1227 |
|
1228 | braces.stringify = (input, options = {}) => {
|
1229 | if (typeof input === 'string') {
|
1230 | return stringify(braces.parse(input, options), options);
|
1231 | }
|
1232 | return stringify(input, options);
|
1233 | };
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 |
|
1246 |
|
1247 |
|
1248 | braces.compile = (input, options = {}) => {
|
1249 | if (typeof input === 'string') {
|
1250 | input = braces.parse(input, options);
|
1251 | }
|
1252 | return compile_1(input, options);
|
1253 | };
|
1254 |
|
1255 |
|
1256 |
|
1257 |
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 |
|
1267 |
|
1268 |
|
1269 |
|
1270 | braces.expand = (input, options = {}) => {
|
1271 | if (typeof input === 'string') {
|
1272 | input = braces.parse(input, options);
|
1273 | }
|
1274 | let result = expand_1(input, options);
|
1275 |
|
1276 | if (options.noempty === true) {
|
1277 | result = result.filter(Boolean);
|
1278 | }
|
1279 |
|
1280 | if (options.nodupes === true) {
|
1281 | result = [...new Set(result)];
|
1282 | }
|
1283 | return result;
|
1284 | };
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 | braces.create = (input, options = {}) => {
|
1301 | if (input === '' || input.length < 3) {
|
1302 | return [input];
|
1303 | }
|
1304 | return options.expand !== true
|
1305 | ? braces.compile(input, options)
|
1306 | : braces.expand(input, options);
|
1307 | };
|
1308 |
|
1309 |
|
1310 |
|
1311 | var braces_1 = braces;
|
1312 |
|
1313 | const WIN_SLASH = '\\\\/';
|
1314 | const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
1315 |
|
1316 |
|
1317 |
|
1318 | const DOT_LITERAL = '\\.';
|
1319 | const PLUS_LITERAL = '\\+';
|
1320 | const QMARK_LITERAL = '\\?';
|
1321 | const SLASH_LITERAL = '\\/';
|
1322 | const ONE_CHAR = '(?=.)';
|
1323 | const QMARK = '[^/]';
|
1324 | const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
1325 | const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
1326 | const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
1327 | const NO_DOT = `(?!${DOT_LITERAL})`;
|
1328 | const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
1329 | const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
1330 | const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
1331 | const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
1332 | const STAR = `${QMARK}*?`;
|
1333 | const POSIX_CHARS = {
|
1334 | DOT_LITERAL,
|
1335 | PLUS_LITERAL,
|
1336 | QMARK_LITERAL,
|
1337 | SLASH_LITERAL,
|
1338 | ONE_CHAR,
|
1339 | QMARK,
|
1340 | END_ANCHOR,
|
1341 | DOTS_SLASH,
|
1342 | NO_DOT,
|
1343 | NO_DOTS,
|
1344 | NO_DOT_SLASH,
|
1345 | NO_DOTS_SLASH,
|
1346 | QMARK_NO_DOT,
|
1347 | STAR,
|
1348 | START_ANCHOR
|
1349 | };
|
1350 |
|
1351 |
|
1352 |
|
1353 | const WINDOWS_CHARS = Object.assign({}, POSIX_CHARS, { SLASH_LITERAL: `[${WIN_SLASH}]`, QMARK: WIN_NO_SLASH, STAR: `${WIN_NO_SLASH}*?`, DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`, NO_DOT: `(?!${DOT_LITERAL})`, NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`, NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`, NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`, QMARK_NO_DOT: `[^.${WIN_SLASH}]`, START_ANCHOR: `(?:^|[${WIN_SLASH}])`, END_ANCHOR: `(?:[${WIN_SLASH}]|$)` });
|
1354 |
|
1355 |
|
1356 |
|
1357 | const POSIX_REGEX_SOURCE = {
|
1358 | alnum: 'a-zA-Z0-9',
|
1359 | alpha: 'a-zA-Z',
|
1360 | ascii: '\\x00-\\x7F',
|
1361 | blank: ' \\t',
|
1362 | cntrl: '\\x00-\\x1F\\x7F',
|
1363 | digit: '0-9',
|
1364 | graph: '\\x21-\\x7E',
|
1365 | lower: 'a-z',
|
1366 | print: '\\x20-\\x7E ',
|
1367 | punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
|
1368 | space: ' \\t\\r\\n\\v\\f',
|
1369 | upper: 'A-Z',
|
1370 | word: 'A-Za-z0-9_',
|
1371 | xdigit: 'A-Fa-f0-9'
|
1372 | };
|
1373 | var constants$1 = {
|
1374 | MAX_LENGTH: 1024 * 64,
|
1375 | POSIX_REGEX_SOURCE,
|
1376 |
|
1377 | REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
1378 | REGEX_NON_SPECIAL_CHAR: /^[^@![\].,$*+?^{}()|\\/]+/,
|
1379 | REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
1380 | REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
1381 | REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
1382 | REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
1383 |
|
1384 | REPLACEMENTS: {
|
1385 | '***': '*',
|
1386 | '**/**': '**',
|
1387 | '**/**/**': '**'
|
1388 | },
|
1389 |
|
1390 | CHAR_0: 48,
|
1391 | CHAR_9: 57,
|
1392 |
|
1393 | CHAR_UPPERCASE_A: 65,
|
1394 | CHAR_LOWERCASE_A: 97,
|
1395 | CHAR_UPPERCASE_Z: 90,
|
1396 | CHAR_LOWERCASE_Z: 122,
|
1397 | CHAR_LEFT_PARENTHESES: 40,
|
1398 | CHAR_RIGHT_PARENTHESES: 41,
|
1399 | CHAR_ASTERISK: 42,
|
1400 |
|
1401 | CHAR_AMPERSAND: 38,
|
1402 | CHAR_AT: 64,
|
1403 | CHAR_BACKWARD_SLASH: 92,
|
1404 | CHAR_CARRIAGE_RETURN: 13,
|
1405 | CHAR_CIRCUMFLEX_ACCENT: 94,
|
1406 | CHAR_COLON: 58,
|
1407 | CHAR_COMMA: 44,
|
1408 | CHAR_DOT: 46,
|
1409 | CHAR_DOUBLE_QUOTE: 34,
|
1410 | CHAR_EQUAL: 61,
|
1411 | CHAR_EXCLAMATION_MARK: 33,
|
1412 | CHAR_FORM_FEED: 12,
|
1413 | CHAR_FORWARD_SLASH: 47,
|
1414 | CHAR_GRAVE_ACCENT: 96,
|
1415 | CHAR_HASH: 35,
|
1416 | CHAR_HYPHEN_MINUS: 45,
|
1417 | CHAR_LEFT_ANGLE_BRACKET: 60,
|
1418 | CHAR_LEFT_CURLY_BRACE: 123,
|
1419 | CHAR_LEFT_SQUARE_BRACKET: 91,
|
1420 | CHAR_LINE_FEED: 10,
|
1421 | CHAR_NO_BREAK_SPACE: 160,
|
1422 | CHAR_PERCENT: 37,
|
1423 | CHAR_PLUS: 43,
|
1424 | CHAR_QUESTION_MARK: 63,
|
1425 | CHAR_RIGHT_ANGLE_BRACKET: 62,
|
1426 | CHAR_RIGHT_CURLY_BRACE: 125,
|
1427 | CHAR_RIGHT_SQUARE_BRACKET: 93,
|
1428 | CHAR_SEMICOLON: 59,
|
1429 | CHAR_SINGLE_QUOTE: 39,
|
1430 | CHAR_SPACE: 32,
|
1431 | CHAR_TAB: 9,
|
1432 | CHAR_UNDERSCORE: 95,
|
1433 | CHAR_VERTICAL_LINE: 124,
|
1434 | CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
1435 | SEP: path__default.sep,
|
1436 | |
1437 |
|
1438 |
|
1439 | extglobChars(chars) {
|
1440 | return {
|
1441 | '!': { type: 'negate', open: '(?:(?!(?:', close: `))${chars.STAR})` },
|
1442 | '?': { type: 'qmark', open: '(?:', close: ')?' },
|
1443 | '+': { type: 'plus', open: '(?:', close: ')+' },
|
1444 | '*': { type: 'star', open: '(?:', close: ')*' },
|
1445 | '@': { type: 'at', open: '(?:', close: ')' }
|
1446 | };
|
1447 | },
|
1448 | |
1449 |
|
1450 |
|
1451 | globChars(win32) {
|
1452 | return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
1453 | }
|
1454 | };
|
1455 |
|
1456 | var utils$1 = createCommonjsModule(function (module, exports) {
|
1457 | const win32 = process.platform === 'win32';
|
1458 | const { REGEX_SPECIAL_CHARS, REGEX_SPECIAL_CHARS_GLOBAL, REGEX_REMOVE_BACKSLASH } = constants$1;
|
1459 | exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
1460 | exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
|
1461 | exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
|
1462 | exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
|
1463 | exports.toPosixSlashes = str => str.replace(/\\/g, '/');
|
1464 | exports.removeBackslashes = str => {
|
1465 | return str.replace(REGEX_REMOVE_BACKSLASH, match => {
|
1466 | return match === '\\' ? '' : match;
|
1467 | });
|
1468 | };
|
1469 | exports.supportsLookbehinds = () => {
|
1470 | let segs = process.version.slice(1).split('.');
|
1471 | if (segs.length === 3 && +segs[0] >= 9 || (+segs[0] === 8 && +segs[1] >= 10)) {
|
1472 | return true;
|
1473 | }
|
1474 | return false;
|
1475 | };
|
1476 | exports.isWindows = options => {
|
1477 | if (options && typeof options.windows === 'boolean') {
|
1478 | return options.windows;
|
1479 | }
|
1480 | return win32 === true || path__default.sep === '\\';
|
1481 | };
|
1482 | exports.escapeLast = (input, char, lastIdx) => {
|
1483 | let idx = input.lastIndexOf(char, lastIdx);
|
1484 | if (idx === -1)
|
1485 | return input;
|
1486 | if (input[idx - 1] === '\\')
|
1487 | return exports.escapeLast(input, char, idx - 1);
|
1488 | return input.slice(0, idx) + '\\' + input.slice(idx);
|
1489 | };
|
1490 | });
|
1491 | var utils_1$1 = utils$1.isObject;
|
1492 | var utils_2$1 = utils$1.hasRegexChars;
|
1493 | var utils_3$1 = utils$1.isRegexChar;
|
1494 | var utils_4$1 = utils$1.escapeRegex;
|
1495 | var utils_5$1 = utils$1.toPosixSlashes;
|
1496 | var utils_6$1 = utils$1.removeBackslashes;
|
1497 | var utils_7$1 = utils$1.supportsLookbehinds;
|
1498 | var utils_8$1 = utils$1.isWindows;
|
1499 | var utils_9$1 = utils$1.escapeLast;
|
1500 |
|
1501 | const { CHAR_ASTERISK, CHAR_AT, CHAR_BACKWARD_SLASH, CHAR_COMMA: CHAR_COMMA$1, CHAR_DOT: CHAR_DOT$1, CHAR_EXCLAMATION_MARK, CHAR_FORWARD_SLASH, CHAR_LEFT_CURLY_BRACE: CHAR_LEFT_CURLY_BRACE$1, CHAR_LEFT_PARENTHESES: CHAR_LEFT_PARENTHESES$1, CHAR_LEFT_SQUARE_BRACKET: CHAR_LEFT_SQUARE_BRACKET$1, CHAR_PLUS, CHAR_QUESTION_MARK, CHAR_RIGHT_CURLY_BRACE: CHAR_RIGHT_CURLY_BRACE$1, CHAR_RIGHT_PARENTHESES: CHAR_RIGHT_PARENTHESES$1, CHAR_RIGHT_SQUARE_BRACKET: CHAR_RIGHT_SQUARE_BRACKET$1 } = constants$1;
|
1502 | const isPathSeparator = code => {
|
1503 | return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
1504 | };
|
1505 |
|
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 | var scan = (input, options) => {
|
1521 | let opts = options || {};
|
1522 | let length = input.length - 1;
|
1523 | let index = -1;
|
1524 | let start = 0;
|
1525 | let lastIndex = 0;
|
1526 | let isGlob = false;
|
1527 | let backslashes = false;
|
1528 | let negated = false;
|
1529 | let braces = 0;
|
1530 | let prev;
|
1531 | let code;
|
1532 | let braceEscaped = false;
|
1533 | let eos = () => index >= length;
|
1534 | let advance = () => {
|
1535 | prev = code;
|
1536 | return input.charCodeAt(++index);
|
1537 | };
|
1538 | while (index < length) {
|
1539 | code = advance();
|
1540 | let next;
|
1541 | if (code === CHAR_BACKWARD_SLASH) {
|
1542 | backslashes = true;
|
1543 | next = advance();
|
1544 | if (next === CHAR_LEFT_CURLY_BRACE$1) {
|
1545 | braceEscaped = true;
|
1546 | }
|
1547 | continue;
|
1548 | }
|
1549 | if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE$1) {
|
1550 | braces++;
|
1551 | while (!eos() && (next = advance())) {
|
1552 | if (next === CHAR_BACKWARD_SLASH) {
|
1553 | backslashes = true;
|
1554 | next = advance();
|
1555 | continue;
|
1556 | }
|
1557 | if (next === CHAR_LEFT_CURLY_BRACE$1) {
|
1558 | braces++;
|
1559 | continue;
|
1560 | }
|
1561 | if (!braceEscaped && next === CHAR_DOT$1 && (next = advance()) === CHAR_DOT$1) {
|
1562 | isGlob = true;
|
1563 | break;
|
1564 | }
|
1565 | if (!braceEscaped && next === CHAR_COMMA$1) {
|
1566 | isGlob = true;
|
1567 | break;
|
1568 | }
|
1569 | if (next === CHAR_RIGHT_CURLY_BRACE$1) {
|
1570 | braces--;
|
1571 | if (braces === 0) {
|
1572 | braceEscaped = false;
|
1573 | break;
|
1574 | }
|
1575 | }
|
1576 | }
|
1577 | }
|
1578 | if (code === CHAR_FORWARD_SLASH) {
|
1579 | if (prev === CHAR_DOT$1 && index === (start + 1)) {
|
1580 | start += 2;
|
1581 | continue;
|
1582 | }
|
1583 | lastIndex = index + 1;
|
1584 | continue;
|
1585 | }
|
1586 | if (code === CHAR_ASTERISK) {
|
1587 | isGlob = true;
|
1588 | break;
|
1589 | }
|
1590 | if (code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK) {
|
1591 | isGlob = true;
|
1592 | break;
|
1593 | }
|
1594 | if (code === CHAR_LEFT_SQUARE_BRACKET$1) {
|
1595 | while (!eos() && (next = advance())) {
|
1596 | if (next === CHAR_BACKWARD_SLASH) {
|
1597 | backslashes = true;
|
1598 | next = advance();
|
1599 | continue;
|
1600 | }
|
1601 | if (next === CHAR_RIGHT_SQUARE_BRACKET$1) {
|
1602 | isGlob = true;
|
1603 | break;
|
1604 | }
|
1605 | }
|
1606 | }
|
1607 | let isExtglobChar = code === CHAR_PLUS
|
1608 | || code === CHAR_AT
|
1609 | || code === CHAR_EXCLAMATION_MARK;
|
1610 | if (isExtglobChar && input.charCodeAt(index + 1) === CHAR_LEFT_PARENTHESES$1) {
|
1611 | isGlob = true;
|
1612 | break;
|
1613 | }
|
1614 | if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
1615 | negated = true;
|
1616 | start++;
|
1617 | continue;
|
1618 | }
|
1619 | if (code === CHAR_LEFT_PARENTHESES$1) {
|
1620 | while (!eos() && (next = advance())) {
|
1621 | if (next === CHAR_BACKWARD_SLASH) {
|
1622 | backslashes = true;
|
1623 | next = advance();
|
1624 | continue;
|
1625 | }
|
1626 | if (next === CHAR_RIGHT_PARENTHESES$1) {
|
1627 | isGlob = true;
|
1628 | break;
|
1629 | }
|
1630 | }
|
1631 | }
|
1632 | if (isGlob) {
|
1633 | break;
|
1634 | }
|
1635 | }
|
1636 | let prefix = '';
|
1637 | let orig = input;
|
1638 | let base = input;
|
1639 | let glob = '';
|
1640 | if (start > 0) {
|
1641 | prefix = input.slice(0, start);
|
1642 | input = input.slice(start);
|
1643 | lastIndex -= start;
|
1644 | }
|
1645 | if (base && isGlob === true && lastIndex > 0) {
|
1646 | base = input.slice(0, lastIndex);
|
1647 | glob = input.slice(lastIndex);
|
1648 | }
|
1649 | else if (isGlob === true) {
|
1650 | base = '';
|
1651 | glob = input;
|
1652 | }
|
1653 | else {
|
1654 | base = input;
|
1655 | }
|
1656 | if (base && base !== '' && base !== '/' && base !== input) {
|
1657 | if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
1658 | base = base.slice(0, -1);
|
1659 | }
|
1660 | }
|
1661 | if (opts.unescape === true) {
|
1662 | if (glob)
|
1663 | glob = utils$1.removeBackslashes(glob);
|
1664 | if (base && backslashes === true) {
|
1665 | base = utils$1.removeBackslashes(base);
|
1666 | }
|
1667 | }
|
1668 | return { prefix, input: orig, base, glob, negated, isGlob };
|
1669 | };
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 | const { MAX_LENGTH: MAX_LENGTH$1, POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1, REGEX_NON_SPECIAL_CHAR, REGEX_SPECIAL_CHARS_BACKREF, REPLACEMENTS } = constants$1;
|
1675 |
|
1676 |
|
1677 |
|
1678 | const expandRange = (args, options) => {
|
1679 | if (typeof options.expandRange === 'function') {
|
1680 | return options.expandRange(...args, options);
|
1681 | }
|
1682 | args.sort();
|
1683 | let value = `[${args.join('-')}]`;
|
1684 | try {
|
1685 | }
|
1686 | catch (ex) {
|
1687 | return args.map(v => utils$1.escapeRegex(v)).join('..');
|
1688 | }
|
1689 | return value;
|
1690 | };
|
1691 | const negate = state => {
|
1692 | let count = 1;
|
1693 | while (state.peek() === '!' && (state.peek(2) !== '(' || state.peek(3) === '?')) {
|
1694 | state.advance();
|
1695 | state.start++;
|
1696 | count++;
|
1697 | }
|
1698 | if (count % 2 === 0) {
|
1699 | return false;
|
1700 | }
|
1701 | state.negated = true;
|
1702 | state.start++;
|
1703 | return true;
|
1704 | };
|
1705 |
|
1706 |
|
1707 |
|
1708 | const syntaxError = (type, char) => {
|
1709 | return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
1710 | };
|
1711 |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 | const parse$1 = (input, options) => {
|
1718 | if (typeof input !== 'string') {
|
1719 | throw new TypeError('Expected a string');
|
1720 | }
|
1721 | input = REPLACEMENTS[input] || input;
|
1722 | let opts = Object.assign({}, options);
|
1723 | let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
|
1724 | let len = input.length;
|
1725 | if (len > max) {
|
1726 | throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
1727 | }
|
1728 | let bos = { type: 'bos', value: '', output: opts.prepend || '' };
|
1729 | let tokens = [bos];
|
1730 | let capture = opts.capture ? '' : '?:';
|
1731 | let win32 = utils$1.isWindows(options);
|
1732 |
|
1733 | const PLATFORM_CHARS = constants$1.globChars(win32);
|
1734 | const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
|
1735 | const { DOT_LITERAL, PLUS_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOT_SLASH, NO_DOTS_SLASH, QMARK, QMARK_NO_DOT, STAR, START_ANCHOR } = PLATFORM_CHARS;
|
1736 | const globstar = (opts) => {
|
1737 | return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
1738 | };
|
1739 | let nodot = opts.dot ? '' : NO_DOT;
|
1740 | let star = opts.bash === true ? globstar(opts) : STAR;
|
1741 | let qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
1742 | if (opts.capture) {
|
1743 | star = `(${star})`;
|
1744 | }
|
1745 |
|
1746 | if (typeof opts.noext === 'boolean') {
|
1747 | opts.noextglob = opts.noext;
|
1748 | }
|
1749 | let state = {
|
1750 | index: -1,
|
1751 | start: 0,
|
1752 | consumed: '',
|
1753 | output: '',
|
1754 | backtrack: false,
|
1755 | brackets: 0,
|
1756 | braces: 0,
|
1757 | parens: 0,
|
1758 | quotes: 0,
|
1759 | tokens
|
1760 | };
|
1761 | let extglobs = [];
|
1762 | let stack = [];
|
1763 | let prev = bos;
|
1764 | let value;
|
1765 | |
1766 |
|
1767 |
|
1768 | const eos = () => state.index === len - 1;
|
1769 | const peek = state.peek = (n = 1) => input[state.index + n];
|
1770 | const advance = state.advance = () => input[++state.index];
|
1771 | const append = token => {
|
1772 | state.output += token.output != null ? token.output : token.value;
|
1773 | state.consumed += token.value || '';
|
1774 | };
|
1775 | const increment = type => {
|
1776 | state[type]++;
|
1777 | stack.push(type);
|
1778 | };
|
1779 | const decrement = type => {
|
1780 | state[type]--;
|
1781 | stack.pop();
|
1782 | };
|
1783 | |
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 | const push = tok => {
|
1791 | if (prev.type === 'globstar') {
|
1792 | let isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
|
1793 | let isExtglob = extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
|
1794 | if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
|
1795 | state.output = state.output.slice(0, -prev.output.length);
|
1796 | prev.type = 'star';
|
1797 | prev.value = '*';
|
1798 | prev.output = star;
|
1799 | state.output += prev.output;
|
1800 | }
|
1801 | }
|
1802 | if (extglobs.length && tok.type !== 'paren' && !EXTGLOB_CHARS[tok.value]) {
|
1803 | extglobs[extglobs.length - 1].inner += tok.value;
|
1804 | }
|
1805 | if (tok.value || tok.output)
|
1806 | append(tok);
|
1807 | if (prev && prev.type === 'text' && tok.type === 'text') {
|
1808 | prev.value += tok.value;
|
1809 | return;
|
1810 | }
|
1811 | tok.prev = prev;
|
1812 | tokens.push(tok);
|
1813 | prev = tok;
|
1814 | };
|
1815 | const extglobOpen = (type, value) => {
|
1816 | let token = Object.assign({}, EXTGLOB_CHARS[value], { conditions: 1, inner: '' });
|
1817 | token.prev = prev;
|
1818 | token.parens = state.parens;
|
1819 | token.output = state.output;
|
1820 | let output = (opts.capture ? '(' : '') + token.open;
|
1821 | push({ type, value, output: state.output ? '' : ONE_CHAR });
|
1822 | push({ type: 'paren', extglob: true, value: advance(), output });
|
1823 | increment('parens');
|
1824 | extglobs.push(token);
|
1825 | };
|
1826 | const extglobClose = token => {
|
1827 | let output = token.close + (opts.capture ? ')' : '');
|
1828 | if (token.type === 'negate') {
|
1829 | let extglobStar = star;
|
1830 | if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
|
1831 | extglobStar = globstar(opts);
|
1832 | }
|
1833 | if (extglobStar !== star || eos() || /^\)+$/.test(input.slice(state.index + 1))) {
|
1834 | output = token.close = ')$))' + extglobStar;
|
1835 | }
|
1836 | if (token.prev.type === 'bos' && eos()) {
|
1837 | state.negatedExtglob = true;
|
1838 | }
|
1839 | }
|
1840 | push({ type: 'paren', extglob: true, value, output });
|
1841 | decrement('parens');
|
1842 | };
|
1843 | if (opts.fastpaths !== false && !/(^[*!]|[/{[()\]}"])/.test(input)) {
|
1844 | let backslashes = false;
|
1845 | let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
1846 | if (first === '\\') {
|
1847 | backslashes = true;
|
1848 | return m;
|
1849 | }
|
1850 | if (first === '?') {
|
1851 | if (esc) {
|
1852 | return esc + first + (rest ? QMARK.repeat(rest.length) : '');
|
1853 | }
|
1854 | if (index === 0) {
|
1855 | return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
|
1856 | }
|
1857 | return QMARK.repeat(chars.length);
|
1858 | }
|
1859 | if (first === '.') {
|
1860 | return DOT_LITERAL.repeat(chars.length);
|
1861 | }
|
1862 | if (first === '*') {
|
1863 | if (esc) {
|
1864 | return esc + first + (rest ? star : '');
|
1865 | }
|
1866 | return star;
|
1867 | }
|
1868 | return esc ? m : '\\' + m;
|
1869 | });
|
1870 | if (backslashes === true) {
|
1871 | if (opts.unescape === true) {
|
1872 | output = output.replace(/\\/g, '');
|
1873 | }
|
1874 | else {
|
1875 | output = output.replace(/\\+/g, m => {
|
1876 | return m.length % 2 === 0 ? '\\\\' : (m ? '\\' : '');
|
1877 | });
|
1878 | }
|
1879 | }
|
1880 | state.output = output;
|
1881 | return state;
|
1882 | }
|
1883 | |
1884 |
|
1885 |
|
1886 | while (!eos()) {
|
1887 | value = advance();
|
1888 | if (value === '\u0000') {
|
1889 | continue;
|
1890 | }
|
1891 | |
1892 |
|
1893 |
|
1894 | if (value === '\\') {
|
1895 | let next = peek();
|
1896 | if (next === '/' && opts.bash !== true) {
|
1897 | continue;
|
1898 | }
|
1899 | if (next === '.' || next === ';') {
|
1900 | continue;
|
1901 | }
|
1902 | if (!next) {
|
1903 | value += '\\';
|
1904 | push({ type: 'text', value });
|
1905 | continue;
|
1906 | }
|
1907 |
|
1908 | let match = /^\\+/.exec(input.slice(state.index + 1));
|
1909 | let slashes = 0;
|
1910 | if (match && match[0].length > 2) {
|
1911 | slashes = match[0].length;
|
1912 | state.index += slashes;
|
1913 | if (slashes % 2 !== 0) {
|
1914 | value += '\\';
|
1915 | }
|
1916 | }
|
1917 | if (opts.unescape === true) {
|
1918 | value = advance() || '';
|
1919 | }
|
1920 | else {
|
1921 | value += advance() || '';
|
1922 | }
|
1923 | if (state.brackets === 0) {
|
1924 | push({ type: 'text', value });
|
1925 | continue;
|
1926 | }
|
1927 | }
|
1928 | |
1929 |
|
1930 |
|
1931 |
|
1932 | if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
|
1933 | if (opts.posix !== false && value === ':') {
|
1934 | let inner = prev.value.slice(1);
|
1935 | if (inner.includes('[')) {
|
1936 | prev.posix = true;
|
1937 | if (inner.includes(':')) {
|
1938 | let idx = prev.value.lastIndexOf('[');
|
1939 | let pre = prev.value.slice(0, idx);
|
1940 | let rest = prev.value.slice(idx + 2);
|
1941 | let posix = POSIX_REGEX_SOURCE$1[rest];
|
1942 | if (posix) {
|
1943 | prev.value = pre + posix;
|
1944 | state.backtrack = true;
|
1945 | advance();
|
1946 | if (!bos.output && tokens.indexOf(prev) === 1) {
|
1947 | bos.output = ONE_CHAR;
|
1948 | }
|
1949 | continue;
|
1950 | }
|
1951 | }
|
1952 | }
|
1953 | }
|
1954 | if ((value === '[' && peek() !== ':') || (value === '-' && peek() === ']')) {
|
1955 | value = '\\' + value;
|
1956 | }
|
1957 | if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
|
1958 | value = '\\' + value;
|
1959 | }
|
1960 | if (opts.posix === true && value === '!' && prev.value === '[') {
|
1961 | value = '^';
|
1962 | }
|
1963 | prev.value += value;
|
1964 | append({ value });
|
1965 | continue;
|
1966 | }
|
1967 | |
1968 |
|
1969 |
|
1970 |
|
1971 | if (state.quotes === 1 && value !== '"') {
|
1972 | value = utils$1.escapeRegex(value);
|
1973 | prev.value += value;
|
1974 | append({ value });
|
1975 | continue;
|
1976 | }
|
1977 | |
1978 |
|
1979 |
|
1980 | if (value === '"') {
|
1981 | state.quotes = state.quotes === 1 ? 0 : 1;
|
1982 | if (opts.keepQuotes === true) {
|
1983 | push({ type: 'text', value });
|
1984 | }
|
1985 | continue;
|
1986 | }
|
1987 | |
1988 |
|
1989 |
|
1990 | if (value === '(') {
|
1991 | push({ type: 'paren', value });
|
1992 | increment('parens');
|
1993 | continue;
|
1994 | }
|
1995 | if (value === ')') {
|
1996 | if (state.parens === 0 && opts.strictBrackets === true) {
|
1997 | throw new SyntaxError(syntaxError('opening', '('));
|
1998 | }
|
1999 | let extglob = extglobs[extglobs.length - 1];
|
2000 | if (extglob && state.parens === extglob.parens + 1) {
|
2001 | extglobClose(extglobs.pop());
|
2002 | continue;
|
2003 | }
|
2004 | push({ type: 'paren', value, output: state.parens ? ')' : '\\)' });
|
2005 | decrement('parens');
|
2006 | continue;
|
2007 | }
|
2008 | |
2009 |
|
2010 |
|
2011 | if (value === '[') {
|
2012 | if (opts.nobracket === true || !input.slice(state.index + 1).includes(']')) {
|
2013 | if (opts.nobracket !== true && opts.strictBrackets === true) {
|
2014 | throw new SyntaxError(syntaxError('closing', ']'));
|
2015 | }
|
2016 | value = '\\' + value;
|
2017 | }
|
2018 | else {
|
2019 | increment('brackets');
|
2020 | }
|
2021 | push({ type: 'bracket', value });
|
2022 | continue;
|
2023 | }
|
2024 | if (value === ']') {
|
2025 | if (opts.nobracket === true || (prev && prev.type === 'bracket' && prev.value.length === 1)) {
|
2026 | push({ type: 'text', value, output: '\\' + value });
|
2027 | continue;
|
2028 | }
|
2029 | if (state.brackets === 0) {
|
2030 | if (opts.strictBrackets === true) {
|
2031 | throw new SyntaxError(syntaxError('opening', '['));
|
2032 | }
|
2033 | push({ type: 'text', value, output: '\\' + value });
|
2034 | continue;
|
2035 | }
|
2036 | decrement('brackets');
|
2037 | let prevValue = prev.value.slice(1);
|
2038 | if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
|
2039 | value = '/' + value;
|
2040 | }
|
2041 | prev.value += value;
|
2042 | append({ value });
|
2043 |
|
2044 |
|
2045 | if (opts.literalBrackets === false || utils$1.hasRegexChars(prevValue)) {
|
2046 | continue;
|
2047 | }
|
2048 | let escaped = utils$1.escapeRegex(prev.value);
|
2049 | state.output = state.output.slice(0, -prev.value.length);
|
2050 |
|
2051 |
|
2052 | if (opts.literalBrackets === true) {
|
2053 | state.output += escaped;
|
2054 | prev.value = escaped;
|
2055 | continue;
|
2056 | }
|
2057 |
|
2058 | prev.value = `(${capture}${escaped}|${prev.value})`;
|
2059 | state.output += prev.value;
|
2060 | continue;
|
2061 | }
|
2062 | |
2063 |
|
2064 |
|
2065 | if (value === '{' && opts.nobrace !== true) {
|
2066 | push({ type: 'brace', value, output: '(' });
|
2067 | increment('braces');
|
2068 | continue;
|
2069 | }
|
2070 | if (value === '}') {
|
2071 | if (opts.nobrace === true || state.braces === 0) {
|
2072 | push({ type: 'text', value, output: '\\' + value });
|
2073 | continue;
|
2074 | }
|
2075 | let output = ')';
|
2076 | if (state.dots === true) {
|
2077 | let arr = tokens.slice();
|
2078 | let range = [];
|
2079 | for (let i = arr.length - 1; i >= 0; i--) {
|
2080 | tokens.pop();
|
2081 | if (arr[i].type === 'brace') {
|
2082 | break;
|
2083 | }
|
2084 | if (arr[i].type !== 'dots') {
|
2085 | range.unshift(arr[i].value);
|
2086 | }
|
2087 | }
|
2088 | output = expandRange(range, opts);
|
2089 | state.backtrack = true;
|
2090 | }
|
2091 | push({ type: 'brace', value, output });
|
2092 | decrement('braces');
|
2093 | continue;
|
2094 | }
|
2095 | |
2096 |
|
2097 |
|
2098 | if (value === '|') {
|
2099 | if (extglobs.length > 0) {
|
2100 | extglobs[extglobs.length - 1].conditions++;
|
2101 | }
|
2102 | push({ type: 'text', value });
|
2103 | continue;
|
2104 | }
|
2105 | |
2106 |
|
2107 |
|
2108 | if (value === ',') {
|
2109 | let output = value;
|
2110 | if (state.braces > 0 && stack[stack.length - 1] === 'braces') {
|
2111 | output = '|';
|
2112 | }
|
2113 | push({ type: 'comma', value, output });
|
2114 | continue;
|
2115 | }
|
2116 | |
2117 |
|
2118 |
|
2119 | if (value === '/') {
|
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 | if (prev.type === 'dot' && state.index === 1) {
|
2125 | state.start = state.index + 1;
|
2126 | state.consumed = '';
|
2127 | state.output = '';
|
2128 | tokens.pop();
|
2129 | prev = bos;
|
2130 | continue;
|
2131 | }
|
2132 | push({ type: 'slash', value, output: SLASH_LITERAL });
|
2133 | continue;
|
2134 | }
|
2135 | |
2136 |
|
2137 |
|
2138 | if (value === '.') {
|
2139 | if (state.braces > 0 && prev.type === 'dot') {
|
2140 | if (prev.value === '.')
|
2141 | prev.output = DOT_LITERAL;
|
2142 | prev.type = 'dots';
|
2143 | prev.output += value;
|
2144 | prev.value += value;
|
2145 | state.dots = true;
|
2146 | continue;
|
2147 | }
|
2148 | push({ type: 'dot', value, output: DOT_LITERAL });
|
2149 | continue;
|
2150 | }
|
2151 | |
2152 |
|
2153 |
|
2154 | if (value === '?') {
|
2155 | if (prev && prev.type === 'paren') {
|
2156 | let next = peek();
|
2157 | let output = value;
|
2158 | if (next === '<' && !utils$1.supportsLookbehinds()) {
|
2159 | throw new Error('Node.js v10 or higher is required for regex lookbehinds');
|
2160 | }
|
2161 | if (prev.value === '(' && !/[!=<:]/.test(next) || (next === '<' && !/[!=]/.test(peek(2)))) {
|
2162 | output = '\\' + value;
|
2163 | }
|
2164 | push({ type: 'text', value, output });
|
2165 | continue;
|
2166 | }
|
2167 | if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
2168 | extglobOpen('qmark', value);
|
2169 | continue;
|
2170 | }
|
2171 | if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
|
2172 | push({ type: 'qmark', value, output: QMARK_NO_DOT });
|
2173 | continue;
|
2174 | }
|
2175 | push({ type: 'qmark', value, output: QMARK });
|
2176 | continue;
|
2177 | }
|
2178 | |
2179 |
|
2180 |
|
2181 | if (value === '!') {
|
2182 | if (opts.noextglob !== true && peek() === '(') {
|
2183 | if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
|
2184 | extglobOpen('negate', value);
|
2185 | continue;
|
2186 | }
|
2187 | }
|
2188 | if (opts.nonegate !== true && state.index === 0) {
|
2189 | negate(state);
|
2190 | continue;
|
2191 | }
|
2192 | }
|
2193 | |
2194 |
|
2195 |
|
2196 | if (value === '+') {
|
2197 | if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
2198 | extglobOpen('plus', value);
|
2199 | continue;
|
2200 | }
|
2201 | if (prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace')) {
|
2202 | let output = prev.extglob === true ? '\\' + value : value;
|
2203 | push({ type: 'plus', value, output });
|
2204 | continue;
|
2205 | }
|
2206 |
|
2207 | if (state.parens > 0 && opts.regex !== false) {
|
2208 | push({ type: 'plus', value });
|
2209 | continue;
|
2210 | }
|
2211 | push({ type: 'plus', value: PLUS_LITERAL });
|
2212 | continue;
|
2213 | }
|
2214 | |
2215 |
|
2216 |
|
2217 | if (value === '@') {
|
2218 | if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
2219 | push({ type: 'at', value, output: '' });
|
2220 | continue;
|
2221 | }
|
2222 | push({ type: 'text', value });
|
2223 | continue;
|
2224 | }
|
2225 | |
2226 |
|
2227 |
|
2228 | if (value !== '*') {
|
2229 | if (value === '$' || value === '^') {
|
2230 | value = '\\' + value;
|
2231 | }
|
2232 | let match = REGEX_NON_SPECIAL_CHAR.exec(input.slice(state.index + 1));
|
2233 | if (match) {
|
2234 | value += match[0];
|
2235 | state.index += match[0].length;
|
2236 | }
|
2237 | push({ type: 'text', value });
|
2238 | continue;
|
2239 | }
|
2240 | |
2241 |
|
2242 |
|
2243 | if (prev && (prev.type === 'globstar' || prev.star === true)) {
|
2244 | prev.type = 'star';
|
2245 | prev.star = true;
|
2246 | prev.value += value;
|
2247 | prev.output = star;
|
2248 | state.backtrack = true;
|
2249 | state.consumed += value;
|
2250 | continue;
|
2251 | }
|
2252 | if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
2253 | extglobOpen('star', value);
|
2254 | continue;
|
2255 | }
|
2256 | if (prev.type === 'star') {
|
2257 | if (opts.noglobstar === true) {
|
2258 | state.consumed += value;
|
2259 | continue;
|
2260 | }
|
2261 | let prior = prev.prev;
|
2262 | let before = prior.prev;
|
2263 | let isStart = prior.type === 'slash' || prior.type === 'bos';
|
2264 | let afterStar = before && (before.type === 'star' || before.type === 'globstar');
|
2265 | if (opts.bash === true && (!isStart || (!eos() && peek() !== '/'))) {
|
2266 | push({ type: 'star', value, output: '' });
|
2267 | continue;
|
2268 | }
|
2269 | let isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
|
2270 | let isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
|
2271 | if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
|
2272 | push({ type: 'star', value, output: '' });
|
2273 | continue;
|
2274 | }
|
2275 |
|
2276 | while (input.slice(state.index + 1, state.index + 4) === '/**') {
|
2277 | let after = input[state.index + 4];
|
2278 | if (after && after !== '/') {
|
2279 | break;
|
2280 | }
|
2281 | state.consumed += '/**';
|
2282 | state.index += 3;
|
2283 | }
|
2284 | if (prior.type === 'bos' && eos()) {
|
2285 | prev.type = 'globstar';
|
2286 | prev.value += value;
|
2287 | prev.output = globstar(opts);
|
2288 | state.output = prev.output;
|
2289 | state.consumed += value;
|
2290 | continue;
|
2291 | }
|
2292 | if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
|
2293 | state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
2294 | prior.output = '(?:' + prior.output;
|
2295 | prev.type = 'globstar';
|
2296 | prev.output = globstar(opts) + '|$)';
|
2297 | prev.value += value;
|
2298 | state.output += prior.output + prev.output;
|
2299 | state.consumed += value;
|
2300 | continue;
|
2301 | }
|
2302 | let next = peek();
|
2303 | if (prior.type === 'slash' && prior.prev.type !== 'bos' && next === '/') {
|
2304 | let end = peek(2) !== void 0 ? '|$' : '';
|
2305 | state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
2306 | prior.output = '(?:' + prior.output;
|
2307 | prev.type = 'globstar';
|
2308 | prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
2309 | prev.value += value;
|
2310 | state.output += prior.output + prev.output;
|
2311 | state.consumed += value + advance();
|
2312 | push({ type: 'slash', value, output: '' });
|
2313 | continue;
|
2314 | }
|
2315 | if (prior.type === 'bos' && next === '/') {
|
2316 | prev.type = 'globstar';
|
2317 | prev.value += value;
|
2318 | prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
2319 | state.output = prev.output;
|
2320 | state.consumed += value + advance();
|
2321 | push({ type: 'slash', value, output: '' });
|
2322 | continue;
|
2323 | }
|
2324 |
|
2325 | state.output = state.output.slice(0, -prev.output.length);
|
2326 |
|
2327 | prev.type = 'globstar';
|
2328 | prev.output = globstar(opts);
|
2329 | prev.value += value;
|
2330 |
|
2331 | state.output += prev.output;
|
2332 | state.consumed += value;
|
2333 | continue;
|
2334 | }
|
2335 | let token = { type: 'star', value, output: star };
|
2336 | if (opts.bash === true) {
|
2337 | token.output = '.*?';
|
2338 | if (prev.type === 'bos' || prev.type === 'slash') {
|
2339 | token.output = nodot + token.output;
|
2340 | }
|
2341 | push(token);
|
2342 | continue;
|
2343 | }
|
2344 | if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
|
2345 | token.output = value;
|
2346 | push(token);
|
2347 | continue;
|
2348 | }
|
2349 | if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
|
2350 | if (prev.type === 'dot') {
|
2351 | state.output += NO_DOT_SLASH;
|
2352 | prev.output += NO_DOT_SLASH;
|
2353 | }
|
2354 | else if (opts.dot === true) {
|
2355 | state.output += NO_DOTS_SLASH;
|
2356 | prev.output += NO_DOTS_SLASH;
|
2357 | }
|
2358 | else {
|
2359 | state.output += nodot;
|
2360 | prev.output += nodot;
|
2361 | }
|
2362 | if (peek() !== '*') {
|
2363 | state.output += ONE_CHAR;
|
2364 | prev.output += ONE_CHAR;
|
2365 | }
|
2366 | }
|
2367 | push(token);
|
2368 | }
|
2369 | while (state.brackets > 0) {
|
2370 | if (opts.strictBrackets === true)
|
2371 | throw new SyntaxError(syntaxError('closing', ']'));
|
2372 | state.output = utils$1.escapeLast(state.output, '[');
|
2373 | decrement('brackets');
|
2374 | }
|
2375 | while (state.parens > 0) {
|
2376 | if (opts.strictBrackets === true)
|
2377 | throw new SyntaxError(syntaxError('closing', ')'));
|
2378 | state.output = utils$1.escapeLast(state.output, '(');
|
2379 | decrement('parens');
|
2380 | }
|
2381 | while (state.braces > 0) {
|
2382 | if (opts.strictBrackets === true)
|
2383 | throw new SyntaxError(syntaxError('closing', '}'));
|
2384 | state.output = utils$1.escapeLast(state.output, '{');
|
2385 | decrement('braces');
|
2386 | }
|
2387 | if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
|
2388 | push({ type: 'maybe_slash', value: '', output: `${SLASH_LITERAL}?` });
|
2389 | }
|
2390 |
|
2391 | if (state.backtrack === true) {
|
2392 | state.output = '';
|
2393 | for (let token of state.tokens) {
|
2394 | state.output += token.output != null ? token.output : token.value;
|
2395 | if (token.suffix) {
|
2396 | state.output += token.suffix;
|
2397 | }
|
2398 | }
|
2399 | }
|
2400 | return state;
|
2401 | };
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 | parse$1.fastpaths = (input, options) => {
|
2408 | let opts = Object.assign({}, options);
|
2409 | let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
|
2410 | let len = input.length;
|
2411 | if (len > max) {
|
2412 | throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
2413 | }
|
2414 | input = REPLACEMENTS[input] || input;
|
2415 | let win32 = utils$1.isWindows(options);
|
2416 |
|
2417 | const { DOT_LITERAL, SLASH_LITERAL, ONE_CHAR, DOTS_SLASH, NO_DOT, NO_DOTS, NO_DOTS_SLASH, STAR, START_ANCHOR } = constants$1.globChars(win32);
|
2418 | let capture = opts.capture ? '' : '?:';
|
2419 | let star = opts.bash === true ? '.*?' : STAR;
|
2420 | let nodot = opts.dot ? NO_DOTS : NO_DOT;
|
2421 | let slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
2422 | if (opts.capture) {
|
2423 | star = `(${star})`;
|
2424 | }
|
2425 | const globstar = (opts) => {
|
2426 | return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
2427 | };
|
2428 | const create = str => {
|
2429 | switch (str) {
|
2430 | case '*':
|
2431 | return `${nodot}${ONE_CHAR}${star}`;
|
2432 | case '.*':
|
2433 | return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
2434 | case '*.*':
|
2435 | return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
2436 | case '*/*':
|
2437 | return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
2438 | case '**':
|
2439 | return nodot + globstar(opts);
|
2440 | case '**/*':
|
2441 | return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
2442 | case '**/*.*':
|
2443 | return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
2444 | case '**/.*':
|
2445 | return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
2446 | default: {
|
2447 | let match = /^(.*?)\.(\w+)$/.exec(str);
|
2448 | if (!match)
|
2449 | return;
|
2450 | let source = create(match[1], options);
|
2451 | if (!source)
|
2452 | return;
|
2453 | return source + DOT_LITERAL + match[2];
|
2454 | }
|
2455 | }
|
2456 | };
|
2457 | let output = create(input);
|
2458 | if (output && opts.strictSlashes !== true) {
|
2459 | output += `${SLASH_LITERAL}?`;
|
2460 | }
|
2461 | return output;
|
2462 | };
|
2463 | var parse_1$1 = parse$1;
|
2464 |
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 | const picomatch = (glob, options, returnState = false) => {
|
2487 | if (Array.isArray(glob)) {
|
2488 | let fns = glob.map(input => picomatch(input, options, returnState));
|
2489 | return str => {
|
2490 | for (let isMatch of fns) {
|
2491 | let state = isMatch(str);
|
2492 | if (state)
|
2493 | return state;
|
2494 | }
|
2495 | return false;
|
2496 | };
|
2497 | }
|
2498 | if (typeof glob !== 'string' || glob === '') {
|
2499 | throw new TypeError('Expected pattern to be a non-empty string');
|
2500 | }
|
2501 | let opts = options || {};
|
2502 | let posix = utils$1.isWindows(options);
|
2503 | let regex = picomatch.makeRe(glob, options, false, true);
|
2504 | let state = regex.state;
|
2505 | delete regex.state;
|
2506 | let isIgnored = () => false;
|
2507 | if (opts.ignore) {
|
2508 | let ignoreOpts = Object.assign({}, options, { ignore: null, onMatch: null, onResult: null });
|
2509 | isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
2510 | }
|
2511 | const matcher = (input, returnObject = false) => {
|
2512 | let { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
|
2513 | let result = { glob, state, regex, posix, input, output, match, isMatch };
|
2514 | if (typeof opts.onResult === 'function') {
|
2515 | opts.onResult(result);
|
2516 | }
|
2517 | if (isMatch === false) {
|
2518 | result.isMatch = false;
|
2519 | return returnObject ? result : false;
|
2520 | }
|
2521 | if (isIgnored(input)) {
|
2522 | if (typeof opts.onIgnore === 'function') {
|
2523 | opts.onIgnore(result);
|
2524 | }
|
2525 | result.isMatch = false;
|
2526 | return returnObject ? result : false;
|
2527 | }
|
2528 | if (typeof opts.onMatch === 'function') {
|
2529 | opts.onMatch(result);
|
2530 | }
|
2531 | return returnObject ? result : true;
|
2532 | };
|
2533 | if (returnState) {
|
2534 | matcher.state = state;
|
2535 | }
|
2536 | return matcher;
|
2537 | };
|
2538 |
|
2539 |
|
2540 |
|
2541 |
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 |
|
2554 | picomatch.test = (input, regex, options, { glob, posix } = {}) => {
|
2555 | if (typeof input !== 'string') {
|
2556 | throw new TypeError('Expected input to be a string');
|
2557 | }
|
2558 | if (input === '') {
|
2559 | return { isMatch: false, output: '' };
|
2560 | }
|
2561 | let opts = options || {};
|
2562 | let format = opts.format || (posix ? utils$1.toPosixSlashes : null);
|
2563 | let match = input === glob;
|
2564 | let output = (match && format) ? format(input) : input;
|
2565 | if (match === false) {
|
2566 | output = format ? format(input) : input;
|
2567 | match = output === glob;
|
2568 | }
|
2569 | if (match === false || opts.capture === true) {
|
2570 | if (opts.matchBase === true || opts.basename === true) {
|
2571 | match = picomatch.matchBase(input, regex, options, posix);
|
2572 | }
|
2573 | else {
|
2574 | match = regex.exec(output);
|
2575 | }
|
2576 | }
|
2577 | return { isMatch: !!match, match, output };
|
2578 | };
|
2579 |
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 | picomatch.matchBase = (input, glob, options, posix = utils$1.isWindows(options)) => {
|
2593 | let regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
2594 | return regex.test(path__default.basename(input));
|
2595 | };
|
2596 |
|
2597 |
|
2598 |
|
2599 |
|
2600 |
|
2601 |
|
2602 |
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 |
|
2612 | picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 | picomatch.parse = (glob, options) => parse_1$1(glob, options);
|
2627 |
|
2628 |
|
2629 |
|
2630 |
|
2631 |
|
2632 |
|
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 | picomatch.scan = (input, options) => scan(input, options);
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 | picomatch.makeRe = (input, options, returnOutput = false, returnState = false) => {
|
2665 | if (!input || typeof input !== 'string') {
|
2666 | throw new TypeError('Expected a non-empty string');
|
2667 | }
|
2668 | let opts = options || {};
|
2669 | let prepend = opts.contains ? '' : '^';
|
2670 | let append = opts.contains ? '' : '$';
|
2671 | let state = { negated: false, fastpaths: true };
|
2672 | let prefix = '';
|
2673 | let output;
|
2674 | if (input.startsWith('./')) {
|
2675 | input = input.slice(2);
|
2676 | prefix = state.prefix = './';
|
2677 | }
|
2678 | if (opts.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
|
2679 | output = parse_1$1.fastpaths(input, options);
|
2680 | }
|
2681 | if (output === void 0) {
|
2682 | state = picomatch.parse(input, options);
|
2683 | state.prefix = prefix + (state.prefix || '');
|
2684 | output = state.output;
|
2685 | }
|
2686 | if (returnOutput === true) {
|
2687 | return output;
|
2688 | }
|
2689 | let source = `${prepend}(?:${output})${append}`;
|
2690 | if (state && state.negated === true) {
|
2691 | source = `^(?!${source}).*$`;
|
2692 | }
|
2693 | let regex = picomatch.toRegex(source, options);
|
2694 | if (returnState === true) {
|
2695 | regex.state = state;
|
2696 | }
|
2697 | return regex;
|
2698 | };
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 | picomatch.toRegex = (source, options) => {
|
2716 | try {
|
2717 | let opts = options || {};
|
2718 | return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
2719 | }
|
2720 | catch (err) {
|
2721 | if (options && options.debug === true)
|
2722 | throw err;
|
2723 | return /$^/;
|
2724 | }
|
2725 | };
|
2726 |
|
2727 |
|
2728 |
|
2729 |
|
2730 | picomatch.constants = constants$1;
|
2731 |
|
2732 |
|
2733 |
|
2734 | var picomatch_1 = picomatch;
|
2735 |
|
2736 | var picomatch$1 = picomatch_1;
|
2737 |
|
2738 | const isEmptyString = val => typeof val === 'string' && (val === '' || val === './');
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 | const micromatch = (list, patterns, options) => {
|
2757 | patterns = [].concat(patterns);
|
2758 | list = [].concat(list);
|
2759 | let omit = new Set();
|
2760 | let keep = new Set();
|
2761 | let items = new Set();
|
2762 | let negatives = 0;
|
2763 | let onResult = state => {
|
2764 | items.add(state.output);
|
2765 | if (options && options.onResult) {
|
2766 | options.onResult(state);
|
2767 | }
|
2768 | };
|
2769 | for (let i = 0; i < patterns.length; i++) {
|
2770 | let isMatch = picomatch$1(String(patterns[i]), Object.assign({}, options, { onResult }), true);
|
2771 | let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
|
2772 | if (negated)
|
2773 | negatives++;
|
2774 | for (let item of list) {
|
2775 | let matched = isMatch(item, true);
|
2776 | let match = negated ? !matched.isMatch : matched.isMatch;
|
2777 | if (!match)
|
2778 | continue;
|
2779 | if (negated) {
|
2780 | omit.add(matched.output);
|
2781 | }
|
2782 | else {
|
2783 | omit.delete(matched.output);
|
2784 | keep.add(matched.output);
|
2785 | }
|
2786 | }
|
2787 | }
|
2788 | let result = negatives === patterns.length ? [...items] : [...keep];
|
2789 | let matches = result.filter(item => !omit.has(item));
|
2790 | if (options && matches.length === 0) {
|
2791 | if (options.failglob === true) {
|
2792 | throw new Error(`No matches found for "${patterns.join(', ')}"`);
|
2793 | }
|
2794 | if (options.nonull === true || options.nullglob === true) {
|
2795 | return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
|
2796 | }
|
2797 | }
|
2798 | return matches;
|
2799 | };
|
2800 |
|
2801 |
|
2802 |
|
2803 | micromatch.match = micromatch;
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 | micromatch.matcher = (pattern, options) => picomatch$1(pattern, options);
|
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 |
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 |
|
2838 |
|
2839 | micromatch.isMatch = (str, patterns, options) => picomatch$1(patterns, options)(str);
|
2840 |
|
2841 |
|
2842 |
|
2843 | micromatch.any = micromatch.isMatch;
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 | micromatch.not = (list, patterns, options = {}) => {
|
2861 | patterns = [].concat(patterns).map(String);
|
2862 | let result = new Set();
|
2863 | let items = [];
|
2864 | let onResult = state => {
|
2865 | if (options.onResult)
|
2866 | options.onResult(state);
|
2867 | items.push(state.output);
|
2868 | };
|
2869 | let matches = micromatch(list, patterns, Object.assign({}, options, { onResult }));
|
2870 | for (let item of items) {
|
2871 | if (!matches.includes(item)) {
|
2872 | result.add(item);
|
2873 | }
|
2874 | }
|
2875 | return [...result];
|
2876 | };
|
2877 |
|
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 |
|
2891 |
|
2892 |
|
2893 |
|
2894 |
|
2895 |
|
2896 | micromatch.contains = (str, pattern, options) => {
|
2897 | if (typeof str !== 'string') {
|
2898 | throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
|
2899 | }
|
2900 | if (Array.isArray(pattern)) {
|
2901 | return pattern.some(p => micromatch.contains(str, p, options));
|
2902 | }
|
2903 | if (typeof pattern === 'string') {
|
2904 | if (isEmptyString(str) || isEmptyString(pattern)) {
|
2905 | return false;
|
2906 | }
|
2907 | if (str.includes(pattern) || (str.startsWith('./') && str.slice(2).includes(pattern))) {
|
2908 | return true;
|
2909 | }
|
2910 | }
|
2911 | return micromatch.isMatch(str, pattern, Object.assign({}, options, { contains: true }));
|
2912 | };
|
2913 |
|
2914 |
|
2915 |
|
2916 |
|
2917 |
|
2918 |
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 |
|
2932 | micromatch.matchKeys = (obj, patterns, options) => {
|
2933 | if (!utils$1.isObject(obj)) {
|
2934 | throw new TypeError('Expected the first argument to be an object');
|
2935 | }
|
2936 | let keys = micromatch(Object.keys(obj), patterns, options);
|
2937 | let res = {};
|
2938 | for (let key of keys)
|
2939 | res[key] = obj[key];
|
2940 | return res;
|
2941 | };
|
2942 |
|
2943 |
|
2944 |
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 |
|
2954 |
|
2955 |
|
2956 |
|
2957 |
|
2958 |
|
2959 |
|
2960 | micromatch.some = (list, patterns, options) => {
|
2961 | let items = [].concat(list);
|
2962 | for (let pattern of [].concat(patterns)) {
|
2963 | let isMatch = picomatch$1(String(pattern), options);
|
2964 | if (items.some(item => isMatch(item))) {
|
2965 | return true;
|
2966 | }
|
2967 | }
|
2968 | return false;
|
2969 | };
|
2970 |
|
2971 |
|
2972 |
|
2973 |
|
2974 |
|
2975 |
|
2976 |
|
2977 |
|
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 |
|
2984 |
|
2985 |
|
2986 |
|
2987 |
|
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 | micromatch.every = (list, patterns, options) => {
|
2994 | let items = [].concat(list);
|
2995 | for (let pattern of [].concat(patterns)) {
|
2996 | let isMatch = picomatch$1(String(pattern), options);
|
2997 | if (!items.every(item => isMatch(item))) {
|
2998 | return false;
|
2999 | }
|
3000 | }
|
3001 | return true;
|
3002 | };
|
3003 |
|
3004 |
|
3005 |
|
3006 |
|
3007 |
|
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 | micromatch.all = (str, patterns, options) => {
|
3030 | if (typeof str !== 'string') {
|
3031 | throw new TypeError(`Expected a string: "${util.inspect(str)}"`);
|
3032 | }
|
3033 | return [].concat(patterns).every(p => picomatch$1(p, options)(str));
|
3034 | };
|
3035 |
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 | micromatch.capture = (glob, input, options) => {
|
3054 | let posix = utils$1.isWindows(options);
|
3055 | let regex = picomatch$1.makeRe(String(glob), Object.assign({}, options, { capture: true }));
|
3056 | let match = regex.exec(posix ? utils$1.toPosixSlashes(input) : input);
|
3057 | if (match) {
|
3058 | return match.slice(1).map(v => v === void 0 ? '' : v);
|
3059 | }
|
3060 | };
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 | micromatch.makeRe = (...args) => picomatch$1.makeRe(...args);
|
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 | micromatch.scan = (...args) => picomatch$1.scan(...args);
|
3091 |
|
3092 |
|
3093 |
|
3094 |
|
3095 |
|
3096 |
|
3097 |
|
3098 |
|
3099 |
|
3100 |
|
3101 |
|
3102 |
|
3103 |
|
3104 | micromatch.parse = (patterns, options) => {
|
3105 | let res = [];
|
3106 | for (let pattern of [].concat(patterns || [])) {
|
3107 | for (let str of braces_1(String(pattern), options)) {
|
3108 | res.push(picomatch$1.parse(str, options));
|
3109 | }
|
3110 | }
|
3111 | return res;
|
3112 | };
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 |
|
3124 |
|
3125 |
|
3126 |
|
3127 |
|
3128 |
|
3129 | micromatch.braces = (pattern, options) => {
|
3130 | if (typeof pattern !== 'string')
|
3131 | throw new TypeError('Expected a string');
|
3132 | if ((options && options.nobrace === true) || !/\{.*\}/.test(pattern)) {
|
3133 | return [pattern];
|
3134 | }
|
3135 | return braces_1(pattern, options);
|
3136 | };
|
3137 |
|
3138 |
|
3139 |
|
3140 | micromatch.braceExpand = (pattern, options) => {
|
3141 | if (typeof pattern !== 'string')
|
3142 | throw new TypeError('Expected a string');
|
3143 | return micromatch.braces(pattern, Object.assign({}, options, { expand: true }));
|
3144 | };
|
3145 |
|
3146 |
|
3147 |
|
3148 | var micromatch_1 = micromatch;
|
3149 |
|
3150 | function ensureArray(thing) {
|
3151 | if (Array.isArray(thing))
|
3152 | return thing;
|
3153 | if (thing == undefined)
|
3154 | return [];
|
3155 | return [thing];
|
3156 | }
|
3157 |
|
3158 | function getMatcherString(id, resolutionBase) {
|
3159 | if (resolutionBase === false) {
|
3160 | return id;
|
3161 | }
|
3162 | return path.resolve(...(typeof resolutionBase === 'string' ? [resolutionBase, id] : [id]));
|
3163 | }
|
3164 | const createFilter = function createFilter(include, exclude, options) {
|
3165 | const resolutionBase = options && options.resolve;
|
3166 | const getMatcher = (id) => {
|
3167 | return id instanceof RegExp
|
3168 | ? id
|
3169 | : {
|
3170 | test: micromatch_1.matcher(getMatcherString(id, resolutionBase)
|
3171 | .split(path.sep)
|
3172 | .join('/'), { dot: true })
|
3173 | };
|
3174 | };
|
3175 | const includeMatchers = ensureArray(include).map(getMatcher);
|
3176 | const excludeMatchers = ensureArray(exclude).map(getMatcher);
|
3177 | return function (id) {
|
3178 | if (typeof id !== 'string')
|
3179 | return false;
|
3180 | if (/\0/.test(id))
|
3181 | return false;
|
3182 | id = id.split(path.sep).join('/');
|
3183 | for (let i = 0; i < excludeMatchers.length; ++i) {
|
3184 | const matcher = excludeMatchers[i];
|
3185 | if (matcher.test(id))
|
3186 | return false;
|
3187 | }
|
3188 | for (let i = 0; i < includeMatchers.length; ++i) {
|
3189 | const matcher = includeMatchers[i];
|
3190 | if (matcher.test(id))
|
3191 | return true;
|
3192 | }
|
3193 | return !includeMatchers.length;
|
3194 | };
|
3195 | };
|
3196 |
|
3197 | const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
|
3198 | const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
|
3199 | const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '));
|
3200 | forbiddenIdentifiers.add('');
|
3201 | const makeLegalIdentifier = function makeLegalIdentifier(str) {
|
3202 | str = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
3203 | if (/\d/.test(str[0]) || forbiddenIdentifiers.has(str)) {
|
3204 | str = `_${str}`;
|
3205 | }
|
3206 | return str || '_';
|
3207 | };
|
3208 |
|
3209 | function stringify$2(obj) {
|
3210 | return (JSON.stringify(obj) || 'undefined').replace(/[\u2028\u2029]/g, char => `\\u${('000' + char.charCodeAt(0).toString(16)).slice(-4)}`);
|
3211 | }
|
3212 | function serializeArray(arr, indent, baseIndent) {
|
3213 | let output = '[';
|
3214 | const separator = indent ? '\n' + baseIndent + indent : '';
|
3215 | for (let i = 0; i < arr.length; i++) {
|
3216 | const key = arr[i];
|
3217 | output += `${i > 0 ? ',' : ''}${separator}${serialize(key, indent, baseIndent + indent)}`;
|
3218 | }
|
3219 | return output + `${indent ? '\n' + baseIndent : ''}]`;
|
3220 | }
|
3221 | function serializeObject(obj, indent, baseIndent) {
|
3222 | let output = '{';
|
3223 | const separator = indent ? '\n' + baseIndent + indent : '';
|
3224 | const keys = Object.keys(obj);
|
3225 | for (let i = 0; i < keys.length; i++) {
|
3226 | const key = keys[i];
|
3227 | const stringKey = makeLegalIdentifier(key) === key ? key : stringify$2(key);
|
3228 | output += `${i > 0 ? ',' : ''}${separator}${stringKey}:${indent ? ' ' : ''}${serialize(obj[key], indent, baseIndent + indent)}`;
|
3229 | }
|
3230 | return output + `${indent ? '\n' + baseIndent : ''}}`;
|
3231 | }
|
3232 | function serialize(obj, indent, baseIndent) {
|
3233 | if (obj === Infinity)
|
3234 | return 'Infinity';
|
3235 | if (obj === -Infinity)
|
3236 | return '-Infinity';
|
3237 | if (obj === 0 && 1 / obj === -Infinity)
|
3238 | return '-0';
|
3239 | if (obj instanceof Date)
|
3240 | return 'new Date(' + obj.getTime() + ')';
|
3241 | if (obj instanceof RegExp)
|
3242 | return obj.toString();
|
3243 | if (obj !== obj)
|
3244 | return 'NaN';
|
3245 | if (Array.isArray(obj))
|
3246 | return serializeArray(obj, indent, baseIndent);
|
3247 | if (obj === null)
|
3248 | return 'null';
|
3249 | if (typeof obj === 'object')
|
3250 | return serializeObject(obj, indent, baseIndent);
|
3251 | return stringify$2(obj);
|
3252 | }
|
3253 | const dataToEsm = function dataToEsm(data, options = {}) {
|
3254 | const t = options.compact ? '' : 'indent' in options ? options.indent : '\t';
|
3255 | const _ = options.compact ? '' : ' ';
|
3256 | const n = options.compact ? '' : '\n';
|
3257 | const declarationType = options.preferConst ? 'const' : 'var';
|
3258 | if (options.namedExports === false ||
|
3259 | typeof data !== 'object' ||
|
3260 | Array.isArray(data) ||
|
3261 | data instanceof Date ||
|
3262 | data instanceof RegExp ||
|
3263 | data === null) {
|
3264 | const code = serialize(data, options.compact ? null : t, '');
|
3265 | const __ = _ || (/^[{[\-\/]/.test(code) ? '' : ' ');
|
3266 | return `export default${__}${code};`;
|
3267 | }
|
3268 | let namedExportCode = '';
|
3269 | const defaultExportRows = [];
|
3270 | const dataKeys = Object.keys(data);
|
3271 | for (let i = 0; i < dataKeys.length; i++) {
|
3272 | const key = dataKeys[i];
|
3273 | if (key === makeLegalIdentifier(key)) {
|
3274 | if (options.objectShorthand)
|
3275 | defaultExportRows.push(key);
|
3276 | else
|
3277 | defaultExportRows.push(`${key}:${_}${key}`);
|
3278 | namedExportCode += `export ${declarationType} ${key}${_}=${_}${serialize(data[key], options.compact ? null : t, '')};${n}`;
|
3279 | }
|
3280 | else {
|
3281 | defaultExportRows.push(`${stringify$2(key)}:${_}${serialize(data[key], options.compact ? null : t, '')}`);
|
3282 | }
|
3283 | }
|
3284 | return (namedExportCode + `export default${_}{${n}${t}${defaultExportRows.join(`,${n}${t}`)}${n}};${n}`);
|
3285 | };
|
3286 |
|
3287 | exports.addExtension = addExtension;
|
3288 | exports.attachScopes = attachScopes;
|
3289 | exports.createFilter = createFilter;
|
3290 | exports.dataToEsm = dataToEsm;
|
3291 | exports.extractAssignedNames = extractAssignedNames;
|
3292 | exports.makeLegalIdentifier = makeLegalIdentifier;
|