1 | #!/usr/bin/env node
|
2 | 'use strict';
|
3 |
|
4 | var path = require('path');
|
5 | var fs$2 = require('fs');
|
6 | var readline = require('readline');
|
7 | var os = require('os');
|
8 | var tty = require('tty');
|
9 | var util$2 = require('util');
|
10 | var stream_1 = require('stream');
|
11 | var events_1 = require('events');
|
12 |
|
13 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
14 |
|
15 | var path__default = _interopDefaultLegacy(path);
|
16 | var fs__default = _interopDefaultLegacy(fs$2);
|
17 | var readline__default = _interopDefaultLegacy(readline);
|
18 | var os__default = _interopDefaultLegacy(os);
|
19 | var tty__default = _interopDefaultLegacy(tty);
|
20 | var util__default = _interopDefaultLegacy(util$2);
|
21 | var stream_1__default = _interopDefaultLegacy(stream_1);
|
22 | var events_1__default = _interopDefaultLegacy(events_1);
|
23 |
|
24 | var semverCompare = function cmp(a, b) {
|
25 | var pa = a.split('.');
|
26 | var pb = b.split('.');
|
27 |
|
28 | for (var i = 0; i < 3; i++) {
|
29 | var na = Number(pa[i]);
|
30 | var nb = Number(pb[i]);
|
31 | if (na > nb) return 1;
|
32 | if (nb > na) return -1;
|
33 | if (!isNaN(na) && isNaN(nb)) return 1;
|
34 | if (isNaN(na) && !isNaN(nb)) return -1;
|
35 | }
|
36 |
|
37 | return 0;
|
38 | };
|
39 |
|
40 | var pleaseUpgradeNode = function pleaseUpgradeNode(pkg, opts) {
|
41 | var opts = opts || {};
|
42 | var requiredVersion = pkg.engines.node.replace('>=', '');
|
43 | var currentVersion = process.version.replace('v', '');
|
44 |
|
45 | if (semverCompare(currentVersion, requiredVersion) === -1) {
|
46 | if (opts.message) {
|
47 | console.error(opts.message(requiredVersion));
|
48 | } else {
|
49 | console.error(pkg.name + ' requires at least version ' + requiredVersion + ' of Node, please upgrade');
|
50 | }
|
51 |
|
52 | if (opts.hasOwnProperty('exitCode')) {
|
53 | process.exit(opts.exitCode);
|
54 | } else {
|
55 | process.exit(1);
|
56 | }
|
57 | }
|
58 | };
|
59 |
|
60 | var name = "prettier";
|
61 | var version = "2.2.1";
|
62 | var description = "Prettier is an opinionated code formatter";
|
63 | var bin = "./bin/prettier.js";
|
64 | var repository = "prettier/prettier";
|
65 | var homepage = "https://prettier.io";
|
66 | var author = "James Long";
|
67 | var license = "MIT";
|
68 | var main = "./index.js";
|
69 | var browser = "./standalone.js";
|
70 | var unpkg = "./standalone.js";
|
71 | var engines = {
|
72 | node: ">=10.13.0"
|
73 | };
|
74 | var files = [
|
75 | "index.js",
|
76 | "standalone.js",
|
77 | "src",
|
78 | "bin"
|
79 | ];
|
80 | var dependencies = {
|
81 | "@angular/compiler": "10.2.3",
|
82 | "@babel/code-frame": "7.10.4",
|
83 | "@babel/parser": "7.12.5",
|
84 | "@glimmer/syntax": "0.66.0",
|
85 | "@iarna/toml": "2.2.5",
|
86 | "@typescript-eslint/typescript-estree": "4.8.1",
|
87 | "angular-estree-parser": "2.2.1",
|
88 | "angular-html-parser": "1.7.1",
|
89 | camelcase: "6.2.0",
|
90 | chalk: "4.1.0",
|
91 | "ci-info": "watson/ci-info#f43f6a1cefff47fb361c88cf4b943fdbcaafe540",
|
92 | "cjk-regex": "2.0.0",
|
93 | cosmiconfig: "7.0.0",
|
94 | dashify: "2.0.0",
|
95 | diff: "5.0.0",
|
96 | editorconfig: "0.15.3",
|
97 | "editorconfig-to-prettier": "0.2.0",
|
98 | "escape-string-regexp": "4.0.0",
|
99 | espree: "7.3.0",
|
100 | esutils: "2.0.3",
|
101 | "fast-glob": "3.2.4",
|
102 | "fast-json-stable-stringify": "2.1.0",
|
103 | "find-parent-dir": "0.3.0",
|
104 | "flow-parser": "0.138.0",
|
105 | "get-stdin": "8.0.0",
|
106 | globby: "11.0.1",
|
107 | graphql: "15.4.0",
|
108 | "html-element-attributes": "2.3.0",
|
109 | "html-styles": "1.0.0",
|
110 | "html-tag-names": "1.1.5",
|
111 | "html-void-elements": "1.0.5",
|
112 | ignore: "4.0.6",
|
113 | "jest-docblock": "26.0.0",
|
114 | json5: "2.1.3",
|
115 | leven: "3.1.0",
|
116 | "lines-and-columns": "1.1.6",
|
117 | "linguist-languages": "7.12.1",
|
118 | lodash: "4.17.20",
|
119 | mem: "8.0.0",
|
120 | meriyah: "3.1.6",
|
121 | minimatch: "3.0.4",
|
122 | minimist: "1.2.5",
|
123 | "n-readlines": "1.0.1",
|
124 | outdent: "0.7.1",
|
125 | "parse-srcset": "ikatyang/parse-srcset#54eb9c1cb21db5c62b4d0e275d7249516df6f0ee",
|
126 | "please-upgrade-node": "3.2.0",
|
127 | "postcss-less": "3.1.4",
|
128 | "postcss-media-query-parser": "0.2.3",
|
129 | "postcss-scss": "2.1.1",
|
130 | "postcss-selector-parser": "2.2.3",
|
131 | "postcss-values-parser": "2.0.1",
|
132 | "regexp-util": "1.2.2",
|
133 | "remark-footnotes": "2.0.0",
|
134 | "remark-math": "3.0.1",
|
135 | "remark-parse": "8.0.3",
|
136 | resolve: "1.19.0",
|
137 | semver: "7.3.2",
|
138 | "string-width": "4.2.0",
|
139 | typescript: "4.1.2",
|
140 | "unicode-regex": "3.0.0",
|
141 | unified: "9.2.0",
|
142 | vnopts: "1.0.2",
|
143 | "yaml-unist-parser": "1.3.1"
|
144 | };
|
145 | var devDependencies = {
|
146 | "@babel/core": "7.12.3",
|
147 | "@babel/preset-env": "7.12.1",
|
148 | "@babel/types": "7.12.6",
|
149 | "@glimmer/reference": "0.66.0",
|
150 | "@rollup/plugin-alias": "3.1.1",
|
151 | "@rollup/plugin-babel": "5.2.1",
|
152 | "@rollup/plugin-commonjs": "16.0.0",
|
153 | "@rollup/plugin-json": "4.1.0",
|
154 | "@rollup/plugin-node-resolve": "10.0.0",
|
155 | "@rollup/plugin-replace": "2.3.4",
|
156 | "@types/estree": "0.0.45",
|
157 | "@types/node": "14.14.0",
|
158 | "@typescript-eslint/types": "4.8.1",
|
159 | "babel-jest": "26.6.3",
|
160 | "babel-loader": "8.2.1",
|
161 | benchmark: "2.1.4",
|
162 | "builtin-modules": "3.1.0",
|
163 | "cross-env": "7.0.2",
|
164 | cspell: "4.2.2",
|
165 | eslint: "7.13.0",
|
166 | "eslint-config-prettier": "6.15.0",
|
167 | "eslint-formatter-friendly": "7.0.0",
|
168 | "eslint-plugin-import": "2.22.1",
|
169 | "eslint-plugin-jest": "24.1.3",
|
170 | "eslint-plugin-prettier-internal-rules": "file:scripts/tools/eslint-plugin-prettier-internal-rules",
|
171 | "eslint-plugin-react": "7.21.5",
|
172 | "eslint-plugin-unicorn": "23.0.0",
|
173 | execa: "4.1.0",
|
174 | jest: "26.6.3",
|
175 | "jest-snapshot-serializer-ansi": "1.0.0",
|
176 | "jest-snapshot-serializer-raw": "1.1.0",
|
177 | "jest-watch-typeahead": "0.6.1",
|
178 | "npm-run-all": "4.1.5",
|
179 | "path-browserify": "1.0.1",
|
180 | prettier: "2.2.0",
|
181 | rimraf: "3.0.2",
|
182 | rollup: "2.33.3",
|
183 | "rollup-plugin-node-globals": "1.4.0",
|
184 | "rollup-plugin-terser": "7.0.2",
|
185 | shelljs: "0.8.4",
|
186 | "snapshot-diff": "0.8.1",
|
187 | "strip-ansi": "6.0.0",
|
188 | "synchronous-promise": "2.0.15",
|
189 | tempy: "1.0.0",
|
190 | "terser-webpack-plugin": "5.0.3",
|
191 | webpack: "5.5.1"
|
192 | };
|
193 | var scripts = {
|
194 | prepublishOnly: "echo \"Error: must publish from dist/\" && exit 1",
|
195 | "prepare-release": "yarn && yarn build && yarn test:dist",
|
196 | test: "jest",
|
197 | "test:dev-package": "cross-env INSTALL_PACKAGE=1 jest",
|
198 | "test:dist": "cross-env NODE_ENV=production jest",
|
199 | "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest",
|
200 | "test:integration": "jest tests_integration",
|
201 | "perf:repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
202 | "perf:repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
203 | "perf:benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
204 | lint: "run-p lint:*",
|
205 | "lint:typecheck": "tsc",
|
206 | "lint:eslint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
|
207 | "lint:changelog": "node ./scripts/lint-changelog.js",
|
208 | "lint:prettier": "prettier . \"!test*\" --check",
|
209 | "lint:dist": "eslint --no-eslintrc --no-ignore --env=es6,browser --parser-options=ecmaVersion:2018 \"dist/!(bin-prettier|index|third-party).js\"",
|
210 | "lint:spellcheck": "cspell \"**/*\" \".github/**/*\"",
|
211 | "lint:deps": "node ./scripts/check-deps.js",
|
212 | fix: "run-s fix:eslint fix:prettier",
|
213 | "fix:eslint": "yarn lint:eslint --fix",
|
214 | "fix:prettier": "yarn lint:prettier --write",
|
215 | build: "node --max-old-space-size=3072 ./scripts/build/build.js",
|
216 | "build-docs": "node ./scripts/build-docs.js"
|
217 | };
|
218 | var require$$1 = {
|
219 | name: name,
|
220 | version: version,
|
221 | description: description,
|
222 | bin: bin,
|
223 | repository: repository,
|
224 | homepage: homepage,
|
225 | author: author,
|
226 | license: license,
|
227 | main: main,
|
228 | browser: browser,
|
229 | unpkg: unpkg,
|
230 | engines: engines,
|
231 | files: files,
|
232 | dependencies: dependencies,
|
233 | devDependencies: devDependencies,
|
234 | scripts: scripts
|
235 | };
|
236 |
|
237 | var fastJsonStableStringify = function (data, opts) {
|
238 | if (!opts) opts = {};
|
239 | if (typeof opts === 'function') opts = {
|
240 | cmp: opts
|
241 | };
|
242 | var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
|
243 |
|
244 | var cmp = opts.cmp && function (f) {
|
245 | return function (node) {
|
246 | return function (a, b) {
|
247 | var aobj = {
|
248 | key: a,
|
249 | value: node[a]
|
250 | };
|
251 | var bobj = {
|
252 | key: b,
|
253 | value: node[b]
|
254 | };
|
255 | return f(aobj, bobj);
|
256 | };
|
257 | };
|
258 | }(opts.cmp);
|
259 |
|
260 | var seen = [];
|
261 | return function stringify(node) {
|
262 | if (node && node.toJSON && typeof node.toJSON === 'function') {
|
263 | node = node.toJSON();
|
264 | }
|
265 |
|
266 | if (node === undefined) return;
|
267 | if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';
|
268 | if (typeof node !== 'object') return JSON.stringify(node);
|
269 | var i, out;
|
270 |
|
271 | if (Array.isArray(node)) {
|
272 | out = '[';
|
273 |
|
274 | for (i = 0; i < node.length; i++) {
|
275 | if (i) out += ',';
|
276 | out += stringify(node[i]) || 'null';
|
277 | }
|
278 |
|
279 | return out + ']';
|
280 | }
|
281 |
|
282 | if (node === null) return 'null';
|
283 |
|
284 | if (seen.indexOf(node) !== -1) {
|
285 | if (cycles) return JSON.stringify('__cycle__');
|
286 | throw new TypeError('Converting circular structure to JSON');
|
287 | }
|
288 |
|
289 | var seenIndex = seen.push(node) - 1;
|
290 | var keys = Object.keys(node).sort(cmp && cmp(node));
|
291 | out = '';
|
292 |
|
293 | for (i = 0; i < keys.length; i++) {
|
294 | var key = keys[i];
|
295 | var value = stringify(node[key]);
|
296 | if (!value) continue;
|
297 | if (out) out += ',';
|
298 | out += JSON.stringify(key) + ':' + value;
|
299 | }
|
300 |
|
301 | seen.splice(seenIndex, 1);
|
302 | return '{' + out + '}';
|
303 | }(data);
|
304 | };
|
305 |
|
306 | var src = require("./index");
|
307 |
|
308 | const preserveCamelCase = (string, locale) => {
|
309 | let isLastCharLower = false;
|
310 | let isLastCharUpper = false;
|
311 | let isLastLastCharUpper = false;
|
312 |
|
313 | for (let i = 0; i < string.length; i++) {
|
314 | const character = string[i];
|
315 |
|
316 | if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
|
317 | string = string.slice(0, i) + '-' + string.slice(i);
|
318 | isLastCharLower = false;
|
319 | isLastLastCharUpper = isLastCharUpper;
|
320 | isLastCharUpper = true;
|
321 | i++;
|
322 | } else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
|
323 | string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
|
324 | isLastLastCharUpper = isLastCharUpper;
|
325 | isLastCharUpper = false;
|
326 | isLastCharLower = true;
|
327 | } else {
|
328 | isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character;
|
329 | isLastLastCharUpper = isLastCharUpper;
|
330 | isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character;
|
331 | }
|
332 | }
|
333 |
|
334 | return string;
|
335 | };
|
336 |
|
337 | const preserveConsecutiveUppercase = input => {
|
338 | return input.replace(/^[\p{Lu}](?![\p{Lu}])/gu, m1 => m1.toLowerCase());
|
339 | };
|
340 |
|
341 | const postProcess = (input, options) => {
|
342 | return input.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locale)).replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locale));
|
343 | };
|
344 |
|
345 | const camelCase = (input, options) => {
|
346 | if (!(typeof input === 'string' || Array.isArray(input))) {
|
347 | throw new TypeError('Expected the input to be `string | string[]`');
|
348 | }
|
349 |
|
350 | options = Object.assign({
|
351 | pascalCase: false,
|
352 | preserveConsecutiveUppercase: false
|
353 | }, options);
|
354 |
|
355 | if (Array.isArray(input)) {
|
356 | input = input.map(x => x.trim()).filter(x => x.length).join('-');
|
357 | } else {
|
358 | input = input.trim();
|
359 | }
|
360 |
|
361 | if (input.length === 0) {
|
362 | return '';
|
363 | }
|
364 |
|
365 | if (input.length === 1) {
|
366 | return options.pascalCase ? input.toLocaleUpperCase(options.locale) : input.toLocaleLowerCase(options.locale);
|
367 | }
|
368 |
|
369 | const hasUpperCase = input !== input.toLocaleLowerCase(options.locale);
|
370 |
|
371 | if (hasUpperCase) {
|
372 | input = preserveCamelCase(input, options.locale);
|
373 | }
|
374 |
|
375 | input = input.replace(/^[_.\- ]+/, '');
|
376 |
|
377 | if (options.preserveConsecutiveUppercase) {
|
378 | input = preserveConsecutiveUppercase(input);
|
379 | } else {
|
380 | input = input.toLocaleLowerCase();
|
381 | }
|
382 |
|
383 | if (options.pascalCase) {
|
384 | input = input.charAt(0).toLocaleUpperCase(options.locale) + input.slice(1);
|
385 | }
|
386 |
|
387 | return postProcess(input, options);
|
388 | };
|
389 |
|
390 | var camelcase = camelCase;
|
391 |
|
392 | var _default = camelCase;
|
393 | camelcase.default = _default;
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 | var dashify = (str, options) => {
|
403 | if (typeof str !== 'string') throw new TypeError('expected a string');
|
404 | return str.trim().replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\W/g, m => /[À-ž]/.test(m) ? m : '-').replace(/^-+|-+$/g, '').replace(/-{2,}/g, m => options && options.condense ? '-' : m).toLowerCase();
|
405 | };
|
406 |
|
407 | function createCommonjsModule(fn, basedir, module) {
|
408 | return module = {
|
409 | path: basedir,
|
410 | exports: {},
|
411 | require: function (path, base) {
|
412 | return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
413 | }
|
414 | }, fn(module, module.exports), module.exports;
|
415 | }
|
416 |
|
417 | function commonjsRequire () {
|
418 | throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
419 | }
|
420 |
|
421 | var colorName = {
|
422 | "aliceblue": [240, 248, 255],
|
423 | "antiquewhite": [250, 235, 215],
|
424 | "aqua": [0, 255, 255],
|
425 | "aquamarine": [127, 255, 212],
|
426 | "azure": [240, 255, 255],
|
427 | "beige": [245, 245, 220],
|
428 | "bisque": [255, 228, 196],
|
429 | "black": [0, 0, 0],
|
430 | "blanchedalmond": [255, 235, 205],
|
431 | "blue": [0, 0, 255],
|
432 | "blueviolet": [138, 43, 226],
|
433 | "brown": [165, 42, 42],
|
434 | "burlywood": [222, 184, 135],
|
435 | "cadetblue": [95, 158, 160],
|
436 | "chartreuse": [127, 255, 0],
|
437 | "chocolate": [210, 105, 30],
|
438 | "coral": [255, 127, 80],
|
439 | "cornflowerblue": [100, 149, 237],
|
440 | "cornsilk": [255, 248, 220],
|
441 | "crimson": [220, 20, 60],
|
442 | "cyan": [0, 255, 255],
|
443 | "darkblue": [0, 0, 139],
|
444 | "darkcyan": [0, 139, 139],
|
445 | "darkgoldenrod": [184, 134, 11],
|
446 | "darkgray": [169, 169, 169],
|
447 | "darkgreen": [0, 100, 0],
|
448 | "darkgrey": [169, 169, 169],
|
449 | "darkkhaki": [189, 183, 107],
|
450 | "darkmagenta": [139, 0, 139],
|
451 | "darkolivegreen": [85, 107, 47],
|
452 | "darkorange": [255, 140, 0],
|
453 | "darkorchid": [153, 50, 204],
|
454 | "darkred": [139, 0, 0],
|
455 | "darksalmon": [233, 150, 122],
|
456 | "darkseagreen": [143, 188, 143],
|
457 | "darkslateblue": [72, 61, 139],
|
458 | "darkslategray": [47, 79, 79],
|
459 | "darkslategrey": [47, 79, 79],
|
460 | "darkturquoise": [0, 206, 209],
|
461 | "darkviolet": [148, 0, 211],
|
462 | "deeppink": [255, 20, 147],
|
463 | "deepskyblue": [0, 191, 255],
|
464 | "dimgray": [105, 105, 105],
|
465 | "dimgrey": [105, 105, 105],
|
466 | "dodgerblue": [30, 144, 255],
|
467 | "firebrick": [178, 34, 34],
|
468 | "floralwhite": [255, 250, 240],
|
469 | "forestgreen": [34, 139, 34],
|
470 | "fuchsia": [255, 0, 255],
|
471 | "gainsboro": [220, 220, 220],
|
472 | "ghostwhite": [248, 248, 255],
|
473 | "gold": [255, 215, 0],
|
474 | "goldenrod": [218, 165, 32],
|
475 | "gray": [128, 128, 128],
|
476 | "green": [0, 128, 0],
|
477 | "greenyellow": [173, 255, 47],
|
478 | "grey": [128, 128, 128],
|
479 | "honeydew": [240, 255, 240],
|
480 | "hotpink": [255, 105, 180],
|
481 | "indianred": [205, 92, 92],
|
482 | "indigo": [75, 0, 130],
|
483 | "ivory": [255, 255, 240],
|
484 | "khaki": [240, 230, 140],
|
485 | "lavender": [230, 230, 250],
|
486 | "lavenderblush": [255, 240, 245],
|
487 | "lawngreen": [124, 252, 0],
|
488 | "lemonchiffon": [255, 250, 205],
|
489 | "lightblue": [173, 216, 230],
|
490 | "lightcoral": [240, 128, 128],
|
491 | "lightcyan": [224, 255, 255],
|
492 | "lightgoldenrodyellow": [250, 250, 210],
|
493 | "lightgray": [211, 211, 211],
|
494 | "lightgreen": [144, 238, 144],
|
495 | "lightgrey": [211, 211, 211],
|
496 | "lightpink": [255, 182, 193],
|
497 | "lightsalmon": [255, 160, 122],
|
498 | "lightseagreen": [32, 178, 170],
|
499 | "lightskyblue": [135, 206, 250],
|
500 | "lightslategray": [119, 136, 153],
|
501 | "lightslategrey": [119, 136, 153],
|
502 | "lightsteelblue": [176, 196, 222],
|
503 | "lightyellow": [255, 255, 224],
|
504 | "lime": [0, 255, 0],
|
505 | "limegreen": [50, 205, 50],
|
506 | "linen": [250, 240, 230],
|
507 | "magenta": [255, 0, 255],
|
508 | "maroon": [128, 0, 0],
|
509 | "mediumaquamarine": [102, 205, 170],
|
510 | "mediumblue": [0, 0, 205],
|
511 | "mediumorchid": [186, 85, 211],
|
512 | "mediumpurple": [147, 112, 219],
|
513 | "mediumseagreen": [60, 179, 113],
|
514 | "mediumslateblue": [123, 104, 238],
|
515 | "mediumspringgreen": [0, 250, 154],
|
516 | "mediumturquoise": [72, 209, 204],
|
517 | "mediumvioletred": [199, 21, 133],
|
518 | "midnightblue": [25, 25, 112],
|
519 | "mintcream": [245, 255, 250],
|
520 | "mistyrose": [255, 228, 225],
|
521 | "moccasin": [255, 228, 181],
|
522 | "navajowhite": [255, 222, 173],
|
523 | "navy": [0, 0, 128],
|
524 | "oldlace": [253, 245, 230],
|
525 | "olive": [128, 128, 0],
|
526 | "olivedrab": [107, 142, 35],
|
527 | "orange": [255, 165, 0],
|
528 | "orangered": [255, 69, 0],
|
529 | "orchid": [218, 112, 214],
|
530 | "palegoldenrod": [238, 232, 170],
|
531 | "palegreen": [152, 251, 152],
|
532 | "paleturquoise": [175, 238, 238],
|
533 | "palevioletred": [219, 112, 147],
|
534 | "papayawhip": [255, 239, 213],
|
535 | "peachpuff": [255, 218, 185],
|
536 | "peru": [205, 133, 63],
|
537 | "pink": [255, 192, 203],
|
538 | "plum": [221, 160, 221],
|
539 | "powderblue": [176, 224, 230],
|
540 | "purple": [128, 0, 128],
|
541 | "rebeccapurple": [102, 51, 153],
|
542 | "red": [255, 0, 0],
|
543 | "rosybrown": [188, 143, 143],
|
544 | "royalblue": [65, 105, 225],
|
545 | "saddlebrown": [139, 69, 19],
|
546 | "salmon": [250, 128, 114],
|
547 | "sandybrown": [244, 164, 96],
|
548 | "seagreen": [46, 139, 87],
|
549 | "seashell": [255, 245, 238],
|
550 | "sienna": [160, 82, 45],
|
551 | "silver": [192, 192, 192],
|
552 | "skyblue": [135, 206, 235],
|
553 | "slateblue": [106, 90, 205],
|
554 | "slategray": [112, 128, 144],
|
555 | "slategrey": [112, 128, 144],
|
556 | "snow": [255, 250, 250],
|
557 | "springgreen": [0, 255, 127],
|
558 | "steelblue": [70, 130, 180],
|
559 | "tan": [210, 180, 140],
|
560 | "teal": [0, 128, 128],
|
561 | "thistle": [216, 191, 216],
|
562 | "tomato": [255, 99, 71],
|
563 | "turquoise": [64, 224, 208],
|
564 | "violet": [238, 130, 238],
|
565 | "wheat": [245, 222, 179],
|
566 | "white": [255, 255, 255],
|
567 | "whitesmoke": [245, 245, 245],
|
568 | "yellow": [255, 255, 0],
|
569 | "yellowgreen": [154, 205, 50]
|
570 | };
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 | const reverseKeywords = {};
|
580 |
|
581 | for (const key of Object.keys(colorName)) {
|
582 | reverseKeywords[colorName[key]] = key;
|
583 | }
|
584 |
|
585 | const convert = {
|
586 | rgb: {
|
587 | channels: 3,
|
588 | labels: 'rgb'
|
589 | },
|
590 | hsl: {
|
591 | channels: 3,
|
592 | labels: 'hsl'
|
593 | },
|
594 | hsv: {
|
595 | channels: 3,
|
596 | labels: 'hsv'
|
597 | },
|
598 | hwb: {
|
599 | channels: 3,
|
600 | labels: 'hwb'
|
601 | },
|
602 | cmyk: {
|
603 | channels: 4,
|
604 | labels: 'cmyk'
|
605 | },
|
606 | xyz: {
|
607 | channels: 3,
|
608 | labels: 'xyz'
|
609 | },
|
610 | lab: {
|
611 | channels: 3,
|
612 | labels: 'lab'
|
613 | },
|
614 | lch: {
|
615 | channels: 3,
|
616 | labels: 'lch'
|
617 | },
|
618 | hex: {
|
619 | channels: 1,
|
620 | labels: ['hex']
|
621 | },
|
622 | keyword: {
|
623 | channels: 1,
|
624 | labels: ['keyword']
|
625 | },
|
626 | ansi16: {
|
627 | channels: 1,
|
628 | labels: ['ansi16']
|
629 | },
|
630 | ansi256: {
|
631 | channels: 1,
|
632 | labels: ['ansi256']
|
633 | },
|
634 | hcg: {
|
635 | channels: 3,
|
636 | labels: ['h', 'c', 'g']
|
637 | },
|
638 | apple: {
|
639 | channels: 3,
|
640 | labels: ['r16', 'g16', 'b16']
|
641 | },
|
642 | gray: {
|
643 | channels: 1,
|
644 | labels: ['gray']
|
645 | }
|
646 | };
|
647 | var conversions = convert;
|
648 |
|
649 | for (const model of Object.keys(convert)) {
|
650 | if (!('channels' in convert[model])) {
|
651 | throw new Error('missing channels property: ' + model);
|
652 | }
|
653 |
|
654 | if (!('labels' in convert[model])) {
|
655 | throw new Error('missing channel labels property: ' + model);
|
656 | }
|
657 |
|
658 | if (convert[model].labels.length !== convert[model].channels) {
|
659 | throw new Error('channel and label counts mismatch: ' + model);
|
660 | }
|
661 |
|
662 | const {
|
663 | channels,
|
664 | labels
|
665 | } = convert[model];
|
666 | delete convert[model].channels;
|
667 | delete convert[model].labels;
|
668 | Object.defineProperty(convert[model], 'channels', {
|
669 | value: channels
|
670 | });
|
671 | Object.defineProperty(convert[model], 'labels', {
|
672 | value: labels
|
673 | });
|
674 | }
|
675 |
|
676 | convert.rgb.hsl = function (rgb) {
|
677 | const r = rgb[0] / 255;
|
678 | const g = rgb[1] / 255;
|
679 | const b = rgb[2] / 255;
|
680 | const min = Math.min(r, g, b);
|
681 | const max = Math.max(r, g, b);
|
682 | const delta = max - min;
|
683 | let h;
|
684 | let s;
|
685 |
|
686 | if (max === min) {
|
687 | h = 0;
|
688 | } else if (r === max) {
|
689 | h = (g - b) / delta;
|
690 | } else if (g === max) {
|
691 | h = 2 + (b - r) / delta;
|
692 | } else if (b === max) {
|
693 | h = 4 + (r - g) / delta;
|
694 | }
|
695 |
|
696 | h = Math.min(h * 60, 360);
|
697 |
|
698 | if (h < 0) {
|
699 | h += 360;
|
700 | }
|
701 |
|
702 | const l = (min + max) / 2;
|
703 |
|
704 | if (max === min) {
|
705 | s = 0;
|
706 | } else if (l <= 0.5) {
|
707 | s = delta / (max + min);
|
708 | } else {
|
709 | s = delta / (2 - max - min);
|
710 | }
|
711 |
|
712 | return [h, s * 100, l * 100];
|
713 | };
|
714 |
|
715 | convert.rgb.hsv = function (rgb) {
|
716 | let rdif;
|
717 | let gdif;
|
718 | let bdif;
|
719 | let h;
|
720 | let s;
|
721 | const r = rgb[0] / 255;
|
722 | const g = rgb[1] / 255;
|
723 | const b = rgb[2] / 255;
|
724 | const v = Math.max(r, g, b);
|
725 | const diff = v - Math.min(r, g, b);
|
726 |
|
727 | const diffc = function (c) {
|
728 | return (v - c) / 6 / diff + 1 / 2;
|
729 | };
|
730 |
|
731 | if (diff === 0) {
|
732 | h = 0;
|
733 | s = 0;
|
734 | } else {
|
735 | s = diff / v;
|
736 | rdif = diffc(r);
|
737 | gdif = diffc(g);
|
738 | bdif = diffc(b);
|
739 |
|
740 | if (r === v) {
|
741 | h = bdif - gdif;
|
742 | } else if (g === v) {
|
743 | h = 1 / 3 + rdif - bdif;
|
744 | } else if (b === v) {
|
745 | h = 2 / 3 + gdif - rdif;
|
746 | }
|
747 |
|
748 | if (h < 0) {
|
749 | h += 1;
|
750 | } else if (h > 1) {
|
751 | h -= 1;
|
752 | }
|
753 | }
|
754 |
|
755 | return [h * 360, s * 100, v * 100];
|
756 | };
|
757 |
|
758 | convert.rgb.hwb = function (rgb) {
|
759 | const r = rgb[0];
|
760 | const g = rgb[1];
|
761 | let b = rgb[2];
|
762 | const h = convert.rgb.hsl(rgb)[0];
|
763 | const w = 1 / 255 * Math.min(r, Math.min(g, b));
|
764 | b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
|
765 | return [h, w * 100, b * 100];
|
766 | };
|
767 |
|
768 | convert.rgb.cmyk = function (rgb) {
|
769 | const r = rgb[0] / 255;
|
770 | const g = rgb[1] / 255;
|
771 | const b = rgb[2] / 255;
|
772 | const k = Math.min(1 - r, 1 - g, 1 - b);
|
773 | const c = (1 - r - k) / (1 - k) || 0;
|
774 | const m = (1 - g - k) / (1 - k) || 0;
|
775 | const y = (1 - b - k) / (1 - k) || 0;
|
776 | return [c * 100, m * 100, y * 100, k * 100];
|
777 | };
|
778 |
|
779 | function comparativeDistance(x, y) {
|
780 | |
781 |
|
782 |
|
783 | return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
|
784 | }
|
785 |
|
786 | convert.rgb.keyword = function (rgb) {
|
787 | const reversed = reverseKeywords[rgb];
|
788 |
|
789 | if (reversed) {
|
790 | return reversed;
|
791 | }
|
792 |
|
793 | let currentClosestDistance = Infinity;
|
794 | let currentClosestKeyword;
|
795 |
|
796 | for (const keyword of Object.keys(colorName)) {
|
797 | const value = colorName[keyword];
|
798 |
|
799 | const distance = comparativeDistance(rgb, value);
|
800 |
|
801 | if (distance < currentClosestDistance) {
|
802 | currentClosestDistance = distance;
|
803 | currentClosestKeyword = keyword;
|
804 | }
|
805 | }
|
806 |
|
807 | return currentClosestKeyword;
|
808 | };
|
809 |
|
810 | convert.keyword.rgb = function (keyword) {
|
811 | return colorName[keyword];
|
812 | };
|
813 |
|
814 | convert.rgb.xyz = function (rgb) {
|
815 | let r = rgb[0] / 255;
|
816 | let g = rgb[1] / 255;
|
817 | let b = rgb[2] / 255;
|
818 |
|
819 | r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
|
820 | g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
|
821 | b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
|
822 | const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
823 | const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
824 | const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
825 | return [x * 100, y * 100, z * 100];
|
826 | };
|
827 |
|
828 | convert.rgb.lab = function (rgb) {
|
829 | const xyz = convert.rgb.xyz(rgb);
|
830 | let x = xyz[0];
|
831 | let y = xyz[1];
|
832 | let z = xyz[2];
|
833 | x /= 95.047;
|
834 | y /= 100;
|
835 | z /= 108.883;
|
836 | x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
837 | y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
838 | z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
839 | const l = 116 * y - 16;
|
840 | const a = 500 * (x - y);
|
841 | const b = 200 * (y - z);
|
842 | return [l, a, b];
|
843 | };
|
844 |
|
845 | convert.hsl.rgb = function (hsl) {
|
846 | const h = hsl[0] / 360;
|
847 | const s = hsl[1] / 100;
|
848 | const l = hsl[2] / 100;
|
849 | let t2;
|
850 | let t3;
|
851 | let val;
|
852 |
|
853 | if (s === 0) {
|
854 | val = l * 255;
|
855 | return [val, val, val];
|
856 | }
|
857 |
|
858 | if (l < 0.5) {
|
859 | t2 = l * (1 + s);
|
860 | } else {
|
861 | t2 = l + s - l * s;
|
862 | }
|
863 |
|
864 | const t1 = 2 * l - t2;
|
865 | const rgb = [0, 0, 0];
|
866 |
|
867 | for (let i = 0; i < 3; i++) {
|
868 | t3 = h + 1 / 3 * -(i - 1);
|
869 |
|
870 | if (t3 < 0) {
|
871 | t3++;
|
872 | }
|
873 |
|
874 | if (t3 > 1) {
|
875 | t3--;
|
876 | }
|
877 |
|
878 | if (6 * t3 < 1) {
|
879 | val = t1 + (t2 - t1) * 6 * t3;
|
880 | } else if (2 * t3 < 1) {
|
881 | val = t2;
|
882 | } else if (3 * t3 < 2) {
|
883 | val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
|
884 | } else {
|
885 | val = t1;
|
886 | }
|
887 |
|
888 | rgb[i] = val * 255;
|
889 | }
|
890 |
|
891 | return rgb;
|
892 | };
|
893 |
|
894 | convert.hsl.hsv = function (hsl) {
|
895 | const h = hsl[0];
|
896 | let s = hsl[1] / 100;
|
897 | let l = hsl[2] / 100;
|
898 | let smin = s;
|
899 | const lmin = Math.max(l, 0.01);
|
900 | l *= 2;
|
901 | s *= l <= 1 ? l : 2 - l;
|
902 | smin *= lmin <= 1 ? lmin : 2 - lmin;
|
903 | const v = (l + s) / 2;
|
904 | const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
|
905 | return [h, sv * 100, v * 100];
|
906 | };
|
907 |
|
908 | convert.hsv.rgb = function (hsv) {
|
909 | const h = hsv[0] / 60;
|
910 | const s = hsv[1] / 100;
|
911 | let v = hsv[2] / 100;
|
912 | const hi = Math.floor(h) % 6;
|
913 | const f = h - Math.floor(h);
|
914 | const p = 255 * v * (1 - s);
|
915 | const q = 255 * v * (1 - s * f);
|
916 | const t = 255 * v * (1 - s * (1 - f));
|
917 | v *= 255;
|
918 |
|
919 | switch (hi) {
|
920 | case 0:
|
921 | return [v, t, p];
|
922 |
|
923 | case 1:
|
924 | return [q, v, p];
|
925 |
|
926 | case 2:
|
927 | return [p, v, t];
|
928 |
|
929 | case 3:
|
930 | return [p, q, v];
|
931 |
|
932 | case 4:
|
933 | return [t, p, v];
|
934 |
|
935 | case 5:
|
936 | return [v, p, q];
|
937 | }
|
938 | };
|
939 |
|
940 | convert.hsv.hsl = function (hsv) {
|
941 | const h = hsv[0];
|
942 | const s = hsv[1] / 100;
|
943 | const v = hsv[2] / 100;
|
944 | const vmin = Math.max(v, 0.01);
|
945 | let sl;
|
946 | let l;
|
947 | l = (2 - s) * v;
|
948 | const lmin = (2 - s) * vmin;
|
949 | sl = s * vmin;
|
950 | sl /= lmin <= 1 ? lmin : 2 - lmin;
|
951 | sl = sl || 0;
|
952 | l /= 2;
|
953 | return [h, sl * 100, l * 100];
|
954 | };
|
955 |
|
956 |
|
957 | convert.hwb.rgb = function (hwb) {
|
958 | const h = hwb[0] / 360;
|
959 | let wh = hwb[1] / 100;
|
960 | let bl = hwb[2] / 100;
|
961 | const ratio = wh + bl;
|
962 | let f;
|
963 |
|
964 | if (ratio > 1) {
|
965 | wh /= ratio;
|
966 | bl /= ratio;
|
967 | }
|
968 |
|
969 | const i = Math.floor(6 * h);
|
970 | const v = 1 - bl;
|
971 | f = 6 * h - i;
|
972 |
|
973 | if ((i & 0x01) !== 0) {
|
974 | f = 1 - f;
|
975 | }
|
976 |
|
977 | const n = wh + f * (v - wh);
|
978 |
|
979 | let r;
|
980 | let g;
|
981 | let b;
|
982 |
|
983 |
|
984 | switch (i) {
|
985 | default:
|
986 | case 6:
|
987 | case 0:
|
988 | r = v;
|
989 | g = n;
|
990 | b = wh;
|
991 | break;
|
992 |
|
993 | case 1:
|
994 | r = n;
|
995 | g = v;
|
996 | b = wh;
|
997 | break;
|
998 |
|
999 | case 2:
|
1000 | r = wh;
|
1001 | g = v;
|
1002 | b = n;
|
1003 | break;
|
1004 |
|
1005 | case 3:
|
1006 | r = wh;
|
1007 | g = n;
|
1008 | b = v;
|
1009 | break;
|
1010 |
|
1011 | case 4:
|
1012 | r = n;
|
1013 | g = wh;
|
1014 | b = v;
|
1015 | break;
|
1016 |
|
1017 | case 5:
|
1018 | r = v;
|
1019 | g = wh;
|
1020 | b = n;
|
1021 | break;
|
1022 | }
|
1023 |
|
1024 |
|
1025 |
|
1026 | return [r * 255, g * 255, b * 255];
|
1027 | };
|
1028 |
|
1029 | convert.cmyk.rgb = function (cmyk) {
|
1030 | const c = cmyk[0] / 100;
|
1031 | const m = cmyk[1] / 100;
|
1032 | const y = cmyk[2] / 100;
|
1033 | const k = cmyk[3] / 100;
|
1034 | const r = 1 - Math.min(1, c * (1 - k) + k);
|
1035 | const g = 1 - Math.min(1, m * (1 - k) + k);
|
1036 | const b = 1 - Math.min(1, y * (1 - k) + k);
|
1037 | return [r * 255, g * 255, b * 255];
|
1038 | };
|
1039 |
|
1040 | convert.xyz.rgb = function (xyz) {
|
1041 | const x = xyz[0] / 100;
|
1042 | const y = xyz[1] / 100;
|
1043 | const z = xyz[2] / 100;
|
1044 | let r;
|
1045 | let g;
|
1046 | let b;
|
1047 | r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
1048 | g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
1049 | b = x * 0.0557 + y * -0.2040 + z * 1.0570;
|
1050 |
|
1051 | r = r > 0.0031308 ? 1.055 * r ** (1.0 / 2.4) - 0.055 : r * 12.92;
|
1052 | g = g > 0.0031308 ? 1.055 * g ** (1.0 / 2.4) - 0.055 : g * 12.92;
|
1053 | b = b > 0.0031308 ? 1.055 * b ** (1.0 / 2.4) - 0.055 : b * 12.92;
|
1054 | r = Math.min(Math.max(0, r), 1);
|
1055 | g = Math.min(Math.max(0, g), 1);
|
1056 | b = Math.min(Math.max(0, b), 1);
|
1057 | return [r * 255, g * 255, b * 255];
|
1058 | };
|
1059 |
|
1060 | convert.xyz.lab = function (xyz) {
|
1061 | let x = xyz[0];
|
1062 | let y = xyz[1];
|
1063 | let z = xyz[2];
|
1064 | x /= 95.047;
|
1065 | y /= 100;
|
1066 | z /= 108.883;
|
1067 | x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
|
1068 | y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
|
1069 | z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
|
1070 | const l = 116 * y - 16;
|
1071 | const a = 500 * (x - y);
|
1072 | const b = 200 * (y - z);
|
1073 | return [l, a, b];
|
1074 | };
|
1075 |
|
1076 | convert.lab.xyz = function (lab) {
|
1077 | const l = lab[0];
|
1078 | const a = lab[1];
|
1079 | const b = lab[2];
|
1080 | let x;
|
1081 | let y;
|
1082 | let z;
|
1083 | y = (l + 16) / 116;
|
1084 | x = a / 500 + y;
|
1085 | z = y - b / 200;
|
1086 | const y2 = y ** 3;
|
1087 | const x2 = x ** 3;
|
1088 | const z2 = z ** 3;
|
1089 | y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
|
1090 | x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
|
1091 | z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
|
1092 | x *= 95.047;
|
1093 | y *= 100;
|
1094 | z *= 108.883;
|
1095 | return [x, y, z];
|
1096 | };
|
1097 |
|
1098 | convert.lab.lch = function (lab) {
|
1099 | const l = lab[0];
|
1100 | const a = lab[1];
|
1101 | const b = lab[2];
|
1102 | let h;
|
1103 | const hr = Math.atan2(b, a);
|
1104 | h = hr * 360 / 2 / Math.PI;
|
1105 |
|
1106 | if (h < 0) {
|
1107 | h += 360;
|
1108 | }
|
1109 |
|
1110 | const c = Math.sqrt(a * a + b * b);
|
1111 | return [l, c, h];
|
1112 | };
|
1113 |
|
1114 | convert.lch.lab = function (lch) {
|
1115 | const l = lch[0];
|
1116 | const c = lch[1];
|
1117 | const h = lch[2];
|
1118 | const hr = h / 360 * 2 * Math.PI;
|
1119 | const a = c * Math.cos(hr);
|
1120 | const b = c * Math.sin(hr);
|
1121 | return [l, a, b];
|
1122 | };
|
1123 |
|
1124 | convert.rgb.ansi16 = function (args, saturation = null) {
|
1125 | const [r, g, b] = args;
|
1126 | let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
|
1127 |
|
1128 | value = Math.round(value / 50);
|
1129 |
|
1130 | if (value === 0) {
|
1131 | return 30;
|
1132 | }
|
1133 |
|
1134 | let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
|
1135 |
|
1136 | if (value === 2) {
|
1137 | ansi += 60;
|
1138 | }
|
1139 |
|
1140 | return ansi;
|
1141 | };
|
1142 |
|
1143 | convert.hsv.ansi16 = function (args) {
|
1144 |
|
1145 |
|
1146 | return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
|
1147 | };
|
1148 |
|
1149 | convert.rgb.ansi256 = function (args) {
|
1150 | const r = args[0];
|
1151 | const g = args[1];
|
1152 | const b = args[2];
|
1153 |
|
1154 |
|
1155 | if (r === g && g === b) {
|
1156 | if (r < 8) {
|
1157 | return 16;
|
1158 | }
|
1159 |
|
1160 | if (r > 248) {
|
1161 | return 231;
|
1162 | }
|
1163 |
|
1164 | return Math.round((r - 8) / 247 * 24) + 232;
|
1165 | }
|
1166 |
|
1167 | const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
|
1168 | return ansi;
|
1169 | };
|
1170 |
|
1171 | convert.ansi16.rgb = function (args) {
|
1172 | let color = args % 10;
|
1173 |
|
1174 | if (color === 0 || color === 7) {
|
1175 | if (args > 50) {
|
1176 | color += 3.5;
|
1177 | }
|
1178 |
|
1179 | color = color / 10.5 * 255;
|
1180 | return [color, color, color];
|
1181 | }
|
1182 |
|
1183 | const mult = (~~(args > 50) + 1) * 0.5;
|
1184 | const r = (color & 1) * mult * 255;
|
1185 | const g = (color >> 1 & 1) * mult * 255;
|
1186 | const b = (color >> 2 & 1) * mult * 255;
|
1187 | return [r, g, b];
|
1188 | };
|
1189 |
|
1190 | convert.ansi256.rgb = function (args) {
|
1191 |
|
1192 | if (args >= 232) {
|
1193 | const c = (args - 232) * 10 + 8;
|
1194 | return [c, c, c];
|
1195 | }
|
1196 |
|
1197 | args -= 16;
|
1198 | let rem;
|
1199 | const r = Math.floor(args / 36) / 5 * 255;
|
1200 | const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
|
1201 | const b = rem % 6 / 5 * 255;
|
1202 | return [r, g, b];
|
1203 | };
|
1204 |
|
1205 | convert.rgb.hex = function (args) {
|
1206 | const integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
|
1207 | const string = integer.toString(16).toUpperCase();
|
1208 | return '000000'.substring(string.length) + string;
|
1209 | };
|
1210 |
|
1211 | convert.hex.rgb = function (args) {
|
1212 | const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
1213 |
|
1214 | if (!match) {
|
1215 | return [0, 0, 0];
|
1216 | }
|
1217 |
|
1218 | let colorString = match[0];
|
1219 |
|
1220 | if (match[0].length === 3) {
|
1221 | colorString = colorString.split('').map(char => {
|
1222 | return char + char;
|
1223 | }).join('');
|
1224 | }
|
1225 |
|
1226 | const integer = parseInt(colorString, 16);
|
1227 | const r = integer >> 16 & 0xFF;
|
1228 | const g = integer >> 8 & 0xFF;
|
1229 | const b = integer & 0xFF;
|
1230 | return [r, g, b];
|
1231 | };
|
1232 |
|
1233 | convert.rgb.hcg = function (rgb) {
|
1234 | const r = rgb[0] / 255;
|
1235 | const g = rgb[1] / 255;
|
1236 | const b = rgb[2] / 255;
|
1237 | const max = Math.max(Math.max(r, g), b);
|
1238 | const min = Math.min(Math.min(r, g), b);
|
1239 | const chroma = max - min;
|
1240 | let grayscale;
|
1241 | let hue;
|
1242 |
|
1243 | if (chroma < 1) {
|
1244 | grayscale = min / (1 - chroma);
|
1245 | } else {
|
1246 | grayscale = 0;
|
1247 | }
|
1248 |
|
1249 | if (chroma <= 0) {
|
1250 | hue = 0;
|
1251 | } else if (max === r) {
|
1252 | hue = (g - b) / chroma % 6;
|
1253 | } else if (max === g) {
|
1254 | hue = 2 + (b - r) / chroma;
|
1255 | } else {
|
1256 | hue = 4 + (r - g) / chroma;
|
1257 | }
|
1258 |
|
1259 | hue /= 6;
|
1260 | hue %= 1;
|
1261 | return [hue * 360, chroma * 100, grayscale * 100];
|
1262 | };
|
1263 |
|
1264 | convert.hsl.hcg = function (hsl) {
|
1265 | const s = hsl[1] / 100;
|
1266 | const l = hsl[2] / 100;
|
1267 | const c = l < 0.5 ? 2.0 * s * l : 2.0 * s * (1.0 - l);
|
1268 | let f = 0;
|
1269 |
|
1270 | if (c < 1.0) {
|
1271 | f = (l - 0.5 * c) / (1.0 - c);
|
1272 | }
|
1273 |
|
1274 | return [hsl[0], c * 100, f * 100];
|
1275 | };
|
1276 |
|
1277 | convert.hsv.hcg = function (hsv) {
|
1278 | const s = hsv[1] / 100;
|
1279 | const v = hsv[2] / 100;
|
1280 | const c = s * v;
|
1281 | let f = 0;
|
1282 |
|
1283 | if (c < 1.0) {
|
1284 | f = (v - c) / (1 - c);
|
1285 | }
|
1286 |
|
1287 | return [hsv[0], c * 100, f * 100];
|
1288 | };
|
1289 |
|
1290 | convert.hcg.rgb = function (hcg) {
|
1291 | const h = hcg[0] / 360;
|
1292 | const c = hcg[1] / 100;
|
1293 | const g = hcg[2] / 100;
|
1294 |
|
1295 | if (c === 0.0) {
|
1296 | return [g * 255, g * 255, g * 255];
|
1297 | }
|
1298 |
|
1299 | const pure = [0, 0, 0];
|
1300 | const hi = h % 1 * 6;
|
1301 | const v = hi % 1;
|
1302 | const w = 1 - v;
|
1303 | let mg = 0;
|
1304 |
|
1305 |
|
1306 | switch (Math.floor(hi)) {
|
1307 | case 0:
|
1308 | pure[0] = 1;
|
1309 | pure[1] = v;
|
1310 | pure[2] = 0;
|
1311 | break;
|
1312 |
|
1313 | case 1:
|
1314 | pure[0] = w;
|
1315 | pure[1] = 1;
|
1316 | pure[2] = 0;
|
1317 | break;
|
1318 |
|
1319 | case 2:
|
1320 | pure[0] = 0;
|
1321 | pure[1] = 1;
|
1322 | pure[2] = v;
|
1323 | break;
|
1324 |
|
1325 | case 3:
|
1326 | pure[0] = 0;
|
1327 | pure[1] = w;
|
1328 | pure[2] = 1;
|
1329 | break;
|
1330 |
|
1331 | case 4:
|
1332 | pure[0] = v;
|
1333 | pure[1] = 0;
|
1334 | pure[2] = 1;
|
1335 | break;
|
1336 |
|
1337 | default:
|
1338 | pure[0] = 1;
|
1339 | pure[1] = 0;
|
1340 | pure[2] = w;
|
1341 | }
|
1342 |
|
1343 |
|
1344 |
|
1345 | mg = (1.0 - c) * g;
|
1346 | return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
|
1347 | };
|
1348 |
|
1349 | convert.hcg.hsv = function (hcg) {
|
1350 | const c = hcg[1] / 100;
|
1351 | const g = hcg[2] / 100;
|
1352 | const v = c + g * (1.0 - c);
|
1353 | let f = 0;
|
1354 |
|
1355 | if (v > 0.0) {
|
1356 | f = c / v;
|
1357 | }
|
1358 |
|
1359 | return [hcg[0], f * 100, v * 100];
|
1360 | };
|
1361 |
|
1362 | convert.hcg.hsl = function (hcg) {
|
1363 | const c = hcg[1] / 100;
|
1364 | const g = hcg[2] / 100;
|
1365 | const l = g * (1.0 - c) + 0.5 * c;
|
1366 | let s = 0;
|
1367 |
|
1368 | if (l > 0.0 && l < 0.5) {
|
1369 | s = c / (2 * l);
|
1370 | } else if (l >= 0.5 && l < 1.0) {
|
1371 | s = c / (2 * (1 - l));
|
1372 | }
|
1373 |
|
1374 | return [hcg[0], s * 100, l * 100];
|
1375 | };
|
1376 |
|
1377 | convert.hcg.hwb = function (hcg) {
|
1378 | const c = hcg[1] / 100;
|
1379 | const g = hcg[2] / 100;
|
1380 | const v = c + g * (1.0 - c);
|
1381 | return [hcg[0], (v - c) * 100, (1 - v) * 100];
|
1382 | };
|
1383 |
|
1384 | convert.hwb.hcg = function (hwb) {
|
1385 | const w = hwb[1] / 100;
|
1386 | const b = hwb[2] / 100;
|
1387 | const v = 1 - b;
|
1388 | const c = v - w;
|
1389 | let g = 0;
|
1390 |
|
1391 | if (c < 1) {
|
1392 | g = (v - c) / (1 - c);
|
1393 | }
|
1394 |
|
1395 | return [hwb[0], c * 100, g * 100];
|
1396 | };
|
1397 |
|
1398 | convert.apple.rgb = function (apple) {
|
1399 | return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
|
1400 | };
|
1401 |
|
1402 | convert.rgb.apple = function (rgb) {
|
1403 | return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
|
1404 | };
|
1405 |
|
1406 | convert.gray.rgb = function (args) {
|
1407 | return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
|
1408 | };
|
1409 |
|
1410 | convert.gray.hsl = function (args) {
|
1411 | return [0, 0, args[0]];
|
1412 | };
|
1413 |
|
1414 | convert.gray.hsv = convert.gray.hsl;
|
1415 |
|
1416 | convert.gray.hwb = function (gray) {
|
1417 | return [0, 100, gray[0]];
|
1418 | };
|
1419 |
|
1420 | convert.gray.cmyk = function (gray) {
|
1421 | return [0, 0, 0, gray[0]];
|
1422 | };
|
1423 |
|
1424 | convert.gray.lab = function (gray) {
|
1425 | return [gray[0], 0, 0];
|
1426 | };
|
1427 |
|
1428 | convert.gray.hex = function (gray) {
|
1429 | const val = Math.round(gray[0] / 100 * 255) & 0xFF;
|
1430 | const integer = (val << 16) + (val << 8) + val;
|
1431 | const string = integer.toString(16).toUpperCase();
|
1432 | return '000000'.substring(string.length) + string;
|
1433 | };
|
1434 |
|
1435 | convert.rgb.gray = function (rgb) {
|
1436 | const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
|
1437 | return [val / 255 * 100];
|
1438 | };
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 | function buildGraph() {
|
1452 | const graph = {};
|
1453 |
|
1454 | const models = Object.keys(conversions);
|
1455 |
|
1456 | for (let len = models.length, i = 0; i < len; i++) {
|
1457 | graph[models[i]] = {
|
1458 |
|
1459 |
|
1460 | distance: -1,
|
1461 | parent: null
|
1462 | };
|
1463 | }
|
1464 |
|
1465 | return graph;
|
1466 | }
|
1467 |
|
1468 |
|
1469 | function deriveBFS(fromModel) {
|
1470 | const graph = buildGraph();
|
1471 | const queue = [fromModel];
|
1472 |
|
1473 | graph[fromModel].distance = 0;
|
1474 |
|
1475 | while (queue.length) {
|
1476 | const current = queue.pop();
|
1477 | const adjacents = Object.keys(conversions[current]);
|
1478 |
|
1479 | for (let len = adjacents.length, i = 0; i < len; i++) {
|
1480 | const adjacent = adjacents[i];
|
1481 | const node = graph[adjacent];
|
1482 |
|
1483 | if (node.distance === -1) {
|
1484 | node.distance = graph[current].distance + 1;
|
1485 | node.parent = current;
|
1486 | queue.unshift(adjacent);
|
1487 | }
|
1488 | }
|
1489 | }
|
1490 |
|
1491 | return graph;
|
1492 | }
|
1493 |
|
1494 | function link(from, to) {
|
1495 | return function (args) {
|
1496 | return to(from(args));
|
1497 | };
|
1498 | }
|
1499 |
|
1500 | function wrapConversion(toModel, graph) {
|
1501 | const path = [graph[toModel].parent, toModel];
|
1502 | let fn = conversions[graph[toModel].parent][toModel];
|
1503 | let cur = graph[toModel].parent;
|
1504 |
|
1505 | while (graph[cur].parent) {
|
1506 | path.unshift(graph[cur].parent);
|
1507 | fn = link(conversions[graph[cur].parent][cur], fn);
|
1508 | cur = graph[cur].parent;
|
1509 | }
|
1510 |
|
1511 | fn.conversion = path;
|
1512 | return fn;
|
1513 | }
|
1514 |
|
1515 | var route = function (fromModel) {
|
1516 | const graph = deriveBFS(fromModel);
|
1517 | const conversion = {};
|
1518 | const models = Object.keys(graph);
|
1519 |
|
1520 | for (let len = models.length, i = 0; i < len; i++) {
|
1521 | const toModel = models[i];
|
1522 | const node = graph[toModel];
|
1523 |
|
1524 | if (node.parent === null) {
|
1525 |
|
1526 | continue;
|
1527 | }
|
1528 |
|
1529 | conversion[toModel] = wrapConversion(toModel, graph);
|
1530 | }
|
1531 |
|
1532 | return conversion;
|
1533 | };
|
1534 |
|
1535 | const convert$1 = {};
|
1536 | const models = Object.keys(conversions);
|
1537 |
|
1538 | function wrapRaw(fn) {
|
1539 | const wrappedFn = function (...args) {
|
1540 | const arg0 = args[0];
|
1541 |
|
1542 | if (arg0 === undefined || arg0 === null) {
|
1543 | return arg0;
|
1544 | }
|
1545 |
|
1546 | if (arg0.length > 1) {
|
1547 | args = arg0;
|
1548 | }
|
1549 |
|
1550 | return fn(args);
|
1551 | };
|
1552 |
|
1553 |
|
1554 | if ('conversion' in fn) {
|
1555 | wrappedFn.conversion = fn.conversion;
|
1556 | }
|
1557 |
|
1558 | return wrappedFn;
|
1559 | }
|
1560 |
|
1561 | function wrapRounded(fn) {
|
1562 | const wrappedFn = function (...args) {
|
1563 | const arg0 = args[0];
|
1564 |
|
1565 | if (arg0 === undefined || arg0 === null) {
|
1566 | return arg0;
|
1567 | }
|
1568 |
|
1569 | if (arg0.length > 1) {
|
1570 | args = arg0;
|
1571 | }
|
1572 |
|
1573 | const result = fn(args);
|
1574 |
|
1575 |
|
1576 |
|
1577 | if (typeof result === 'object') {
|
1578 | for (let len = result.length, i = 0; i < len; i++) {
|
1579 | result[i] = Math.round(result[i]);
|
1580 | }
|
1581 | }
|
1582 |
|
1583 | return result;
|
1584 | };
|
1585 |
|
1586 |
|
1587 | if ('conversion' in fn) {
|
1588 | wrappedFn.conversion = fn.conversion;
|
1589 | }
|
1590 |
|
1591 | return wrappedFn;
|
1592 | }
|
1593 |
|
1594 | models.forEach(fromModel => {
|
1595 | convert$1[fromModel] = {};
|
1596 | Object.defineProperty(convert$1[fromModel], 'channels', {
|
1597 | value: conversions[fromModel].channels
|
1598 | });
|
1599 | Object.defineProperty(convert$1[fromModel], 'labels', {
|
1600 | value: conversions[fromModel].labels
|
1601 | });
|
1602 | const routes = route(fromModel);
|
1603 | const routeModels = Object.keys(routes);
|
1604 | routeModels.forEach(toModel => {
|
1605 | const fn = routes[toModel];
|
1606 | convert$1[fromModel][toModel] = wrapRounded(fn);
|
1607 | convert$1[fromModel][toModel].raw = wrapRaw(fn);
|
1608 | });
|
1609 | });
|
1610 | var colorConvert = convert$1;
|
1611 |
|
1612 | var ansiStyles = createCommonjsModule(function (module) {
|
1613 |
|
1614 | const wrapAnsi16 = (fn, offset) => (...args) => {
|
1615 | const code = fn(...args);
|
1616 | return `\u001B[${code + offset}m`;
|
1617 | };
|
1618 |
|
1619 | const wrapAnsi256 = (fn, offset) => (...args) => {
|
1620 | const code = fn(...args);
|
1621 | return `\u001B[${38 + offset};5;${code}m`;
|
1622 | };
|
1623 |
|
1624 | const wrapAnsi16m = (fn, offset) => (...args) => {
|
1625 | const rgb = fn(...args);
|
1626 | return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
1627 | };
|
1628 |
|
1629 | const ansi2ansi = n => n;
|
1630 |
|
1631 | const rgb2rgb = (r, g, b) => [r, g, b];
|
1632 |
|
1633 | const setLazyProperty = (object, property, get) => {
|
1634 | Object.defineProperty(object, property, {
|
1635 | get: () => {
|
1636 | const value = get();
|
1637 | Object.defineProperty(object, property, {
|
1638 | value,
|
1639 | enumerable: true,
|
1640 | configurable: true
|
1641 | });
|
1642 | return value;
|
1643 | },
|
1644 | enumerable: true,
|
1645 | configurable: true
|
1646 | });
|
1647 | };
|
1648 |
|
1649 |
|
1650 |
|
1651 | let colorConvert$1;
|
1652 |
|
1653 | const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
1654 | if (colorConvert$1 === undefined) {
|
1655 | colorConvert$1 = colorConvert;
|
1656 | }
|
1657 |
|
1658 | const offset = isBackground ? 10 : 0;
|
1659 | const styles = {};
|
1660 |
|
1661 | for (const [sourceSpace, suite] of Object.entries(colorConvert$1)) {
|
1662 | const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
|
1663 |
|
1664 | if (sourceSpace === targetSpace) {
|
1665 | styles[name] = wrap(identity, offset);
|
1666 | } else if (typeof suite === 'object') {
|
1667 | styles[name] = wrap(suite[targetSpace], offset);
|
1668 | }
|
1669 | }
|
1670 |
|
1671 | return styles;
|
1672 | };
|
1673 |
|
1674 | function assembleStyles() {
|
1675 | const codes = new Map();
|
1676 | const styles = {
|
1677 | modifier: {
|
1678 | reset: [0, 0],
|
1679 |
|
1680 | bold: [1, 22],
|
1681 | dim: [2, 22],
|
1682 | italic: [3, 23],
|
1683 | underline: [4, 24],
|
1684 | inverse: [7, 27],
|
1685 | hidden: [8, 28],
|
1686 | strikethrough: [9, 29]
|
1687 | },
|
1688 | color: {
|
1689 | black: [30, 39],
|
1690 | red: [31, 39],
|
1691 | green: [32, 39],
|
1692 | yellow: [33, 39],
|
1693 | blue: [34, 39],
|
1694 | magenta: [35, 39],
|
1695 | cyan: [36, 39],
|
1696 | white: [37, 39],
|
1697 |
|
1698 | blackBright: [90, 39],
|
1699 | redBright: [91, 39],
|
1700 | greenBright: [92, 39],
|
1701 | yellowBright: [93, 39],
|
1702 | blueBright: [94, 39],
|
1703 | magentaBright: [95, 39],
|
1704 | cyanBright: [96, 39],
|
1705 | whiteBright: [97, 39]
|
1706 | },
|
1707 | bgColor: {
|
1708 | bgBlack: [40, 49],
|
1709 | bgRed: [41, 49],
|
1710 | bgGreen: [42, 49],
|
1711 | bgYellow: [43, 49],
|
1712 | bgBlue: [44, 49],
|
1713 | bgMagenta: [45, 49],
|
1714 | bgCyan: [46, 49],
|
1715 | bgWhite: [47, 49],
|
1716 |
|
1717 | bgBlackBright: [100, 49],
|
1718 | bgRedBright: [101, 49],
|
1719 | bgGreenBright: [102, 49],
|
1720 | bgYellowBright: [103, 49],
|
1721 | bgBlueBright: [104, 49],
|
1722 | bgMagentaBright: [105, 49],
|
1723 | bgCyanBright: [106, 49],
|
1724 | bgWhiteBright: [107, 49]
|
1725 | }
|
1726 | };
|
1727 |
|
1728 | styles.color.gray = styles.color.blackBright;
|
1729 | styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
1730 | styles.color.grey = styles.color.blackBright;
|
1731 | styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
1732 |
|
1733 | for (const [groupName, group] of Object.entries(styles)) {
|
1734 | for (const [styleName, style] of Object.entries(group)) {
|
1735 | styles[styleName] = {
|
1736 | open: `\u001B[${style[0]}m`,
|
1737 | close: `\u001B[${style[1]}m`
|
1738 | };
|
1739 | group[styleName] = styles[styleName];
|
1740 | codes.set(style[0], style[1]);
|
1741 | }
|
1742 |
|
1743 | Object.defineProperty(styles, groupName, {
|
1744 | value: group,
|
1745 | enumerable: false
|
1746 | });
|
1747 | }
|
1748 |
|
1749 | Object.defineProperty(styles, 'codes', {
|
1750 | value: codes,
|
1751 | enumerable: false
|
1752 | });
|
1753 | styles.color.close = '\u001B[39m';
|
1754 | styles.bgColor.close = '\u001B[49m';
|
1755 | setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
|
1756 | setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
|
1757 | setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
|
1758 | setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
|
1759 | setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
|
1760 | setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
|
1761 | return styles;
|
1762 | }
|
1763 |
|
1764 |
|
1765 | Object.defineProperty(module, 'exports', {
|
1766 | enumerable: true,
|
1767 | get: assembleStyles
|
1768 | });
|
1769 | });
|
1770 |
|
1771 | var hasFlag = (flag, argv = process.argv) => {
|
1772 | const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
|
1773 | const position = argv.indexOf(prefix + flag);
|
1774 | const terminatorPosition = argv.indexOf('--');
|
1775 | return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
1776 | };
|
1777 |
|
1778 | const {
|
1779 | env
|
1780 | } = process;
|
1781 | let forceColor;
|
1782 |
|
1783 | if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
|
1784 | forceColor = 0;
|
1785 | } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
|
1786 | forceColor = 1;
|
1787 | }
|
1788 |
|
1789 | if ('FORCE_COLOR' in env) {
|
1790 | if (env.FORCE_COLOR === 'true') {
|
1791 | forceColor = 1;
|
1792 | } else if (env.FORCE_COLOR === 'false') {
|
1793 | forceColor = 0;
|
1794 | } else {
|
1795 | forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
1796 | }
|
1797 | }
|
1798 |
|
1799 | function translateLevel(level) {
|
1800 | if (level === 0) {
|
1801 | return false;
|
1802 | }
|
1803 |
|
1804 | return {
|
1805 | level,
|
1806 | hasBasic: true,
|
1807 | has256: level >= 2,
|
1808 | has16m: level >= 3
|
1809 | };
|
1810 | }
|
1811 |
|
1812 | function supportsColor(haveStream, streamIsTTY) {
|
1813 | if (forceColor === 0) {
|
1814 | return 0;
|
1815 | }
|
1816 |
|
1817 | if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
|
1818 | return 3;
|
1819 | }
|
1820 |
|
1821 | if (hasFlag('color=256')) {
|
1822 | return 2;
|
1823 | }
|
1824 |
|
1825 | if (haveStream && !streamIsTTY && forceColor === undefined) {
|
1826 | return 0;
|
1827 | }
|
1828 |
|
1829 | const min = forceColor || 0;
|
1830 |
|
1831 | if (env.TERM === 'dumb') {
|
1832 | return min;
|
1833 | }
|
1834 |
|
1835 | if (process.platform === 'win32') {
|
1836 |
|
1837 |
|
1838 | const osRelease = os__default['default'].release().split('.');
|
1839 |
|
1840 | if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
|
1841 | return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
1842 | }
|
1843 |
|
1844 | return 1;
|
1845 | }
|
1846 |
|
1847 | if ('CI' in env) {
|
1848 | if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
1849 | return 1;
|
1850 | }
|
1851 |
|
1852 | return min;
|
1853 | }
|
1854 |
|
1855 | if ('TEAMCITY_VERSION' in env) {
|
1856 | return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
1857 | }
|
1858 |
|
1859 | if ('GITHUB_ACTIONS' in env) {
|
1860 | return 1;
|
1861 | }
|
1862 |
|
1863 | if (env.COLORTERM === 'truecolor') {
|
1864 | return 3;
|
1865 | }
|
1866 |
|
1867 | if ('TERM_PROGRAM' in env) {
|
1868 | const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
1869 |
|
1870 | switch (env.TERM_PROGRAM) {
|
1871 | case 'iTerm.app':
|
1872 | return version >= 3 ? 3 : 2;
|
1873 |
|
1874 | case 'Apple_Terminal':
|
1875 | return 2;
|
1876 |
|
1877 | }
|
1878 | }
|
1879 |
|
1880 | if (/-256(color)?$/i.test(env.TERM)) {
|
1881 | return 2;
|
1882 | }
|
1883 |
|
1884 | if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
1885 | return 1;
|
1886 | }
|
1887 |
|
1888 | if ('COLORTERM' in env) {
|
1889 | return 1;
|
1890 | }
|
1891 |
|
1892 | return min;
|
1893 | }
|
1894 |
|
1895 | function getSupportLevel(stream) {
|
1896 | const level = supportsColor(stream, stream && stream.isTTY);
|
1897 | return translateLevel(level);
|
1898 | }
|
1899 |
|
1900 | var supportsColor_1 = {
|
1901 | supportsColor: getSupportLevel,
|
1902 | stdout: translateLevel(supportsColor(true, tty__default['default'].isatty(1))),
|
1903 | stderr: translateLevel(supportsColor(true, tty__default['default'].isatty(2)))
|
1904 | };
|
1905 |
|
1906 | const stringReplaceAll = (string, substring, replacer) => {
|
1907 | let index = string.indexOf(substring);
|
1908 |
|
1909 | if (index === -1) {
|
1910 | return string;
|
1911 | }
|
1912 |
|
1913 | const substringLength = substring.length;
|
1914 | let endIndex = 0;
|
1915 | let returnValue = '';
|
1916 |
|
1917 | do {
|
1918 | returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
1919 | endIndex = index + substringLength;
|
1920 | index = string.indexOf(substring, endIndex);
|
1921 | } while (index !== -1);
|
1922 |
|
1923 | returnValue += string.substr(endIndex);
|
1924 | return returnValue;
|
1925 | };
|
1926 |
|
1927 | const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
1928 | let endIndex = 0;
|
1929 | let returnValue = '';
|
1930 |
|
1931 | do {
|
1932 | const gotCR = string[index - 1] === '\r';
|
1933 | returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
1934 | endIndex = index + 1;
|
1935 | index = string.indexOf('\n', endIndex);
|
1936 | } while (index !== -1);
|
1937 |
|
1938 | returnValue += string.substr(endIndex);
|
1939 | return returnValue;
|
1940 | };
|
1941 |
|
1942 | var util = {
|
1943 | stringReplaceAll,
|
1944 | stringEncaseCRLFWithFirstIndex
|
1945 | };
|
1946 |
|
1947 | const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
1948 | const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
1949 | const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
1950 | const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
|
1951 | const ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
|
1952 |
|
1953 | function unescape(c) {
|
1954 | const u = c[0] === 'u';
|
1955 | const bracket = c[1] === '{';
|
1956 |
|
1957 | if (u && !bracket && c.length === 5 || c[0] === 'x' && c.length === 3) {
|
1958 | return String.fromCharCode(parseInt(c.slice(1), 16));
|
1959 | }
|
1960 |
|
1961 | if (u && bracket) {
|
1962 | return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
1963 | }
|
1964 |
|
1965 | return ESCAPES.get(c) || c;
|
1966 | }
|
1967 |
|
1968 | function parseArguments(name, arguments_) {
|
1969 | const results = [];
|
1970 | const chunks = arguments_.trim().split(/\s*,\s*/g);
|
1971 | let matches;
|
1972 |
|
1973 | for (const chunk of chunks) {
|
1974 | const number = Number(chunk);
|
1975 |
|
1976 | if (!Number.isNaN(number)) {
|
1977 | results.push(number);
|
1978 | } else if (matches = chunk.match(STRING_REGEX)) {
|
1979 | results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
|
1980 | } else {
|
1981 | throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
1982 | }
|
1983 | }
|
1984 |
|
1985 | return results;
|
1986 | }
|
1987 |
|
1988 | function parseStyle(style) {
|
1989 | STYLE_REGEX.lastIndex = 0;
|
1990 | const results = [];
|
1991 | let matches;
|
1992 |
|
1993 | while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
1994 | const name = matches[1];
|
1995 |
|
1996 | if (matches[2]) {
|
1997 | const args = parseArguments(name, matches[2]);
|
1998 | results.push([name].concat(args));
|
1999 | } else {
|
2000 | results.push([name]);
|
2001 | }
|
2002 | }
|
2003 |
|
2004 | return results;
|
2005 | }
|
2006 |
|
2007 | function buildStyle(chalk, styles) {
|
2008 | const enabled = {};
|
2009 |
|
2010 | for (const layer of styles) {
|
2011 | for (const style of layer.styles) {
|
2012 | enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
2013 | }
|
2014 | }
|
2015 |
|
2016 | let current = chalk;
|
2017 |
|
2018 | for (const [styleName, styles] of Object.entries(enabled)) {
|
2019 | if (!Array.isArray(styles)) {
|
2020 | continue;
|
2021 | }
|
2022 |
|
2023 | if (!(styleName in current)) {
|
2024 | throw new Error(`Unknown Chalk style: ${styleName}`);
|
2025 | }
|
2026 |
|
2027 | current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
|
2028 | }
|
2029 |
|
2030 | return current;
|
2031 | }
|
2032 |
|
2033 | var templates = (chalk, temporary) => {
|
2034 | const styles = [];
|
2035 | const chunks = [];
|
2036 | let chunk = [];
|
2037 |
|
2038 | temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
2039 | if (escapeCharacter) {
|
2040 | chunk.push(unescape(escapeCharacter));
|
2041 | } else if (style) {
|
2042 | const string = chunk.join('');
|
2043 | chunk = [];
|
2044 | chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
|
2045 | styles.push({
|
2046 | inverse,
|
2047 | styles: parseStyle(style)
|
2048 | });
|
2049 | } else if (close) {
|
2050 | if (styles.length === 0) {
|
2051 | throw new Error('Found extraneous } in Chalk template literal');
|
2052 | }
|
2053 |
|
2054 | chunks.push(buildStyle(chalk, styles)(chunk.join('')));
|
2055 | chunk = [];
|
2056 | styles.pop();
|
2057 | } else {
|
2058 | chunk.push(character);
|
2059 | }
|
2060 | });
|
2061 | chunks.push(chunk.join(''));
|
2062 |
|
2063 | if (styles.length > 0) {
|
2064 | const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
2065 | throw new Error(errMessage);
|
2066 | }
|
2067 |
|
2068 | return chunks.join('');
|
2069 | };
|
2070 |
|
2071 | const {
|
2072 | stdout: stdoutColor,
|
2073 | stderr: stderrColor
|
2074 | } = supportsColor_1;
|
2075 | const {
|
2076 | stringReplaceAll: stringReplaceAll$1,
|
2077 | stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
|
2078 | } = util;
|
2079 | const {
|
2080 | isArray
|
2081 | } = Array;
|
2082 |
|
2083 | const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
|
2084 | const styles = Object.create(null);
|
2085 |
|
2086 | const applyOptions = (object, options = {}) => {
|
2087 | if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
|
2088 | throw new Error('The `level` option should be an integer from 0 to 3');
|
2089 | }
|
2090 |
|
2091 |
|
2092 | const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
2093 | object.level = options.level === undefined ? colorLevel : options.level;
|
2094 | };
|
2095 |
|
2096 | class ChalkClass {
|
2097 | constructor(options) {
|
2098 |
|
2099 | return chalkFactory(options);
|
2100 | }
|
2101 |
|
2102 | }
|
2103 |
|
2104 | const chalkFactory = options => {
|
2105 | const chalk = {};
|
2106 | applyOptions(chalk, options);
|
2107 |
|
2108 | chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
|
2109 |
|
2110 | Object.setPrototypeOf(chalk, Chalk.prototype);
|
2111 | Object.setPrototypeOf(chalk.template, chalk);
|
2112 |
|
2113 | chalk.template.constructor = () => {
|
2114 | throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
|
2115 | };
|
2116 |
|
2117 | chalk.template.Instance = ChalkClass;
|
2118 | return chalk.template;
|
2119 | };
|
2120 |
|
2121 | function Chalk(options) {
|
2122 | return chalkFactory(options);
|
2123 | }
|
2124 |
|
2125 | for (const [styleName, style] of Object.entries(ansiStyles)) {
|
2126 | styles[styleName] = {
|
2127 | get() {
|
2128 | const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
2129 | Object.defineProperty(this, styleName, {
|
2130 | value: builder
|
2131 | });
|
2132 | return builder;
|
2133 | }
|
2134 |
|
2135 | };
|
2136 | }
|
2137 |
|
2138 | styles.visible = {
|
2139 | get() {
|
2140 | const builder = createBuilder(this, this._styler, true);
|
2141 | Object.defineProperty(this, 'visible', {
|
2142 | value: builder
|
2143 | });
|
2144 | return builder;
|
2145 | }
|
2146 |
|
2147 | };
|
2148 | const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
|
2149 |
|
2150 | for (const model of usedModels) {
|
2151 | styles[model] = {
|
2152 | get() {
|
2153 | const {
|
2154 | level
|
2155 | } = this;
|
2156 | return function (...arguments_) {
|
2157 | const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
|
2158 | return createBuilder(this, styler, this._isEmpty);
|
2159 | };
|
2160 | }
|
2161 |
|
2162 | };
|
2163 | }
|
2164 |
|
2165 | for (const model of usedModels) {
|
2166 | const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
2167 | styles[bgModel] = {
|
2168 | get() {
|
2169 | const {
|
2170 | level
|
2171 | } = this;
|
2172 | return function (...arguments_) {
|
2173 | const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
|
2174 | return createBuilder(this, styler, this._isEmpty);
|
2175 | };
|
2176 | }
|
2177 |
|
2178 | };
|
2179 | }
|
2180 |
|
2181 | const proto = Object.defineProperties(() => {}, Object.assign({}, styles, {
|
2182 | level: {
|
2183 | enumerable: true,
|
2184 |
|
2185 | get() {
|
2186 | return this._generator.level;
|
2187 | },
|
2188 |
|
2189 | set(level) {
|
2190 | this._generator.level = level;
|
2191 | }
|
2192 |
|
2193 | }
|
2194 | }));
|
2195 |
|
2196 | const createStyler = (open, close, parent) => {
|
2197 | let openAll;
|
2198 | let closeAll;
|
2199 |
|
2200 | if (parent === undefined) {
|
2201 | openAll = open;
|
2202 | closeAll = close;
|
2203 | } else {
|
2204 | openAll = parent.openAll + open;
|
2205 | closeAll = close + parent.closeAll;
|
2206 | }
|
2207 |
|
2208 | return {
|
2209 | open,
|
2210 | close,
|
2211 | openAll,
|
2212 | closeAll,
|
2213 | parent
|
2214 | };
|
2215 | };
|
2216 |
|
2217 | const createBuilder = (self, _styler, _isEmpty) => {
|
2218 | const builder = (...arguments_) => {
|
2219 | if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
|
2220 |
|
2221 | return applyStyle(builder, chalkTag(builder, ...arguments_));
|
2222 | }
|
2223 |
|
2224 |
|
2225 |
|
2226 | return applyStyle(builder, arguments_.length === 1 ? '' + arguments_[0] : arguments_.join(' '));
|
2227 | };
|
2228 |
|
2229 |
|
2230 |
|
2231 | Object.setPrototypeOf(builder, proto);
|
2232 | builder._generator = self;
|
2233 | builder._styler = _styler;
|
2234 | builder._isEmpty = _isEmpty;
|
2235 | return builder;
|
2236 | };
|
2237 |
|
2238 | const applyStyle = (self, string) => {
|
2239 | if (self.level <= 0 || !string) {
|
2240 | return self._isEmpty ? '' : string;
|
2241 | }
|
2242 |
|
2243 | let styler = self._styler;
|
2244 |
|
2245 | if (styler === undefined) {
|
2246 | return string;
|
2247 | }
|
2248 |
|
2249 | const {
|
2250 | openAll,
|
2251 | closeAll
|
2252 | } = styler;
|
2253 |
|
2254 | if (string.indexOf('\u001B') !== -1) {
|
2255 | while (styler !== undefined) {
|
2256 |
|
2257 |
|
2258 |
|
2259 | string = stringReplaceAll$1(string, styler.close, styler.open);
|
2260 | styler = styler.parent;
|
2261 | }
|
2262 | }
|
2263 |
|
2264 |
|
2265 |
|
2266 |
|
2267 | const lfIndex = string.indexOf('\n');
|
2268 |
|
2269 | if (lfIndex !== -1) {
|
2270 | string = stringEncaseCRLFWithFirstIndex$1(string, closeAll, openAll, lfIndex);
|
2271 | }
|
2272 |
|
2273 | return openAll + string + closeAll;
|
2274 | };
|
2275 |
|
2276 | let template;
|
2277 |
|
2278 | const chalkTag = (chalk, ...strings) => {
|
2279 | const [firstString] = strings;
|
2280 |
|
2281 | if (!isArray(firstString) || !isArray(firstString.raw)) {
|
2282 |
|
2283 |
|
2284 | return strings.join(' ');
|
2285 | }
|
2286 |
|
2287 | const arguments_ = strings.slice(1);
|
2288 | const parts = [firstString.raw[0]];
|
2289 |
|
2290 | for (let i = 1; i < firstString.length; i++) {
|
2291 | parts.push(String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), String(firstString.raw[i]));
|
2292 | }
|
2293 |
|
2294 | if (template === undefined) {
|
2295 | template = templates;
|
2296 | }
|
2297 |
|
2298 | return template(chalk, parts.join(''));
|
2299 | };
|
2300 |
|
2301 | Object.defineProperties(Chalk.prototype, styles);
|
2302 | const chalk = Chalk();
|
2303 |
|
2304 | chalk.supportsColor = stdoutColor;
|
2305 | chalk.stderr = Chalk({
|
2306 | level: stderrColor ? stderrColor.level : 0
|
2307 | });
|
2308 |
|
2309 | chalk.stderr.supportsColor = stderrColor;
|
2310 | var source = chalk;
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 |
|
2327 | function fromPairs(pairs) {
|
2328 | var index = -1,
|
2329 | length = pairs == null ? 0 : pairs.length,
|
2330 | result = {};
|
2331 |
|
2332 | while (++index < length) {
|
2333 | var pair = pairs[index];
|
2334 | result[pair[0]] = pair[1];
|
2335 | }
|
2336 |
|
2337 | return result;
|
2338 | }
|
2339 |
|
2340 | var fromPairs_1 = fromPairs;
|
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 |
|
2356 |
|
2357 |
|
2358 |
|
2359 |
|
2360 |
|
2361 |
|
2362 |
|
2363 |
|
2364 |
|
2365 | var isArray$1 = Array.isArray;
|
2366 | var isArray_1 = isArray$1;
|
2367 |
|
2368 |
|
2369 | var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
2370 | var _freeGlobal = freeGlobal;
|
2371 |
|
2372 |
|
2373 |
|
2374 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
2375 |
|
2376 |
|
2377 | var root = _freeGlobal || freeSelf || Function('return this')();
|
2378 | var _root = root;
|
2379 |
|
2380 |
|
2381 |
|
2382 | var Symbol$1 = _root.Symbol;
|
2383 | var _Symbol = Symbol$1;
|
2384 |
|
2385 |
|
2386 |
|
2387 | var objectProto = Object.prototype;
|
2388 |
|
2389 |
|
2390 | var hasOwnProperty = objectProto.hasOwnProperty;
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 | var nativeObjectToString = objectProto.toString;
|
2398 |
|
2399 |
|
2400 | var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 | function getRawTag(value) {
|
2410 | var isOwn = hasOwnProperty.call(value, symToStringTag),
|
2411 | tag = value[symToStringTag];
|
2412 |
|
2413 | try {
|
2414 | value[symToStringTag] = undefined;
|
2415 | var unmasked = true;
|
2416 | } catch (e) {}
|
2417 |
|
2418 | var result = nativeObjectToString.call(value);
|
2419 |
|
2420 | if (unmasked) {
|
2421 | if (isOwn) {
|
2422 | value[symToStringTag] = tag;
|
2423 | } else {
|
2424 | delete value[symToStringTag];
|
2425 | }
|
2426 | }
|
2427 |
|
2428 | return result;
|
2429 | }
|
2430 |
|
2431 | var _getRawTag = getRawTag;
|
2432 |
|
2433 |
|
2434 | var objectProto$1 = Object.prototype;
|
2435 |
|
2436 |
|
2437 |
|
2438 |
|
2439 |
|
2440 |
|
2441 | var nativeObjectToString$1 = objectProto$1.toString;
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 | function objectToString(value) {
|
2451 | return nativeObjectToString$1.call(value);
|
2452 | }
|
2453 |
|
2454 | var _objectToString = objectToString;
|
2455 |
|
2456 |
|
2457 |
|
2458 | var nullTag = '[object Null]',
|
2459 | undefinedTag = '[object Undefined]';
|
2460 |
|
2461 |
|
2462 | var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
|
2463 |
|
2464 |
|
2465 |
|
2466 |
|
2467 |
|
2468 |
|
2469 |
|
2470 |
|
2471 | function baseGetTag(value) {
|
2472 | if (value == null) {
|
2473 | return value === undefined ? undefinedTag : nullTag;
|
2474 | }
|
2475 |
|
2476 | return symToStringTag$1 && symToStringTag$1 in Object(value) ? _getRawTag(value) : _objectToString(value);
|
2477 | }
|
2478 |
|
2479 | var _baseGetTag = baseGetTag;
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 | function isObjectLike(value) {
|
2506 | return value != null && typeof value == 'object';
|
2507 | }
|
2508 |
|
2509 | var isObjectLike_1 = isObjectLike;
|
2510 |
|
2511 |
|
2512 |
|
2513 | var symbolTag = '[object Symbol]';
|
2514 |
|
2515 |
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 |
|
2524 |
|
2525 |
|
2526 |
|
2527 |
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 | function isSymbol(value) {
|
2533 | return typeof value == 'symbol' || isObjectLike_1(value) && _baseGetTag(value) == symbolTag;
|
2534 | }
|
2535 |
|
2536 | var isSymbol_1 = isSymbol;
|
2537 |
|
2538 |
|
2539 |
|
2540 | var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
|
2541 | reIsPlainProp = /^\w*$/;
|
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 | function isKey(value, object) {
|
2552 | if (isArray_1(value)) {
|
2553 | return false;
|
2554 | }
|
2555 |
|
2556 | var type = typeof value;
|
2557 |
|
2558 | if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol_1(value)) {
|
2559 | return true;
|
2560 | }
|
2561 |
|
2562 | return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
|
2563 | }
|
2564 |
|
2565 | var _isKey = isKey;
|
2566 |
|
2567 |
|
2568 |
|
2569 |
|
2570 |
|
2571 |
|
2572 |
|
2573 |
|
2574 |
|
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 | function isObject(value) {
|
2593 | var type = typeof value;
|
2594 | return value != null && (type == 'object' || type == 'function');
|
2595 | }
|
2596 |
|
2597 | var isObject_1 = isObject;
|
2598 |
|
2599 |
|
2600 |
|
2601 | var asyncTag = '[object AsyncFunction]',
|
2602 | funcTag = '[object Function]',
|
2603 | genTag = '[object GeneratorFunction]',
|
2604 | proxyTag = '[object Proxy]';
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 |
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 |
|
2623 | function isFunction(value) {
|
2624 | if (!isObject_1(value)) {
|
2625 | return false;
|
2626 | }
|
2627 |
|
2628 |
|
2629 |
|
2630 | var tag = _baseGetTag(value);
|
2631 | return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
|
2632 | }
|
2633 |
|
2634 | var isFunction_1 = isFunction;
|
2635 |
|
2636 |
|
2637 |
|
2638 | var coreJsData = _root['__core-js_shared__'];
|
2639 | var _coreJsData = coreJsData;
|
2640 |
|
2641 |
|
2642 |
|
2643 | var maskSrcKey = function () {
|
2644 | var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || '');
|
2645 | return uid ? 'Symbol(src)_1.' + uid : '';
|
2646 | }();
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 | function isMasked(func) {
|
2657 | return !!maskSrcKey && maskSrcKey in func;
|
2658 | }
|
2659 |
|
2660 | var _isMasked = isMasked;
|
2661 |
|
2662 |
|
2663 | var funcProto = Function.prototype;
|
2664 |
|
2665 |
|
2666 | var funcToString = funcProto.toString;
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 | function toSource(func) {
|
2676 | if (func != null) {
|
2677 | try {
|
2678 | return funcToString.call(func);
|
2679 | } catch (e) {}
|
2680 |
|
2681 | try {
|
2682 | return func + '';
|
2683 | } catch (e) {}
|
2684 | }
|
2685 |
|
2686 | return '';
|
2687 | }
|
2688 |
|
2689 | var _toSource = toSource;
|
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 |
|
2695 |
|
2696 | var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
2697 |
|
2698 |
|
2699 | var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
2700 |
|
2701 |
|
2702 | var funcProto$1 = Function.prototype,
|
2703 | objectProto$2 = Object.prototype;
|
2704 |
|
2705 |
|
2706 | var funcToString$1 = funcProto$1.toString;
|
2707 |
|
2708 |
|
2709 | var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
|
2710 |
|
2711 |
|
2712 | var reIsNative = RegExp('^' + funcToString$1.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 | function baseIsNative(value) {
|
2723 | if (!isObject_1(value) || _isMasked(value)) {
|
2724 | return false;
|
2725 | }
|
2726 |
|
2727 | var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
|
2728 | return pattern.test(_toSource(value));
|
2729 | }
|
2730 |
|
2731 | var _baseIsNative = baseIsNative;
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 | function getValue(object, key) {
|
2742 | return object == null ? undefined : object[key];
|
2743 | }
|
2744 |
|
2745 | var _getValue = getValue;
|
2746 |
|
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 |
|
2753 |
|
2754 |
|
2755 |
|
2756 | function getNative(object, key) {
|
2757 | var value = _getValue(object, key);
|
2758 | return _baseIsNative(value) ? value : undefined;
|
2759 | }
|
2760 |
|
2761 | var _getNative = getNative;
|
2762 |
|
2763 |
|
2764 |
|
2765 | var nativeCreate = _getNative(Object, 'create');
|
2766 | var _nativeCreate = nativeCreate;
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 | function hashClear() {
|
2777 | this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
|
2778 | this.size = 0;
|
2779 | }
|
2780 |
|
2781 | var _hashClear = hashClear;
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 |
|
2792 |
|
2793 | function hashDelete(key) {
|
2794 | var result = this.has(key) && delete this.__data__[key];
|
2795 | this.size -= result ? 1 : 0;
|
2796 | return result;
|
2797 | }
|
2798 |
|
2799 | var _hashDelete = hashDelete;
|
2800 |
|
2801 |
|
2802 |
|
2803 | var HASH_UNDEFINED = '__lodash_hash_undefined__';
|
2804 |
|
2805 |
|
2806 | var objectProto$3 = Object.prototype;
|
2807 |
|
2808 |
|
2809 | var hasOwnProperty$2 = objectProto$3.hasOwnProperty;
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 | function hashGet(key) {
|
2821 | var data = this.__data__;
|
2822 |
|
2823 | if (_nativeCreate) {
|
2824 | var result = data[key];
|
2825 | return result === HASH_UNDEFINED ? undefined : result;
|
2826 | }
|
2827 |
|
2828 | return hasOwnProperty$2.call(data, key) ? data[key] : undefined;
|
2829 | }
|
2830 |
|
2831 | var _hashGet = hashGet;
|
2832 |
|
2833 |
|
2834 |
|
2835 | var objectProto$4 = Object.prototype;
|
2836 |
|
2837 |
|
2838 | var hasOwnProperty$3 = objectProto$4.hasOwnProperty;
|
2839 |
|
2840 |
|
2841 |
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 | function hashHas(key) {
|
2850 | var data = this.__data__;
|
2851 | return _nativeCreate ? data[key] !== undefined : hasOwnProperty$3.call(data, key);
|
2852 | }
|
2853 |
|
2854 | var _hashHas = hashHas;
|
2855 |
|
2856 |
|
2857 |
|
2858 | var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 |
|
2868 |
|
2869 |
|
2870 | function hashSet(key, value) {
|
2871 | var data = this.__data__;
|
2872 | this.size += this.has(key) ? 0 : 1;
|
2873 | data[key] = _nativeCreate && value === undefined ? HASH_UNDEFINED$1 : value;
|
2874 | return this;
|
2875 | }
|
2876 |
|
2877 | var _hashSet = hashSet;
|
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 | function Hash(entries) {
|
2888 | var index = -1,
|
2889 | length = entries == null ? 0 : entries.length;
|
2890 | this.clear();
|
2891 |
|
2892 | while (++index < length) {
|
2893 | var entry = entries[index];
|
2894 | this.set(entry[0], entry[1]);
|
2895 | }
|
2896 | }
|
2897 |
|
2898 |
|
2899 | Hash.prototype.clear = _hashClear;
|
2900 | Hash.prototype['delete'] = _hashDelete;
|
2901 | Hash.prototype.get = _hashGet;
|
2902 | Hash.prototype.has = _hashHas;
|
2903 | Hash.prototype.set = _hashSet;
|
2904 | var _Hash = Hash;
|
2905 |
|
2906 |
|
2907 |
|
2908 |
|
2909 |
|
2910 |
|
2911 |
|
2912 |
|
2913 | function listCacheClear() {
|
2914 | this.__data__ = [];
|
2915 | this.size = 0;
|
2916 | }
|
2917 |
|
2918 | var _listCacheClear = listCacheClear;
|
2919 |
|
2920 |
|
2921 |
|
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 |
|
2930 |
|
2931 |
|
2932 |
|
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 |
|
2941 |
|
2942 |
|
2943 |
|
2944 |
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 | function eq(value, other) {
|
2953 | return value === other || value !== value && other !== other;
|
2954 | }
|
2955 |
|
2956 | var eq_1 = eq;
|
2957 |
|
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 |
|
2964 |
|
2965 |
|
2966 |
|
2967 | function assocIndexOf(array, key) {
|
2968 | var length = array.length;
|
2969 |
|
2970 | while (length--) {
|
2971 | if (eq_1(array[length][0], key)) {
|
2972 | return length;
|
2973 | }
|
2974 | }
|
2975 |
|
2976 | return -1;
|
2977 | }
|
2978 |
|
2979 | var _assocIndexOf = assocIndexOf;
|
2980 |
|
2981 |
|
2982 |
|
2983 | var arrayProto = Array.prototype;
|
2984 |
|
2985 |
|
2986 | var splice = arrayProto.splice;
|
2987 |
|
2988 |
|
2989 |
|
2990 |
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 |
|
2996 |
|
2997 | function listCacheDelete(key) {
|
2998 | var data = this.__data__,
|
2999 | index = _assocIndexOf(data, key);
|
3000 |
|
3001 | if (index < 0) {
|
3002 | return false;
|
3003 | }
|
3004 |
|
3005 | var lastIndex = data.length - 1;
|
3006 |
|
3007 | if (index == lastIndex) {
|
3008 | data.pop();
|
3009 | } else {
|
3010 | splice.call(data, index, 1);
|
3011 | }
|
3012 |
|
3013 | --this.size;
|
3014 | return true;
|
3015 | }
|
3016 |
|
3017 | var _listCacheDelete = listCacheDelete;
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 | function listCacheGet(key) {
|
3030 | var data = this.__data__,
|
3031 | index = _assocIndexOf(data, key);
|
3032 | return index < 0 ? undefined : data[index][1];
|
3033 | }
|
3034 |
|
3035 | var _listCacheGet = listCacheGet;
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 | function listCacheHas(key) {
|
3048 | return _assocIndexOf(this.__data__, key) > -1;
|
3049 | }
|
3050 |
|
3051 | var _listCacheHas = listCacheHas;
|
3052 |
|
3053 |
|
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 | function listCacheSet(key, value) {
|
3065 | var data = this.__data__,
|
3066 | index = _assocIndexOf(data, key);
|
3067 |
|
3068 | if (index < 0) {
|
3069 | ++this.size;
|
3070 | data.push([key, value]);
|
3071 | } else {
|
3072 | data[index][1] = value;
|
3073 | }
|
3074 |
|
3075 | return this;
|
3076 | }
|
3077 |
|
3078 | var _listCacheSet = listCacheSet;
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 |
|
3088 | function ListCache(entries) {
|
3089 | var index = -1,
|
3090 | length = entries == null ? 0 : entries.length;
|
3091 | this.clear();
|
3092 |
|
3093 | while (++index < length) {
|
3094 | var entry = entries[index];
|
3095 | this.set(entry[0], entry[1]);
|
3096 | }
|
3097 | }
|
3098 |
|
3099 |
|
3100 | ListCache.prototype.clear = _listCacheClear;
|
3101 | ListCache.prototype['delete'] = _listCacheDelete;
|
3102 | ListCache.prototype.get = _listCacheGet;
|
3103 | ListCache.prototype.has = _listCacheHas;
|
3104 | ListCache.prototype.set = _listCacheSet;
|
3105 | var _ListCache = ListCache;
|
3106 |
|
3107 |
|
3108 |
|
3109 | var Map$1 = _getNative(_root, 'Map');
|
3110 | var _Map = Map$1;
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 |
|
3118 |
|
3119 |
|
3120 | function mapCacheClear() {
|
3121 | this.size = 0;
|
3122 | this.__data__ = {
|
3123 | 'hash': new _Hash(),
|
3124 | 'map': new (_Map || _ListCache)(),
|
3125 | 'string': new _Hash()
|
3126 | };
|
3127 | }
|
3128 |
|
3129 | var _mapCacheClear = mapCacheClear;
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 | function isKeyable(value) {
|
3139 | var type = typeof value;
|
3140 | return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
|
3141 | }
|
3142 |
|
3143 | var _isKeyable = isKeyable;
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 |
|
3151 |
|
3152 |
|
3153 |
|
3154 | function getMapData(map, key) {
|
3155 | var data = map.__data__;
|
3156 | return _isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
|
3157 | }
|
3158 |
|
3159 | var _getMapData = getMapData;
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 | function mapCacheDelete(key) {
|
3172 | var result = _getMapData(this, key)['delete'](key);
|
3173 | this.size -= result ? 1 : 0;
|
3174 | return result;
|
3175 | }
|
3176 |
|
3177 | var _mapCacheDelete = mapCacheDelete;
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 | function mapCacheGet(key) {
|
3190 | return _getMapData(this, key).get(key);
|
3191 | }
|
3192 |
|
3193 | var _mapCacheGet = mapCacheGet;
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 |
|
3199 |
|
3200 |
|
3201 |
|
3202 |
|
3203 |
|
3204 |
|
3205 | function mapCacheHas(key) {
|
3206 | return _getMapData(this, key).has(key);
|
3207 | }
|
3208 |
|
3209 | var _mapCacheHas = mapCacheHas;
|
3210 |
|
3211 |
|
3212 |
|
3213 |
|
3214 |
|
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 |
|
3221 |
|
3222 | function mapCacheSet(key, value) {
|
3223 | var data = _getMapData(this, key),
|
3224 | size = data.size;
|
3225 | data.set(key, value);
|
3226 | this.size += data.size == size ? 0 : 1;
|
3227 | return this;
|
3228 | }
|
3229 |
|
3230 | var _mapCacheSet = mapCacheSet;
|
3231 |
|
3232 |
|
3233 |
|
3234 |
|
3235 |
|
3236 |
|
3237 |
|
3238 |
|
3239 |
|
3240 | function MapCache(entries) {
|
3241 | var index = -1,
|
3242 | length = entries == null ? 0 : entries.length;
|
3243 | this.clear();
|
3244 |
|
3245 | while (++index < length) {
|
3246 | var entry = entries[index];
|
3247 | this.set(entry[0], entry[1]);
|
3248 | }
|
3249 | }
|
3250 |
|
3251 |
|
3252 | MapCache.prototype.clear = _mapCacheClear;
|
3253 | MapCache.prototype['delete'] = _mapCacheDelete;
|
3254 | MapCache.prototype.get = _mapCacheGet;
|
3255 | MapCache.prototype.has = _mapCacheHas;
|
3256 | MapCache.prototype.set = _mapCacheSet;
|
3257 | var _MapCache = MapCache;
|
3258 |
|
3259 |
|
3260 |
|
3261 | var FUNC_ERROR_TEXT = 'Expected a function';
|
3262 |
|
3263 |
|
3264 |
|
3265 |
|
3266 |
|
3267 |
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 |
|
3281 |
|
3282 |
|
3283 |
|
3284 |
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 |
|
3303 |
|
3304 |
|
3305 |
|
3306 |
|
3307 | function memoize(func, resolver) {
|
3308 | if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
|
3309 | throw new TypeError(FUNC_ERROR_TEXT);
|
3310 | }
|
3311 |
|
3312 | var memoized = function () {
|
3313 | var args = arguments,
|
3314 | key = resolver ? resolver.apply(this, args) : args[0],
|
3315 | cache = memoized.cache;
|
3316 |
|
3317 | if (cache.has(key)) {
|
3318 | return cache.get(key);
|
3319 | }
|
3320 |
|
3321 | var result = func.apply(this, args);
|
3322 | memoized.cache = cache.set(key, result) || cache;
|
3323 | return result;
|
3324 | };
|
3325 |
|
3326 | memoized.cache = new (memoize.Cache || _MapCache)();
|
3327 | return memoized;
|
3328 | }
|
3329 |
|
3330 |
|
3331 | memoize.Cache = _MapCache;
|
3332 | var memoize_1 = memoize;
|
3333 |
|
3334 |
|
3335 |
|
3336 | var MAX_MEMOIZE_SIZE = 500;
|
3337 |
|
3338 |
|
3339 |
|
3340 |
|
3341 |
|
3342 |
|
3343 |
|
3344 |
|
3345 |
|
3346 | function memoizeCapped(func) {
|
3347 | var result = memoize_1(func, function (key) {
|
3348 | if (cache.size === MAX_MEMOIZE_SIZE) {
|
3349 | cache.clear();
|
3350 | }
|
3351 |
|
3352 | return key;
|
3353 | });
|
3354 | var cache = result.cache;
|
3355 | return result;
|
3356 | }
|
3357 |
|
3358 | var _memoizeCapped = memoizeCapped;
|
3359 |
|
3360 |
|
3361 |
|
3362 | var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
|
3363 |
|
3364 |
|
3365 | var reEscapeChar = /\\(\\)?/g;
|
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 | var stringToPath = _memoizeCapped(function (string) {
|
3375 | var result = [];
|
3376 |
|
3377 | if (string.charCodeAt(0) === 46
|
3378 |
|
3379 | ) {
|
3380 | result.push('');
|
3381 | }
|
3382 |
|
3383 | string.replace(rePropName, function (match, number, quote, subString) {
|
3384 | result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
|
3385 | });
|
3386 | return result;
|
3387 | });
|
3388 | var _stringToPath = stringToPath;
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 |
|
3399 | function arrayMap(array, iteratee) {
|
3400 | var index = -1,
|
3401 | length = array == null ? 0 : array.length,
|
3402 | result = Array(length);
|
3403 |
|
3404 | while (++index < length) {
|
3405 | result[index] = iteratee(array[index], index, array);
|
3406 | }
|
3407 |
|
3408 | return result;
|
3409 | }
|
3410 |
|
3411 | var _arrayMap = arrayMap;
|
3412 |
|
3413 |
|
3414 |
|
3415 | var INFINITY = 1 / 0;
|
3416 |
|
3417 |
|
3418 | var symbolProto = _Symbol ? _Symbol.prototype : undefined,
|
3419 | symbolToString = symbolProto ? symbolProto.toString : undefined;
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 | function baseToString(value) {
|
3430 |
|
3431 | if (typeof value == 'string') {
|
3432 | return value;
|
3433 | }
|
3434 |
|
3435 | if (isArray_1(value)) {
|
3436 |
|
3437 | return _arrayMap(value, baseToString) + '';
|
3438 | }
|
3439 |
|
3440 | if (isSymbol_1(value)) {
|
3441 | return symbolToString ? symbolToString.call(value) : '';
|
3442 | }
|
3443 |
|
3444 | var result = value + '';
|
3445 | return result == '0' && 1 / value == -INFINITY ? '-0' : result;
|
3446 | }
|
3447 |
|
3448 | var _baseToString = baseToString;
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 |
|
3464 |
|
3465 |
|
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 | function toString(value) {
|
3473 | return value == null ? '' : _baseToString(value);
|
3474 | }
|
3475 |
|
3476 | var toString_1 = toString;
|
3477 |
|
3478 |
|
3479 |
|
3480 |
|
3481 |
|
3482 |
|
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 | function castPath(value, object) {
|
3488 | if (isArray_1(value)) {
|
3489 | return value;
|
3490 | }
|
3491 |
|
3492 | return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
|
3493 | }
|
3494 |
|
3495 | var _castPath = castPath;
|
3496 |
|
3497 |
|
3498 |
|
3499 | var INFINITY$1 = 1 / 0;
|
3500 |
|
3501 |
|
3502 |
|
3503 |
|
3504 |
|
3505 |
|
3506 |
|
3507 |
|
3508 | function toKey(value) {
|
3509 | if (typeof value == 'string' || isSymbol_1(value)) {
|
3510 | return value;
|
3511 | }
|
3512 |
|
3513 | var result = value + '';
|
3514 | return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
|
3515 | }
|
3516 |
|
3517 | var _toKey = toKey;
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 | function baseGet(object, path) {
|
3529 | path = _castPath(path, object);
|
3530 | var index = 0,
|
3531 | length = path.length;
|
3532 |
|
3533 | while (object != null && index < length) {
|
3534 | object = object[_toKey(path[index++])];
|
3535 | }
|
3536 |
|
3537 | return index && index == length ? object : undefined;
|
3538 | }
|
3539 |
|
3540 | var _baseGet = baseGet;
|
3541 |
|
3542 | var defineProperty = function () {
|
3543 | try {
|
3544 | var func = _getNative(Object, 'defineProperty');
|
3545 | func({}, '', {});
|
3546 | return func;
|
3547 | } catch (e) {}
|
3548 | }();
|
3549 |
|
3550 | var _defineProperty = defineProperty;
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 | function baseAssignValue(object, key, value) {
|
3563 | if (key == '__proto__' && _defineProperty) {
|
3564 | _defineProperty(object, key, {
|
3565 | 'configurable': true,
|
3566 | 'enumerable': true,
|
3567 | 'value': value,
|
3568 | 'writable': true
|
3569 | });
|
3570 | } else {
|
3571 | object[key] = value;
|
3572 | }
|
3573 | }
|
3574 |
|
3575 | var _baseAssignValue = baseAssignValue;
|
3576 |
|
3577 |
|
3578 |
|
3579 | var objectProto$5 = Object.prototype;
|
3580 |
|
3581 |
|
3582 | var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 | function assignValue(object, key, value) {
|
3595 | var objValue = object[key];
|
3596 |
|
3597 | if (!(hasOwnProperty$4.call(object, key) && eq_1(objValue, value)) || value === undefined && !(key in object)) {
|
3598 | _baseAssignValue(object, key, value);
|
3599 | }
|
3600 | }
|
3601 |
|
3602 | var _assignValue = assignValue;
|
3603 |
|
3604 |
|
3605 | var MAX_SAFE_INTEGER = 9007199254740991;
|
3606 |
|
3607 |
|
3608 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
3609 |
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 |
|
3617 |
|
3618 | function isIndex(value, length) {
|
3619 | var type = typeof value;
|
3620 | length = length == null ? MAX_SAFE_INTEGER : length;
|
3621 | return !!length && (type == 'number' || type != 'symbol' && reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
|
3622 | }
|
3623 |
|
3624 | var _isIndex = isIndex;
|
3625 |
|
3626 |
|
3627 |
|
3628 |
|
3629 |
|
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 |
|
3635 |
|
3636 |
|
3637 | function baseSet(object, path, value, customizer) {
|
3638 | if (!isObject_1(object)) {
|
3639 | return object;
|
3640 | }
|
3641 |
|
3642 | path = _castPath(path, object);
|
3643 | var index = -1,
|
3644 | length = path.length,
|
3645 | lastIndex = length - 1,
|
3646 | nested = object;
|
3647 |
|
3648 | while (nested != null && ++index < length) {
|
3649 | var key = _toKey(path[index]),
|
3650 | newValue = value;
|
3651 |
|
3652 | if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
3653 | return object;
|
3654 | }
|
3655 |
|
3656 | if (index != lastIndex) {
|
3657 | var objValue = nested[key];
|
3658 | newValue = customizer ? customizer(objValue, key, nested) : undefined;
|
3659 |
|
3660 | if (newValue === undefined) {
|
3661 | newValue = isObject_1(objValue) ? objValue : _isIndex(path[index + 1]) ? [] : {};
|
3662 | }
|
3663 | }
|
3664 |
|
3665 | _assignValue(nested, key, newValue);
|
3666 | nested = nested[key];
|
3667 | }
|
3668 |
|
3669 | return object;
|
3670 | }
|
3671 |
|
3672 | var _baseSet = baseSet;
|
3673 |
|
3674 |
|
3675 |
|
3676 |
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 | function basePickBy(object, paths, predicate) {
|
3685 | var index = -1,
|
3686 | length = paths.length,
|
3687 | result = {};
|
3688 |
|
3689 | while (++index < length) {
|
3690 | var path = paths[index],
|
3691 | value = _baseGet(object, path);
|
3692 |
|
3693 | if (predicate(value, path)) {
|
3694 | _baseSet(result, _castPath(path, object), value);
|
3695 | }
|
3696 | }
|
3697 |
|
3698 | return result;
|
3699 | }
|
3700 |
|
3701 | var _basePickBy = basePickBy;
|
3702 |
|
3703 |
|
3704 |
|
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 | function baseHasIn(object, key) {
|
3712 | return object != null && key in Object(object);
|
3713 | }
|
3714 |
|
3715 | var _baseHasIn = baseHasIn;
|
3716 |
|
3717 |
|
3718 |
|
3719 | var argsTag = '[object Arguments]';
|
3720 |
|
3721 |
|
3722 |
|
3723 |
|
3724 |
|
3725 |
|
3726 |
|
3727 |
|
3728 | function baseIsArguments(value) {
|
3729 | return isObjectLike_1(value) && _baseGetTag(value) == argsTag;
|
3730 | }
|
3731 |
|
3732 | var _baseIsArguments = baseIsArguments;
|
3733 |
|
3734 |
|
3735 |
|
3736 | var objectProto$6 = Object.prototype;
|
3737 |
|
3738 |
|
3739 | var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
|
3740 |
|
3741 |
|
3742 | var propertyIsEnumerable = objectProto$6.propertyIsEnumerable;
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 |
|
3762 | var isArguments = _baseIsArguments(function () {
|
3763 | return arguments;
|
3764 | }()) ? _baseIsArguments : function (value) {
|
3765 | return isObjectLike_1(value) && hasOwnProperty$5.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
|
3766 | };
|
3767 | var isArguments_1 = isArguments;
|
3768 |
|
3769 |
|
3770 | var MAX_SAFE_INTEGER$1 = 9007199254740991;
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 |
|
3781 |
|
3782 |
|
3783 |
|
3784 |
|
3785 |
|
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 | function isLength(value) {
|
3799 | return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$1;
|
3800 | }
|
3801 |
|
3802 | var isLength_1 = isLength;
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 | function hasPath(object, path, hasFunc) {
|
3815 | path = _castPath(path, object);
|
3816 | var index = -1,
|
3817 | length = path.length,
|
3818 | result = false;
|
3819 |
|
3820 | while (++index < length) {
|
3821 | var key = _toKey(path[index]);
|
3822 |
|
3823 | if (!(result = object != null && hasFunc(object, key))) {
|
3824 | break;
|
3825 | }
|
3826 |
|
3827 | object = object[key];
|
3828 | }
|
3829 |
|
3830 | if (result || ++index != length) {
|
3831 | return result;
|
3832 | }
|
3833 |
|
3834 | length = object == null ? 0 : object.length;
|
3835 | return !!length && isLength_1(length) && _isIndex(key, length) && (isArray_1(object) || isArguments_1(object));
|
3836 | }
|
3837 |
|
3838 | var _hasPath = hasPath;
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 |
|
3848 |
|
3849 |
|
3850 |
|
3851 |
|
3852 |
|
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 | function hasIn(object, path) {
|
3868 | return object != null && _hasPath(object, path, _baseHasIn);
|
3869 | }
|
3870 |
|
3871 | var hasIn_1 = hasIn;
|
3872 |
|
3873 |
|
3874 |
|
3875 |
|
3876 |
|
3877 |
|
3878 |
|
3879 |
|
3880 |
|
3881 |
|
3882 |
|
3883 | function basePick(object, paths) {
|
3884 | return _basePickBy(object, paths, function (value, path) {
|
3885 | return hasIn_1(object, path);
|
3886 | });
|
3887 | }
|
3888 |
|
3889 | var _basePick = basePick;
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 |
|
3897 |
|
3898 |
|
3899 | function arrayPush(array, values) {
|
3900 | var index = -1,
|
3901 | length = values.length,
|
3902 | offset = array.length;
|
3903 |
|
3904 | while (++index < length) {
|
3905 | array[offset + index] = values[index];
|
3906 | }
|
3907 |
|
3908 | return array;
|
3909 | }
|
3910 |
|
3911 | var _arrayPush = arrayPush;
|
3912 |
|
3913 |
|
3914 |
|
3915 | var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
|
3916 |
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 | function isFlattenable(value) {
|
3925 | return isArray_1(value) || isArguments_1(value) || !!(spreadableSymbol && value && value[spreadableSymbol]);
|
3926 | }
|
3927 |
|
3928 | var _isFlattenable = isFlattenable;
|
3929 |
|
3930 |
|
3931 |
|
3932 |
|
3933 |
|
3934 |
|
3935 |
|
3936 |
|
3937 |
|
3938 |
|
3939 |
|
3940 |
|
3941 |
|
3942 | function baseFlatten(array, depth, predicate, isStrict, result) {
|
3943 | var index = -1,
|
3944 | length = array.length;
|
3945 | predicate || (predicate = _isFlattenable);
|
3946 | result || (result = []);
|
3947 |
|
3948 | while (++index < length) {
|
3949 | var value = array[index];
|
3950 |
|
3951 | if (depth > 0 && predicate(value)) {
|
3952 | if (depth > 1) {
|
3953 |
|
3954 | baseFlatten(value, depth - 1, predicate, isStrict, result);
|
3955 | } else {
|
3956 | _arrayPush(result, value);
|
3957 | }
|
3958 | } else if (!isStrict) {
|
3959 | result[result.length] = value;
|
3960 | }
|
3961 | }
|
3962 |
|
3963 | return result;
|
3964 | }
|
3965 |
|
3966 | var _baseFlatten = baseFlatten;
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 |
|
3983 | function flatten(array) {
|
3984 | var length = array == null ? 0 : array.length;
|
3985 | return length ? _baseFlatten(array, 1) : [];
|
3986 | }
|
3987 |
|
3988 | var flatten_1 = flatten;
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 | function apply(func, thisArg, args) {
|
4001 | switch (args.length) {
|
4002 | case 0:
|
4003 | return func.call(thisArg);
|
4004 |
|
4005 | case 1:
|
4006 | return func.call(thisArg, args[0]);
|
4007 |
|
4008 | case 2:
|
4009 | return func.call(thisArg, args[0], args[1]);
|
4010 |
|
4011 | case 3:
|
4012 | return func.call(thisArg, args[0], args[1], args[2]);
|
4013 | }
|
4014 |
|
4015 | return func.apply(thisArg, args);
|
4016 | }
|
4017 |
|
4018 | var _apply = apply;
|
4019 |
|
4020 |
|
4021 |
|
4022 | var nativeMax = Math.max;
|
4023 |
|
4024 |
|
4025 |
|
4026 |
|
4027 |
|
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 | function overRest(func, start, transform) {
|
4034 | start = nativeMax(start === undefined ? func.length - 1 : start, 0);
|
4035 | return function () {
|
4036 | var args = arguments,
|
4037 | index = -1,
|
4038 | length = nativeMax(args.length - start, 0),
|
4039 | array = Array(length);
|
4040 |
|
4041 | while (++index < length) {
|
4042 | array[index] = args[start + index];
|
4043 | }
|
4044 |
|
4045 | index = -1;
|
4046 | var otherArgs = Array(start + 1);
|
4047 |
|
4048 | while (++index < start) {
|
4049 | otherArgs[index] = args[index];
|
4050 | }
|
4051 |
|
4052 | otherArgs[start] = transform(array);
|
4053 | return _apply(func, this, otherArgs);
|
4054 | };
|
4055 | }
|
4056 |
|
4057 | var _overRest = overRest;
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 |
|
4072 |
|
4073 |
|
4074 |
|
4075 |
|
4076 |
|
4077 |
|
4078 | function constant(value) {
|
4079 | return function () {
|
4080 | return value;
|
4081 | };
|
4082 | }
|
4083 |
|
4084 | var constant_1 = constant;
|
4085 |
|
4086 |
|
4087 |
|
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 |
|
4099 |
|
4100 |
|
4101 |
|
4102 | function identity(value) {
|
4103 | return value;
|
4104 | }
|
4105 |
|
4106 | var identity_1 = identity;
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 |
|
4115 |
|
4116 |
|
4117 | var baseSetToString = !_defineProperty ? identity_1 : function (func, string) {
|
4118 | return _defineProperty(func, 'toString', {
|
4119 | 'configurable': true,
|
4120 | 'enumerable': false,
|
4121 | 'value': constant_1(string),
|
4122 | 'writable': true
|
4123 | });
|
4124 | };
|
4125 | var _baseSetToString = baseSetToString;
|
4126 |
|
4127 |
|
4128 | var HOT_COUNT = 800,
|
4129 | HOT_SPAN = 16;
|
4130 |
|
4131 |
|
4132 | var nativeNow = Date.now;
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 |
|
4143 | function shortOut(func) {
|
4144 | var count = 0,
|
4145 | lastCalled = 0;
|
4146 | return function () {
|
4147 | var stamp = nativeNow(),
|
4148 | remaining = HOT_SPAN - (stamp - lastCalled);
|
4149 | lastCalled = stamp;
|
4150 |
|
4151 | if (remaining > 0) {
|
4152 | if (++count >= HOT_COUNT) {
|
4153 | return arguments[0];
|
4154 | }
|
4155 | } else {
|
4156 | count = 0;
|
4157 | }
|
4158 |
|
4159 | return func.apply(undefined, arguments);
|
4160 | };
|
4161 | }
|
4162 |
|
4163 | var _shortOut = shortOut;
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 | var setToString = _shortOut(_baseSetToString);
|
4175 | var _setToString = setToString;
|
4176 |
|
4177 |
|
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 |
|
4184 |
|
4185 | function flatRest(func) {
|
4186 | return _setToString(_overRest(func, undefined, flatten_1), func + '');
|
4187 | }
|
4188 |
|
4189 | var _flatRest = flatRest;
|
4190 |
|
4191 |
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 |
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 | var pick = _flatRest(function (object, paths) {
|
4210 | return object == null ? {} : _basePick(object, paths);
|
4211 | });
|
4212 | var pick_1 = pick;
|
4213 |
|
4214 |
|
4215 |
|
4216 |
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 |
|
4222 |
|
4223 |
|
4224 | function arrayAggregator(array, setter, iteratee, accumulator) {
|
4225 | var index = -1,
|
4226 | length = array == null ? 0 : array.length;
|
4227 |
|
4228 | while (++index < length) {
|
4229 | var value = array[index];
|
4230 | setter(accumulator, value, iteratee(value), array);
|
4231 | }
|
4232 |
|
4233 | return accumulator;
|
4234 | }
|
4235 |
|
4236 | var _arrayAggregator = arrayAggregator;
|
4237 |
|
4238 |
|
4239 |
|
4240 |
|
4241 |
|
4242 |
|
4243 |
|
4244 |
|
4245 | function createBaseFor(fromRight) {
|
4246 | return function (object, iteratee, keysFunc) {
|
4247 | var index = -1,
|
4248 | iterable = Object(object),
|
4249 | props = keysFunc(object),
|
4250 | length = props.length;
|
4251 |
|
4252 | while (length--) {
|
4253 | var key = props[fromRight ? length : ++index];
|
4254 |
|
4255 | if (iteratee(iterable[key], key, iterable) === false) {
|
4256 | break;
|
4257 | }
|
4258 | }
|
4259 |
|
4260 | return object;
|
4261 | };
|
4262 | }
|
4263 |
|
4264 | var _createBaseFor = createBaseFor;
|
4265 |
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 | var baseFor = _createBaseFor();
|
4279 | var _baseFor = baseFor;
|
4280 |
|
4281 |
|
4282 |
|
4283 |
|
4284 |
|
4285 |
|
4286 |
|
4287 |
|
4288 |
|
4289 |
|
4290 | function baseTimes(n, iteratee) {
|
4291 | var index = -1,
|
4292 | result = Array(n);
|
4293 |
|
4294 | while (++index < n) {
|
4295 | result[index] = iteratee(index);
|
4296 | }
|
4297 |
|
4298 | return result;
|
4299 | }
|
4300 |
|
4301 | var _baseTimes = baseTimes;
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 | function stubFalse() {
|
4317 | return false;
|
4318 | }
|
4319 |
|
4320 | var stubFalse_1 = stubFalse;
|
4321 |
|
4322 | var isBuffer_1 = createCommonjsModule(function (module, exports) {
|
4323 |
|
4324 | var freeExports = exports && !exports.nodeType && exports;
|
4325 |
|
4326 |
|
4327 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
4328 |
|
4329 |
|
4330 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
4331 |
|
4332 |
|
4333 | var Buffer = moduleExports ? _root.Buffer : undefined;
|
4334 |
|
4335 |
|
4336 | var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
4337 | |
4338 |
|
4339 |
|
4340 |
|
4341 |
|
4342 |
|
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 |
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 | var isBuffer = nativeIsBuffer || stubFalse_1;
|
4356 | module.exports = isBuffer;
|
4357 | });
|
4358 |
|
4359 |
|
4360 |
|
4361 | var argsTag$1 = '[object Arguments]',
|
4362 | arrayTag = '[object Array]',
|
4363 | boolTag = '[object Boolean]',
|
4364 | dateTag = '[object Date]',
|
4365 | errorTag = '[object Error]',
|
4366 | funcTag$1 = '[object Function]',
|
4367 | mapTag = '[object Map]',
|
4368 | numberTag = '[object Number]',
|
4369 | objectTag = '[object Object]',
|
4370 | regexpTag = '[object RegExp]',
|
4371 | setTag = '[object Set]',
|
4372 | stringTag = '[object String]',
|
4373 | weakMapTag = '[object WeakMap]';
|
4374 | var arrayBufferTag = '[object ArrayBuffer]',
|
4375 | dataViewTag = '[object DataView]',
|
4376 | float32Tag = '[object Float32Array]',
|
4377 | float64Tag = '[object Float64Array]',
|
4378 | int8Tag = '[object Int8Array]',
|
4379 | int16Tag = '[object Int16Array]',
|
4380 | int32Tag = '[object Int32Array]',
|
4381 | uint8Tag = '[object Uint8Array]',
|
4382 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
4383 | uint16Tag = '[object Uint16Array]',
|
4384 | uint32Tag = '[object Uint32Array]';
|
4385 |
|
4386 |
|
4387 | var typedArrayTags = {};
|
4388 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
|
4389 | typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] = typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = typedArrayTags[errorTag] = typedArrayTags[funcTag$1] = typedArrayTags[mapTag] = typedArrayTags[numberTag] = typedArrayTags[objectTag] = typedArrayTags[regexpTag] = typedArrayTags[setTag] = typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
|
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 |
|
4395 |
|
4396 |
|
4397 |
|
4398 | function baseIsTypedArray(value) {
|
4399 | return isObjectLike_1(value) && isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
|
4400 | }
|
4401 |
|
4402 | var _baseIsTypedArray = baseIsTypedArray;
|
4403 |
|
4404 |
|
4405 |
|
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 |
|
4411 | function baseUnary(func) {
|
4412 | return function (value) {
|
4413 | return func(value);
|
4414 | };
|
4415 | }
|
4416 |
|
4417 | var _baseUnary = baseUnary;
|
4418 |
|
4419 | var _nodeUtil = createCommonjsModule(function (module, exports) {
|
4420 |
|
4421 | var freeExports = exports && !exports.nodeType && exports;
|
4422 |
|
4423 |
|
4424 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
4425 |
|
4426 |
|
4427 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
4428 |
|
4429 |
|
4430 | var freeProcess = moduleExports && _freeGlobal.process;
|
4431 |
|
4432 |
|
4433 | var nodeUtil = function () {
|
4434 | try {
|
4435 |
|
4436 | var types = freeModule && freeModule.require && freeModule.require('util').types;
|
4437 |
|
4438 | if (types) {
|
4439 | return types;
|
4440 | }
|
4441 |
|
4442 |
|
4443 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
4444 | } catch (e) {}
|
4445 | }();
|
4446 |
|
4447 | module.exports = nodeUtil;
|
4448 | });
|
4449 |
|
4450 |
|
4451 |
|
4452 | var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
|
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 |
|
4470 |
|
4471 | var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
|
4472 | var isTypedArray_1 = isTypedArray;
|
4473 |
|
4474 |
|
4475 |
|
4476 | var objectProto$7 = Object.prototype;
|
4477 |
|
4478 |
|
4479 | var hasOwnProperty$6 = objectProto$7.hasOwnProperty;
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 |
|
4488 |
|
4489 | function arrayLikeKeys(value, inherited) {
|
4490 | var isArr = isArray_1(value),
|
4491 | isArg = !isArr && isArguments_1(value),
|
4492 | isBuff = !isArr && !isArg && isBuffer_1(value),
|
4493 | isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
|
4494 | skipIndexes = isArr || isArg || isBuff || isType,
|
4495 | result = skipIndexes ? _baseTimes(value.length, String) : [],
|
4496 | length = result.length;
|
4497 |
|
4498 | for (var key in value) {
|
4499 | if ((inherited || hasOwnProperty$6.call(value, key)) && !(skipIndexes && (
|
4500 | key == 'length' ||
|
4501 | isBuff && (key == 'offset' || key == 'parent') ||
|
4502 | isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') ||
|
4503 | _isIndex(key, length)))) {
|
4504 | result.push(key);
|
4505 | }
|
4506 | }
|
4507 |
|
4508 | return result;
|
4509 | }
|
4510 |
|
4511 | var _arrayLikeKeys = arrayLikeKeys;
|
4512 |
|
4513 |
|
4514 | var objectProto$8 = Object.prototype;
|
4515 |
|
4516 |
|
4517 |
|
4518 |
|
4519 |
|
4520 |
|
4521 |
|
4522 |
|
4523 | function isPrototype(value) {
|
4524 | var Ctor = value && value.constructor,
|
4525 | proto = typeof Ctor == 'function' && Ctor.prototype || objectProto$8;
|
4526 | return value === proto;
|
4527 | }
|
4528 |
|
4529 | var _isPrototype = isPrototype;
|
4530 |
|
4531 |
|
4532 |
|
4533 |
|
4534 |
|
4535 |
|
4536 |
|
4537 |
|
4538 |
|
4539 | function overArg(func, transform) {
|
4540 | return function (arg) {
|
4541 | return func(transform(arg));
|
4542 | };
|
4543 | }
|
4544 |
|
4545 | var _overArg = overArg;
|
4546 |
|
4547 |
|
4548 |
|
4549 | var nativeKeys = _overArg(Object.keys, Object);
|
4550 | var _nativeKeys = nativeKeys;
|
4551 |
|
4552 |
|
4553 |
|
4554 | var objectProto$9 = Object.prototype;
|
4555 |
|
4556 |
|
4557 | var hasOwnProperty$7 = objectProto$9.hasOwnProperty;
|
4558 |
|
4559 |
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 |
|
4566 | function baseKeys(object) {
|
4567 | if (!_isPrototype(object)) {
|
4568 | return _nativeKeys(object);
|
4569 | }
|
4570 |
|
4571 | var result = [];
|
4572 |
|
4573 | for (var key in Object(object)) {
|
4574 | if (hasOwnProperty$7.call(object, key) && key != 'constructor') {
|
4575 | result.push(key);
|
4576 | }
|
4577 | }
|
4578 |
|
4579 | return result;
|
4580 | }
|
4581 |
|
4582 | var _baseKeys = baseKeys;
|
4583 |
|
4584 |
|
4585 |
|
4586 |
|
4587 |
|
4588 |
|
4589 |
|
4590 |
|
4591 |
|
4592 |
|
4593 |
|
4594 |
|
4595 |
|
4596 |
|
4597 |
|
4598 |
|
4599 |
|
4600 |
|
4601 |
|
4602 |
|
4603 |
|
4604 |
|
4605 |
|
4606 |
|
4607 |
|
4608 |
|
4609 |
|
4610 | function isArrayLike(value) {
|
4611 | return value != null && isLength_1(value.length) && !isFunction_1(value);
|
4612 | }
|
4613 |
|
4614 | var isArrayLike_1 = isArrayLike;
|
4615 |
|
4616 |
|
4617 |
|
4618 |
|
4619 |
|
4620 |
|
4621 |
|
4622 |
|
4623 |
|
4624 |
|
4625 |
|
4626 |
|
4627 |
|
4628 |
|
4629 |
|
4630 |
|
4631 |
|
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 |
|
4637 |
|
4638 |
|
4639 |
|
4640 |
|
4641 |
|
4642 |
|
4643 |
|
4644 |
|
4645 | function keys(object) {
|
4646 | return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
|
4647 | }
|
4648 |
|
4649 | var keys_1 = keys;
|
4650 |
|
4651 |
|
4652 |
|
4653 |
|
4654 |
|
4655 |
|
4656 |
|
4657 |
|
4658 |
|
4659 |
|
4660 | function baseForOwn(object, iteratee) {
|
4661 | return object && _baseFor(object, iteratee, keys_1);
|
4662 | }
|
4663 |
|
4664 | var _baseForOwn = baseForOwn;
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 | function createBaseEach(eachFunc, fromRight) {
|
4676 | return function (collection, iteratee) {
|
4677 | if (collection == null) {
|
4678 | return collection;
|
4679 | }
|
4680 |
|
4681 | if (!isArrayLike_1(collection)) {
|
4682 | return eachFunc(collection, iteratee);
|
4683 | }
|
4684 |
|
4685 | var length = collection.length,
|
4686 | index = fromRight ? length : -1,
|
4687 | iterable = Object(collection);
|
4688 |
|
4689 | while (fromRight ? index-- : ++index < length) {
|
4690 | if (iteratee(iterable[index], index, iterable) === false) {
|
4691 | break;
|
4692 | }
|
4693 | }
|
4694 |
|
4695 | return collection;
|
4696 | };
|
4697 | }
|
4698 |
|
4699 | var _createBaseEach = createBaseEach;
|
4700 |
|
4701 |
|
4702 |
|
4703 |
|
4704 |
|
4705 |
|
4706 |
|
4707 |
|
4708 |
|
4709 |
|
4710 | var baseEach = _createBaseEach(_baseForOwn);
|
4711 | var _baseEach = baseEach;
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 | function baseAggregator(collection, setter, iteratee, accumulator) {
|
4726 | _baseEach(collection, function (value, key, collection) {
|
4727 | setter(accumulator, value, iteratee(value), collection);
|
4728 | });
|
4729 | return accumulator;
|
4730 | }
|
4731 |
|
4732 | var _baseAggregator = baseAggregator;
|
4733 |
|
4734 |
|
4735 |
|
4736 |
|
4737 |
|
4738 |
|
4739 |
|
4740 |
|
4741 |
|
4742 | function stackClear() {
|
4743 | this.__data__ = new _ListCache();
|
4744 | this.size = 0;
|
4745 | }
|
4746 |
|
4747 | var _stackClear = stackClear;
|
4748 |
|
4749 |
|
4750 |
|
4751 |
|
4752 |
|
4753 |
|
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 | function stackDelete(key) {
|
4759 | var data = this.__data__,
|
4760 | result = data['delete'](key);
|
4761 | this.size = data.size;
|
4762 | return result;
|
4763 | }
|
4764 |
|
4765 | var _stackDelete = stackDelete;
|
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 | function stackGet(key) {
|
4777 | return this.__data__.get(key);
|
4778 | }
|
4779 |
|
4780 | var _stackGet = stackGet;
|
4781 |
|
4782 |
|
4783 |
|
4784 |
|
4785 |
|
4786 |
|
4787 |
|
4788 |
|
4789 |
|
4790 |
|
4791 | function stackHas(key) {
|
4792 | return this.__data__.has(key);
|
4793 | }
|
4794 |
|
4795 | var _stackHas = stackHas;
|
4796 |
|
4797 |
|
4798 |
|
4799 | var LARGE_ARRAY_SIZE = 200;
|
4800 |
|
4801 |
|
4802 |
|
4803 |
|
4804 |
|
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 |
|
4810 |
|
4811 | function stackSet(key, value) {
|
4812 | var data = this.__data__;
|
4813 |
|
4814 | if (data instanceof _ListCache) {
|
4815 | var pairs = data.__data__;
|
4816 |
|
4817 | if (!_Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
|
4818 | pairs.push([key, value]);
|
4819 | this.size = ++data.size;
|
4820 | return this;
|
4821 | }
|
4822 |
|
4823 | data = this.__data__ = new _MapCache(pairs);
|
4824 | }
|
4825 |
|
4826 | data.set(key, value);
|
4827 | this.size = data.size;
|
4828 | return this;
|
4829 | }
|
4830 |
|
4831 | var _stackSet = stackSet;
|
4832 |
|
4833 |
|
4834 |
|
4835 |
|
4836 |
|
4837 |
|
4838 |
|
4839 |
|
4840 |
|
4841 | function Stack(entries) {
|
4842 | var data = this.__data__ = new _ListCache(entries);
|
4843 | this.size = data.size;
|
4844 | }
|
4845 |
|
4846 |
|
4847 | Stack.prototype.clear = _stackClear;
|
4848 | Stack.prototype['delete'] = _stackDelete;
|
4849 | Stack.prototype.get = _stackGet;
|
4850 | Stack.prototype.has = _stackHas;
|
4851 | Stack.prototype.set = _stackSet;
|
4852 | var _Stack = Stack;
|
4853 |
|
4854 |
|
4855 | var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
|
4856 |
|
4857 |
|
4858 |
|
4859 |
|
4860 |
|
4861 |
|
4862 |
|
4863 |
|
4864 |
|
4865 |
|
4866 |
|
4867 | function setCacheAdd(value) {
|
4868 | this.__data__.set(value, HASH_UNDEFINED$2);
|
4869 |
|
4870 | return this;
|
4871 | }
|
4872 |
|
4873 | var _setCacheAdd = setCacheAdd;
|
4874 |
|
4875 |
|
4876 |
|
4877 |
|
4878 |
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 | function setCacheHas(value) {
|
4885 | return this.__data__.has(value);
|
4886 | }
|
4887 |
|
4888 | var _setCacheHas = setCacheHas;
|
4889 |
|
4890 |
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 | function SetCache(values) {
|
4900 | var index = -1,
|
4901 | length = values == null ? 0 : values.length;
|
4902 | this.__data__ = new _MapCache();
|
4903 |
|
4904 | while (++index < length) {
|
4905 | this.add(values[index]);
|
4906 | }
|
4907 | }
|
4908 |
|
4909 |
|
4910 | SetCache.prototype.add = SetCache.prototype.push = _setCacheAdd;
|
4911 | SetCache.prototype.has = _setCacheHas;
|
4912 | var _SetCache = SetCache;
|
4913 |
|
4914 |
|
4915 |
|
4916 |
|
4917 |
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 | function arraySome(array, predicate) {
|
4925 | var index = -1,
|
4926 | length = array == null ? 0 : array.length;
|
4927 |
|
4928 | while (++index < length) {
|
4929 | if (predicate(array[index], index, array)) {
|
4930 | return true;
|
4931 | }
|
4932 | }
|
4933 |
|
4934 | return false;
|
4935 | }
|
4936 |
|
4937 | var _arraySome = arraySome;
|
4938 |
|
4939 |
|
4940 |
|
4941 |
|
4942 |
|
4943 |
|
4944 |
|
4945 |
|
4946 |
|
4947 | function cacheHas(cache, key) {
|
4948 | return cache.has(key);
|
4949 | }
|
4950 |
|
4951 | var _cacheHas = cacheHas;
|
4952 |
|
4953 |
|
4954 |
|
4955 | var COMPARE_PARTIAL_FLAG = 1,
|
4956 | COMPARE_UNORDERED_FLAG = 2;
|
4957 |
|
4958 |
|
4959 |
|
4960 |
|
4961 |
|
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 | function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
|
4972 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
|
4973 | arrLength = array.length,
|
4974 | othLength = other.length;
|
4975 |
|
4976 | if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
|
4977 | return false;
|
4978 | }
|
4979 |
|
4980 |
|
4981 | var arrStacked = stack.get(array);
|
4982 | var othStacked = stack.get(other);
|
4983 |
|
4984 | if (arrStacked && othStacked) {
|
4985 | return arrStacked == other && othStacked == array;
|
4986 | }
|
4987 |
|
4988 | var index = -1,
|
4989 | result = true,
|
4990 | seen = bitmask & COMPARE_UNORDERED_FLAG ? new _SetCache() : undefined;
|
4991 | stack.set(array, other);
|
4992 | stack.set(other, array);
|
4993 |
|
4994 | while (++index < arrLength) {
|
4995 | var arrValue = array[index],
|
4996 | othValue = other[index];
|
4997 |
|
4998 | if (customizer) {
|
4999 | var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
|
5000 | }
|
5001 |
|
5002 | if (compared !== undefined) {
|
5003 | if (compared) {
|
5004 | continue;
|
5005 | }
|
5006 |
|
5007 | result = false;
|
5008 | break;
|
5009 | }
|
5010 |
|
5011 |
|
5012 | if (seen) {
|
5013 | if (!_arraySome(other, function (othValue, othIndex) {
|
5014 | if (!_cacheHas(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
5015 | return seen.push(othIndex);
|
5016 | }
|
5017 | })) {
|
5018 | result = false;
|
5019 | break;
|
5020 | }
|
5021 | } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
|
5022 | result = false;
|
5023 | break;
|
5024 | }
|
5025 | }
|
5026 |
|
5027 | stack['delete'](array);
|
5028 | stack['delete'](other);
|
5029 | return result;
|
5030 | }
|
5031 |
|
5032 | var _equalArrays = equalArrays;
|
5033 |
|
5034 |
|
5035 |
|
5036 | var Uint8Array = _root.Uint8Array;
|
5037 | var _Uint8Array = Uint8Array;
|
5038 |
|
5039 |
|
5040 |
|
5041 |
|
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 | function mapToArray(map) {
|
5047 | var index = -1,
|
5048 | result = Array(map.size);
|
5049 | map.forEach(function (value, key) {
|
5050 | result[++index] = [key, value];
|
5051 | });
|
5052 | return result;
|
5053 | }
|
5054 |
|
5055 | var _mapToArray = mapToArray;
|
5056 |
|
5057 |
|
5058 |
|
5059 |
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 | function setToArray(set) {
|
5065 | var index = -1,
|
5066 | result = Array(set.size);
|
5067 | set.forEach(function (value) {
|
5068 | result[++index] = value;
|
5069 | });
|
5070 | return result;
|
5071 | }
|
5072 |
|
5073 | var _setToArray = setToArray;
|
5074 |
|
5075 |
|
5076 |
|
5077 | var COMPARE_PARTIAL_FLAG$1 = 1,
|
5078 | COMPARE_UNORDERED_FLAG$1 = 2;
|
5079 |
|
5080 |
|
5081 | var boolTag$1 = '[object Boolean]',
|
5082 | dateTag$1 = '[object Date]',
|
5083 | errorTag$1 = '[object Error]',
|
5084 | mapTag$1 = '[object Map]',
|
5085 | numberTag$1 = '[object Number]',
|
5086 | regexpTag$1 = '[object RegExp]',
|
5087 | setTag$1 = '[object Set]',
|
5088 | stringTag$1 = '[object String]',
|
5089 | symbolTag$1 = '[object Symbol]';
|
5090 | var arrayBufferTag$1 = '[object ArrayBuffer]',
|
5091 | dataViewTag$1 = '[object DataView]';
|
5092 |
|
5093 |
|
5094 | var symbolProto$1 = _Symbol ? _Symbol.prototype : undefined,
|
5095 | symbolValueOf = symbolProto$1 ? symbolProto$1.valueOf : undefined;
|
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 |
|
5104 |
|
5105 |
|
5106 |
|
5107 |
|
5108 |
|
5109 |
|
5110 |
|
5111 |
|
5112 |
|
5113 |
|
5114 | function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
|
5115 | switch (tag) {
|
5116 | case dataViewTag$1:
|
5117 | if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
|
5118 | return false;
|
5119 | }
|
5120 |
|
5121 | object = object.buffer;
|
5122 | other = other.buffer;
|
5123 |
|
5124 | case arrayBufferTag$1:
|
5125 | if (object.byteLength != other.byteLength || !equalFunc(new _Uint8Array(object), new _Uint8Array(other))) {
|
5126 | return false;
|
5127 | }
|
5128 |
|
5129 | return true;
|
5130 |
|
5131 | case boolTag$1:
|
5132 | case dateTag$1:
|
5133 | case numberTag$1:
|
5134 |
|
5135 |
|
5136 | return eq_1(+object, +other);
|
5137 |
|
5138 | case errorTag$1:
|
5139 | return object.name == other.name && object.message == other.message;
|
5140 |
|
5141 | case regexpTag$1:
|
5142 | case stringTag$1:
|
5143 |
|
5144 |
|
5145 |
|
5146 | return object == other + '';
|
5147 |
|
5148 | case mapTag$1:
|
5149 | var convert = _mapToArray;
|
5150 |
|
5151 | case setTag$1:
|
5152 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG$1;
|
5153 | convert || (convert = _setToArray);
|
5154 |
|
5155 | if (object.size != other.size && !isPartial) {
|
5156 | return false;
|
5157 | }
|
5158 |
|
5159 |
|
5160 | var stacked = stack.get(object);
|
5161 |
|
5162 | if (stacked) {
|
5163 | return stacked == other;
|
5164 | }
|
5165 |
|
5166 | bitmask |= COMPARE_UNORDERED_FLAG$1;
|
5167 |
|
5168 | stack.set(object, other);
|
5169 | var result = _equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
|
5170 | stack['delete'](object);
|
5171 | return result;
|
5172 |
|
5173 | case symbolTag$1:
|
5174 | if (symbolValueOf) {
|
5175 | return symbolValueOf.call(object) == symbolValueOf.call(other);
|
5176 | }
|
5177 |
|
5178 | }
|
5179 |
|
5180 | return false;
|
5181 | }
|
5182 |
|
5183 | var _equalByTag = equalByTag;
|
5184 |
|
5185 |
|
5186 |
|
5187 |
|
5188 |
|
5189 |
|
5190 |
|
5191 |
|
5192 |
|
5193 |
|
5194 |
|
5195 |
|
5196 |
|
5197 | function baseGetAllKeys(object, keysFunc, symbolsFunc) {
|
5198 | var result = keysFunc(object);
|
5199 | return isArray_1(object) ? result : _arrayPush(result, symbolsFunc(object));
|
5200 | }
|
5201 |
|
5202 | var _baseGetAllKeys = baseGetAllKeys;
|
5203 |
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 |
|
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 | function arrayFilter(array, predicate) {
|
5214 | var index = -1,
|
5215 | length = array == null ? 0 : array.length,
|
5216 | resIndex = 0,
|
5217 | result = [];
|
5218 |
|
5219 | while (++index < length) {
|
5220 | var value = array[index];
|
5221 |
|
5222 | if (predicate(value, index, array)) {
|
5223 | result[resIndex++] = value;
|
5224 | }
|
5225 | }
|
5226 |
|
5227 | return result;
|
5228 | }
|
5229 |
|
5230 | var _arrayFilter = arrayFilter;
|
5231 |
|
5232 |
|
5233 |
|
5234 |
|
5235 |
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 |
|
5243 |
|
5244 |
|
5245 |
|
5246 |
|
5247 |
|
5248 |
|
5249 |
|
5250 | function stubArray() {
|
5251 | return [];
|
5252 | }
|
5253 |
|
5254 | var stubArray_1 = stubArray;
|
5255 |
|
5256 |
|
5257 |
|
5258 | var objectProto$a = Object.prototype;
|
5259 |
|
5260 |
|
5261 | var propertyIsEnumerable$1 = objectProto$a.propertyIsEnumerable;
|
5262 |
|
5263 |
|
5264 | var nativeGetSymbols = Object.getOwnPropertySymbols;
|
5265 |
|
5266 |
|
5267 |
|
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 | var getSymbols = !nativeGetSymbols ? stubArray_1 : function (object) {
|
5274 | if (object == null) {
|
5275 | return [];
|
5276 | }
|
5277 |
|
5278 | object = Object(object);
|
5279 | return _arrayFilter(nativeGetSymbols(object), function (symbol) {
|
5280 | return propertyIsEnumerable$1.call(object, symbol);
|
5281 | });
|
5282 | };
|
5283 | var _getSymbols = getSymbols;
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 | function getAllKeys(object) {
|
5294 | return _baseGetAllKeys(object, keys_1, _getSymbols);
|
5295 | }
|
5296 |
|
5297 | var _getAllKeys = getAllKeys;
|
5298 |
|
5299 |
|
5300 |
|
5301 | var COMPARE_PARTIAL_FLAG$2 = 1;
|
5302 |
|
5303 |
|
5304 | var objectProto$b = Object.prototype;
|
5305 |
|
5306 |
|
5307 | var hasOwnProperty$8 = objectProto$b.hasOwnProperty;
|
5308 |
|
5309 |
|
5310 |
|
5311 |
|
5312 |
|
5313 |
|
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
|
5321 |
|
5322 | function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
|
5323 | var isPartial = bitmask & COMPARE_PARTIAL_FLAG$2,
|
5324 | objProps = _getAllKeys(object),
|
5325 | objLength = objProps.length,
|
5326 | othProps = _getAllKeys(other),
|
5327 | othLength = othProps.length;
|
5328 |
|
5329 | if (objLength != othLength && !isPartial) {
|
5330 | return false;
|
5331 | }
|
5332 |
|
5333 | var index = objLength;
|
5334 |
|
5335 | while (index--) {
|
5336 | var key = objProps[index];
|
5337 |
|
5338 | if (!(isPartial ? key in other : hasOwnProperty$8.call(other, key))) {
|
5339 | return false;
|
5340 | }
|
5341 | }
|
5342 |
|
5343 |
|
5344 | var objStacked = stack.get(object);
|
5345 | var othStacked = stack.get(other);
|
5346 |
|
5347 | if (objStacked && othStacked) {
|
5348 | return objStacked == other && othStacked == object;
|
5349 | }
|
5350 |
|
5351 | var result = true;
|
5352 | stack.set(object, other);
|
5353 | stack.set(other, object);
|
5354 | var skipCtor = isPartial;
|
5355 |
|
5356 | while (++index < objLength) {
|
5357 | key = objProps[index];
|
5358 | var objValue = object[key],
|
5359 | othValue = other[key];
|
5360 |
|
5361 | if (customizer) {
|
5362 | var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
|
5363 | }
|
5364 |
|
5365 |
|
5366 | if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
|
5367 | result = false;
|
5368 | break;
|
5369 | }
|
5370 |
|
5371 | skipCtor || (skipCtor = key == 'constructor');
|
5372 | }
|
5373 |
|
5374 | if (result && !skipCtor) {
|
5375 | var objCtor = object.constructor,
|
5376 | othCtor = other.constructor;
|
5377 |
|
5378 | if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
5379 | result = false;
|
5380 | }
|
5381 | }
|
5382 |
|
5383 | stack['delete'](object);
|
5384 | stack['delete'](other);
|
5385 | return result;
|
5386 | }
|
5387 |
|
5388 | var _equalObjects = equalObjects;
|
5389 |
|
5390 |
|
5391 |
|
5392 | var DataView = _getNative(_root, 'DataView');
|
5393 | var _DataView = DataView;
|
5394 |
|
5395 |
|
5396 |
|
5397 | var Promise$1 = _getNative(_root, 'Promise');
|
5398 | var _Promise = Promise$1;
|
5399 |
|
5400 |
|
5401 |
|
5402 | var Set$1 = _getNative(_root, 'Set');
|
5403 | var _Set = Set$1;
|
5404 |
|
5405 |
|
5406 |
|
5407 | var WeakMap$1 = _getNative(_root, 'WeakMap');
|
5408 | var _WeakMap = WeakMap$1;
|
5409 |
|
5410 |
|
5411 |
|
5412 | var mapTag$2 = '[object Map]',
|
5413 | objectTag$1 = '[object Object]',
|
5414 | promiseTag = '[object Promise]',
|
5415 | setTag$2 = '[object Set]',
|
5416 | weakMapTag$1 = '[object WeakMap]';
|
5417 | var dataViewTag$2 = '[object DataView]';
|
5418 |
|
5419 |
|
5420 | var dataViewCtorString = _toSource(_DataView),
|
5421 | mapCtorString = _toSource(_Map),
|
5422 | promiseCtorString = _toSource(_Promise),
|
5423 | setCtorString = _toSource(_Set),
|
5424 | weakMapCtorString = _toSource(_WeakMap);
|
5425 |
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 | var getTag = _baseGetTag;
|
5434 |
|
5435 | if (_DataView && getTag(new _DataView(new ArrayBuffer(1))) != dataViewTag$2 || _Map && getTag(new _Map()) != mapTag$2 || _Promise && getTag(_Promise.resolve()) != promiseTag || _Set && getTag(new _Set()) != setTag$2 || _WeakMap && getTag(new _WeakMap()) != weakMapTag$1) {
|
5436 | getTag = function (value) {
|
5437 | var result = _baseGetTag(value),
|
5438 | Ctor = result == objectTag$1 ? value.constructor : undefined,
|
5439 | ctorString = Ctor ? _toSource(Ctor) : '';
|
5440 |
|
5441 | if (ctorString) {
|
5442 | switch (ctorString) {
|
5443 | case dataViewCtorString:
|
5444 | return dataViewTag$2;
|
5445 |
|
5446 | case mapCtorString:
|
5447 | return mapTag$2;
|
5448 |
|
5449 | case promiseCtorString:
|
5450 | return promiseTag;
|
5451 |
|
5452 | case setCtorString:
|
5453 | return setTag$2;
|
5454 |
|
5455 | case weakMapCtorString:
|
5456 | return weakMapTag$1;
|
5457 | }
|
5458 | }
|
5459 |
|
5460 | return result;
|
5461 | };
|
5462 | }
|
5463 |
|
5464 | var _getTag = getTag;
|
5465 |
|
5466 |
|
5467 |
|
5468 | var COMPARE_PARTIAL_FLAG$3 = 1;
|
5469 |
|
5470 |
|
5471 | var argsTag$2 = '[object Arguments]',
|
5472 | arrayTag$1 = '[object Array]',
|
5473 | objectTag$2 = '[object Object]';
|
5474 |
|
5475 |
|
5476 | var objectProto$c = Object.prototype;
|
5477 |
|
5478 |
|
5479 | var hasOwnProperty$9 = objectProto$c.hasOwnProperty;
|
5480 |
|
5481 |
|
5482 |
|
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 |
|
5494 |
|
5495 | function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
5496 | var objIsArr = isArray_1(object),
|
5497 | othIsArr = isArray_1(other),
|
5498 | objTag = objIsArr ? arrayTag$1 : _getTag(object),
|
5499 | othTag = othIsArr ? arrayTag$1 : _getTag(other);
|
5500 | objTag = objTag == argsTag$2 ? objectTag$2 : objTag;
|
5501 | othTag = othTag == argsTag$2 ? objectTag$2 : othTag;
|
5502 | var objIsObj = objTag == objectTag$2,
|
5503 | othIsObj = othTag == objectTag$2,
|
5504 | isSameTag = objTag == othTag;
|
5505 |
|
5506 | if (isSameTag && isBuffer_1(object)) {
|
5507 | if (!isBuffer_1(other)) {
|
5508 | return false;
|
5509 | }
|
5510 |
|
5511 | objIsArr = true;
|
5512 | objIsObj = false;
|
5513 | }
|
5514 |
|
5515 | if (isSameTag && !objIsObj) {
|
5516 | stack || (stack = new _Stack());
|
5517 | return objIsArr || isTypedArray_1(object) ? _equalArrays(object, other, bitmask, customizer, equalFunc, stack) : _equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
|
5518 | }
|
5519 |
|
5520 | if (!(bitmask & COMPARE_PARTIAL_FLAG$3)) {
|
5521 | var objIsWrapped = objIsObj && hasOwnProperty$9.call(object, '__wrapped__'),
|
5522 | othIsWrapped = othIsObj && hasOwnProperty$9.call(other, '__wrapped__');
|
5523 |
|
5524 | if (objIsWrapped || othIsWrapped) {
|
5525 | var objUnwrapped = objIsWrapped ? object.value() : object,
|
5526 | othUnwrapped = othIsWrapped ? other.value() : other;
|
5527 | stack || (stack = new _Stack());
|
5528 | return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
|
5529 | }
|
5530 | }
|
5531 |
|
5532 | if (!isSameTag) {
|
5533 | return false;
|
5534 | }
|
5535 |
|
5536 | stack || (stack = new _Stack());
|
5537 | return _equalObjects(object, other, bitmask, customizer, equalFunc, stack);
|
5538 | }
|
5539 |
|
5540 | var _baseIsEqualDeep = baseIsEqualDeep;
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 |
|
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 | function baseIsEqual(value, other, bitmask, customizer, stack) {
|
5558 | if (value === other) {
|
5559 | return true;
|
5560 | }
|
5561 |
|
5562 | if (value == null || other == null || !isObjectLike_1(value) && !isObjectLike_1(other)) {
|
5563 | return value !== value && other !== other;
|
5564 | }
|
5565 |
|
5566 | return _baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
|
5567 | }
|
5568 |
|
5569 | var _baseIsEqual = baseIsEqual;
|
5570 |
|
5571 |
|
5572 |
|
5573 | var COMPARE_PARTIAL_FLAG$4 = 1,
|
5574 | COMPARE_UNORDERED_FLAG$2 = 2;
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 | function baseIsMatch(object, source, matchData, customizer) {
|
5587 | var index = matchData.length,
|
5588 | length = index,
|
5589 | noCustomizer = !customizer;
|
5590 |
|
5591 | if (object == null) {
|
5592 | return !length;
|
5593 | }
|
5594 |
|
5595 | object = Object(object);
|
5596 |
|
5597 | while (index--) {
|
5598 | var data = matchData[index];
|
5599 |
|
5600 | if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
|
5601 | return false;
|
5602 | }
|
5603 | }
|
5604 |
|
5605 | while (++index < length) {
|
5606 | data = matchData[index];
|
5607 | var key = data[0],
|
5608 | objValue = object[key],
|
5609 | srcValue = data[1];
|
5610 |
|
5611 | if (noCustomizer && data[2]) {
|
5612 | if (objValue === undefined && !(key in object)) {
|
5613 | return false;
|
5614 | }
|
5615 | } else {
|
5616 | var stack = new _Stack();
|
5617 |
|
5618 | if (customizer) {
|
5619 | var result = customizer(objValue, srcValue, key, object, source, stack);
|
5620 | }
|
5621 |
|
5622 | if (!(result === undefined ? _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$4 | COMPARE_UNORDERED_FLAG$2, customizer, stack) : result)) {
|
5623 | return false;
|
5624 | }
|
5625 | }
|
5626 | }
|
5627 |
|
5628 | return true;
|
5629 | }
|
5630 |
|
5631 | var _baseIsMatch = baseIsMatch;
|
5632 |
|
5633 |
|
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 |
|
5641 |
|
5642 | function isStrictComparable(value) {
|
5643 | return value === value && !isObject_1(value);
|
5644 | }
|
5645 |
|
5646 | var _isStrictComparable = isStrictComparable;
|
5647 |
|
5648 |
|
5649 |
|
5650 |
|
5651 |
|
5652 |
|
5653 |
|
5654 |
|
5655 |
|
5656 | function getMatchData(object) {
|
5657 | var result = keys_1(object),
|
5658 | length = result.length;
|
5659 |
|
5660 | while (length--) {
|
5661 | var key = result[length],
|
5662 | value = object[key];
|
5663 | result[length] = [key, value, _isStrictComparable(value)];
|
5664 | }
|
5665 |
|
5666 | return result;
|
5667 | }
|
5668 |
|
5669 | var _getMatchData = getMatchData;
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 | function matchesStrictComparable(key, srcValue) {
|
5681 | return function (object) {
|
5682 | if (object == null) {
|
5683 | return false;
|
5684 | }
|
5685 |
|
5686 | return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
|
5687 | };
|
5688 | }
|
5689 |
|
5690 | var _matchesStrictComparable = matchesStrictComparable;
|
5691 |
|
5692 |
|
5693 |
|
5694 |
|
5695 |
|
5696 |
|
5697 |
|
5698 |
|
5699 |
|
5700 | function baseMatches(source) {
|
5701 | var matchData = _getMatchData(source);
|
5702 |
|
5703 | if (matchData.length == 1 && matchData[0][2]) {
|
5704 | return _matchesStrictComparable(matchData[0][0], matchData[0][1]);
|
5705 | }
|
5706 |
|
5707 | return function (object) {
|
5708 | return object === source || _baseIsMatch(object, source, matchData);
|
5709 | };
|
5710 | }
|
5711 |
|
5712 | var _baseMatches = baseMatches;
|
5713 |
|
5714 |
|
5715 |
|
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 | function get(object, path, defaultValue) {
|
5741 | var result = object == null ? undefined : _baseGet(object, path);
|
5742 | return result === undefined ? defaultValue : result;
|
5743 | }
|
5744 |
|
5745 | var get_1 = get;
|
5746 |
|
5747 | /** Used to compose bitmasks for value comparisons. */
|
5748 |
|
5749 | var COMPARE_PARTIAL_FLAG$5 = 1,
|
5750 | COMPARE_UNORDERED_FLAG$3 = 2;
|
5751 | /**
|
5752 | * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
|
5753 | *
|
5754 | * @private
|
5755 | * @param {string} path The path of the property to get.
|
5756 | * @param {*} srcValue The value to match.
|
5757 | * @returns {Function} Returns the new spec function.
|
5758 | */
|
5759 |
|
5760 | function baseMatchesProperty(path, srcValue) {
|
5761 | if (_isKey(path) && _isStrictComparable(srcValue)) {
|
5762 | return _matchesStrictComparable(_toKey(path), srcValue);
|
5763 | }
|
5764 |
|
5765 | return function (object) {
|
5766 | var objValue = get_1(object, path);
|
5767 | return objValue === undefined && objValue === srcValue ? hasIn_1(object, path) : _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$5 | COMPARE_UNORDERED_FLAG$3);
|
5768 | };
|
5769 | }
|
5770 |
|
5771 | var _baseMatchesProperty = baseMatchesProperty;
|
5772 |
|
5773 |
|
5774 |
|
5775 |
|
5776 |
|
5777 |
|
5778 |
|
5779 |
|
5780 | function baseProperty(key) {
|
5781 | return function (object) {
|
5782 | return object == null ? undefined : object[key];
|
5783 | };
|
5784 | }
|
5785 |
|
5786 | var _baseProperty = baseProperty;
|
5787 |
|
5788 |
|
5789 |
|
5790 |
|
5791 |
|
5792 |
|
5793 |
|
5794 |
|
5795 |
|
5796 | function basePropertyDeep(path) {
|
5797 | return function (object) {
|
5798 | return _baseGet(object, path);
|
5799 | };
|
5800 | }
|
5801 |
|
5802 | var _basePropertyDeep = basePropertyDeep;
|
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 |
|
5810 |
|
5811 |
|
5812 |
|
5813 |
|
5814 |
|
5815 |
|
5816 |
|
5817 |
|
5818 |
|
5819 |
|
5820 |
|
5821 |
|
5822 |
|
5823 |
|
5824 |
|
5825 |
|
5826 |
|
5827 | function property(path) {
|
5828 | return _isKey(path) ? _baseProperty(_toKey(path)) : _basePropertyDeep(path);
|
5829 | }
|
5830 |
|
5831 | var property_1 = property;
|
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 |
|
5838 |
|
5839 |
|
5840 |
|
5841 | function baseIteratee(value) {
|
5842 |
|
5843 |
|
5844 | if (typeof value == 'function') {
|
5845 | return value;
|
5846 | }
|
5847 |
|
5848 | if (value == null) {
|
5849 | return identity_1;
|
5850 | }
|
5851 |
|
5852 | if (typeof value == 'object') {
|
5853 | return isArray_1(value) ? _baseMatchesProperty(value[0], value[1]) : _baseMatches(value);
|
5854 | }
|
5855 |
|
5856 | return property_1(value);
|
5857 | }
|
5858 |
|
5859 | var _baseIteratee = baseIteratee;
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 | function createAggregator(setter, initializer) {
|
5871 | return function (collection, iteratee) {
|
5872 | var func = isArray_1(collection) ? _arrayAggregator : _baseAggregator,
|
5873 | accumulator = initializer ? initializer() : {};
|
5874 | return func(collection, setter, _baseIteratee(iteratee), accumulator);
|
5875 | };
|
5876 | }
|
5877 |
|
5878 | var _createAggregator = createAggregator;
|
5879 |
|
5880 |
|
5881 |
|
5882 | var objectProto$d = Object.prototype;
|
5883 |
|
5884 |
|
5885 | var hasOwnProperty$a = objectProto$d.hasOwnProperty;
|
5886 |
|
5887 |
|
5888 |
|
5889 |
|
5890 |
|
5891 |
|
5892 |
|
5893 |
|
5894 |
|
5895 |
|
5896 |
|
5897 |
|
5898 |
|
5899 |
|
5900 |
|
5901 |
|
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 |
|
5908 |
|
5909 |
|
5910 | var groupBy = _createAggregator(function (result, value, key) {
|
5911 | if (hasOwnProperty$a.call(result, key)) {
|
5912 | result[key].push(value);
|
5913 | } else {
|
5914 | _baseAssignValue(result, key, [value]);
|
5915 | }
|
5916 | });
|
5917 | var groupBy_1 = groupBy;
|
5918 |
|
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 |
|
5928 |
|
5929 |
|
5930 |
|
5931 |
|
5932 |
|
5933 |
|
5934 |
|
5935 |
|
5936 |
|
5937 |
|
5938 |
|
5939 |
|
5940 |
|
5941 |
|
5942 |
|
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 |
|
5948 |
|
5949 |
|
5950 |
|
5951 |
|
5952 |
|
5953 |
|
5954 |
|
5955 |
|
5956 | var partition = _createAggregator(function (result, value, key) {
|
5957 | result[key ? 0 : 1].push(value);
|
5958 | }, function () {
|
5959 | return [[], []];
|
5960 | });
|
5961 | var partition_1 = partition;
|
5962 |
|
5963 | var thirdParty = require("./third-party");
|
5964 |
|
5965 | var prettierInternal = src.__internal;
|
5966 |
|
5967 | var minimist = function (args, opts) {
|
5968 | if (!opts) opts = {};
|
5969 | var flags = {
|
5970 | bools: {},
|
5971 | strings: {},
|
5972 | unknownFn: null
|
5973 | };
|
5974 |
|
5975 | if (typeof opts['unknown'] === 'function') {
|
5976 | flags.unknownFn = opts['unknown'];
|
5977 | }
|
5978 |
|
5979 | if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
|
5980 | flags.allBools = true;
|
5981 | } else {
|
5982 | [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
|
5983 | flags.bools[key] = true;
|
5984 | });
|
5985 | }
|
5986 |
|
5987 | var aliases = {};
|
5988 | Object.keys(opts.alias || {}).forEach(function (key) {
|
5989 | aliases[key] = [].concat(opts.alias[key]);
|
5990 | aliases[key].forEach(function (x) {
|
5991 | aliases[x] = [key].concat(aliases[key].filter(function (y) {
|
5992 | return x !== y;
|
5993 | }));
|
5994 | });
|
5995 | });
|
5996 | [].concat(opts.string).filter(Boolean).forEach(function (key) {
|
5997 | flags.strings[key] = true;
|
5998 |
|
5999 | if (aliases[key]) {
|
6000 | flags.strings[aliases[key]] = true;
|
6001 | }
|
6002 | });
|
6003 | var defaults = opts['default'] || {};
|
6004 | var argv = {
|
6005 | _: []
|
6006 | };
|
6007 | Object.keys(flags.bools).forEach(function (key) {
|
6008 | setArg(key, defaults[key] === undefined ? false : defaults[key]);
|
6009 | });
|
6010 | var notFlags = [];
|
6011 |
|
6012 | if (args.indexOf('--') !== -1) {
|
6013 | notFlags = args.slice(args.indexOf('--') + 1);
|
6014 | args = args.slice(0, args.indexOf('--'));
|
6015 | }
|
6016 |
|
6017 | function argDefined(key, arg) {
|
6018 | return flags.allBools && /^--[^=]+$/.test(arg) || flags.strings[key] || flags.bools[key] || aliases[key];
|
6019 | }
|
6020 |
|
6021 | function setArg(key, val, arg) {
|
6022 | if (arg && flags.unknownFn && !argDefined(key, arg)) {
|
6023 | if (flags.unknownFn(arg) === false) return;
|
6024 | }
|
6025 |
|
6026 | var value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
|
6027 | setKey(argv, key.split('.'), value);
|
6028 | (aliases[key] || []).forEach(function (x) {
|
6029 | setKey(argv, x.split('.'), value);
|
6030 | });
|
6031 | }
|
6032 |
|
6033 | function setKey(obj, keys, value) {
|
6034 | var o = obj;
|
6035 |
|
6036 | for (var i = 0; i < keys.length - 1; i++) {
|
6037 | var key = keys[i];
|
6038 | if (key === '__proto__') return;
|
6039 | if (o[key] === undefined) o[key] = {};
|
6040 | if (o[key] === Object.prototype || o[key] === Number.prototype || o[key] === String.prototype) o[key] = {};
|
6041 | if (o[key] === Array.prototype) o[key] = [];
|
6042 | o = o[key];
|
6043 | }
|
6044 |
|
6045 | var key = keys[keys.length - 1];
|
6046 | if (key === '__proto__') return;
|
6047 | if (o === Object.prototype || o === Number.prototype || o === String.prototype) o = {};
|
6048 | if (o === Array.prototype) o = [];
|
6049 |
|
6050 | if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
|
6051 | o[key] = value;
|
6052 | } else if (Array.isArray(o[key])) {
|
6053 | o[key].push(value);
|
6054 | } else {
|
6055 | o[key] = [o[key], value];
|
6056 | }
|
6057 | }
|
6058 |
|
6059 | function aliasIsBoolean(key) {
|
6060 | return aliases[key].some(function (x) {
|
6061 | return flags.bools[x];
|
6062 | });
|
6063 | }
|
6064 |
|
6065 | for (var i = 0; i < args.length; i++) {
|
6066 | var arg = args[i];
|
6067 |
|
6068 | if (/^--.+=/.test(arg)) {
|
6069 |
|
6070 |
|
6071 |
|
6072 | var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
|
6073 | var key = m[1];
|
6074 | var value = m[2];
|
6075 |
|
6076 | if (flags.bools[key]) {
|
6077 | value = value !== 'false';
|
6078 | }
|
6079 |
|
6080 | setArg(key, value, arg);
|
6081 | } else if (/^--no-.+/.test(arg)) {
|
6082 | var key = arg.match(/^--no-(.+)/)[1];
|
6083 | setArg(key, false, arg);
|
6084 | } else if (/^--.+/.test(arg)) {
|
6085 | var key = arg.match(/^--(.+)/)[1];
|
6086 | var next = args[i + 1];
|
6087 |
|
6088 | if (next !== undefined && !/^-/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
6089 | setArg(key, next, arg);
|
6090 | i++;
|
6091 | } else if (/^(true|false)$/.test(next)) {
|
6092 | setArg(key, next === 'true', arg);
|
6093 | i++;
|
6094 | } else {
|
6095 | setArg(key, flags.strings[key] ? '' : true, arg);
|
6096 | }
|
6097 | } else if (/^-[^-]+/.test(arg)) {
|
6098 | var letters = arg.slice(1, -1).split('');
|
6099 | var broken = false;
|
6100 |
|
6101 | for (var j = 0; j < letters.length; j++) {
|
6102 | var next = arg.slice(j + 2);
|
6103 |
|
6104 | if (next === '-') {
|
6105 | setArg(letters[j], next, arg);
|
6106 | continue;
|
6107 | }
|
6108 |
|
6109 | if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
|
6110 | setArg(letters[j], next.split('=')[1], arg);
|
6111 | broken = true;
|
6112 | break;
|
6113 | }
|
6114 |
|
6115 | if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
|
6116 | setArg(letters[j], next, arg);
|
6117 | broken = true;
|
6118 | break;
|
6119 | }
|
6120 |
|
6121 | if (letters[j + 1] && letters[j + 1].match(/\W/)) {
|
6122 | setArg(letters[j], arg.slice(j + 2), arg);
|
6123 | broken = true;
|
6124 | break;
|
6125 | } else {
|
6126 | setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
|
6127 | }
|
6128 | }
|
6129 |
|
6130 | var key = arg.slice(-1)[0];
|
6131 |
|
6132 | if (!broken && key !== '-') {
|
6133 | if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
|
6134 | setArg(key, args[i + 1], arg);
|
6135 | i++;
|
6136 | } else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
|
6137 | setArg(key, args[i + 1] === 'true', arg);
|
6138 | i++;
|
6139 | } else {
|
6140 | setArg(key, flags.strings[key] ? '' : true, arg);
|
6141 | }
|
6142 | }
|
6143 | } else {
|
6144 | if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
|
6145 | argv._.push(flags.strings['_'] || !isNumber(arg) ? arg : Number(arg));
|
6146 | }
|
6147 |
|
6148 | if (opts.stopEarly) {
|
6149 | argv._.push.apply(argv._, args.slice(i + 1));
|
6150 |
|
6151 | break;
|
6152 | }
|
6153 | }
|
6154 | }
|
6155 |
|
6156 | Object.keys(defaults).forEach(function (key) {
|
6157 | if (!hasKey(argv, key.split('.'))) {
|
6158 | setKey(argv, key.split('.'), defaults[key]);
|
6159 | (aliases[key] || []).forEach(function (x) {
|
6160 | setKey(argv, x.split('.'), defaults[key]);
|
6161 | });
|
6162 | }
|
6163 | });
|
6164 |
|
6165 | if (opts['--']) {
|
6166 | argv['--'] = new Array();
|
6167 | notFlags.forEach(function (key) {
|
6168 | argv['--'].push(key);
|
6169 | });
|
6170 | } else {
|
6171 | notFlags.forEach(function (key) {
|
6172 | argv._.push(key);
|
6173 | });
|
6174 | }
|
6175 |
|
6176 | return argv;
|
6177 | };
|
6178 |
|
6179 | function hasKey(obj, keys) {
|
6180 | var o = obj;
|
6181 | keys.slice(0, -1).forEach(function (key) {
|
6182 | o = o[key] || {};
|
6183 | });
|
6184 | var key = keys[keys.length - 1];
|
6185 | return key in o;
|
6186 | }
|
6187 |
|
6188 | function isNumber(x) {
|
6189 | if (typeof x === 'number') return true;
|
6190 | if (/^0x[0-9a-f]+$/i.test(x)) return true;
|
6191 | return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
|
6192 | }
|
6193 |
|
6194 | const PLACEHOLDER = null;
|
6195 |
|
6196 |
|
6197 |
|
6198 |
|
6199 | var minimist_1 = function (args, options) {
|
6200 | const boolean = options.boolean || [];
|
6201 | const defaults = options.default || {};
|
6202 | const booleanWithoutDefault = boolean.filter(key => !(key in defaults));
|
6203 | const newDefaults = Object.assign({}, defaults, fromPairs_1(booleanWithoutDefault.map(key => [key, PLACEHOLDER])));
|
6204 | const parsed = minimist(args, Object.assign({}, options, {
|
6205 | default: newDefaults
|
6206 | }));
|
6207 | return fromPairs_1(Object.entries(parsed).filter(([, value]) => value !== PLACEHOLDER));
|
6208 | };
|
6209 |
|
6210 | var array = createCommonjsModule(function (module, exports) {
|
6211 |
|
6212 | Object.defineProperty(exports, "__esModule", {
|
6213 | value: true
|
6214 | });
|
6215 | exports.splitWhen = exports.flatten = void 0;
|
6216 |
|
6217 | function flatten(items) {
|
6218 | return items.reduce((collection, item) => [].concat(collection, item), []);
|
6219 | }
|
6220 |
|
6221 | exports.flatten = flatten;
|
6222 |
|
6223 | function splitWhen(items, predicate) {
|
6224 | const result = [[]];
|
6225 | let groupIndex = 0;
|
6226 |
|
6227 | for (const item of items) {
|
6228 | if (predicate(item)) {
|
6229 | groupIndex++;
|
6230 | result[groupIndex] = [];
|
6231 | } else {
|
6232 | result[groupIndex].push(item);
|
6233 | }
|
6234 | }
|
6235 |
|
6236 | return result;
|
6237 | }
|
6238 |
|
6239 | exports.splitWhen = splitWhen;
|
6240 | });
|
6241 |
|
6242 | var errno = createCommonjsModule(function (module, exports) {
|
6243 |
|
6244 | Object.defineProperty(exports, "__esModule", {
|
6245 | value: true
|
6246 | });
|
6247 | exports.isEnoentCodeError = void 0;
|
6248 |
|
6249 | function isEnoentCodeError(error) {
|
6250 | return error.code === 'ENOENT';
|
6251 | }
|
6252 |
|
6253 | exports.isEnoentCodeError = isEnoentCodeError;
|
6254 | });
|
6255 |
|
6256 | var fs = createCommonjsModule(function (module, exports) {
|
6257 |
|
6258 | Object.defineProperty(exports, "__esModule", {
|
6259 | value: true
|
6260 | });
|
6261 | exports.createDirentFromStats = void 0;
|
6262 |
|
6263 | class DirentFromStats {
|
6264 | constructor(name, stats) {
|
6265 | this.name = name;
|
6266 | this.isBlockDevice = stats.isBlockDevice.bind(stats);
|
6267 | this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
|
6268 | this.isDirectory = stats.isDirectory.bind(stats);
|
6269 | this.isFIFO = stats.isFIFO.bind(stats);
|
6270 | this.isFile = stats.isFile.bind(stats);
|
6271 | this.isSocket = stats.isSocket.bind(stats);
|
6272 | this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
|
6273 | }
|
6274 |
|
6275 | }
|
6276 |
|
6277 | function createDirentFromStats(name, stats) {
|
6278 | return new DirentFromStats(name, stats);
|
6279 | }
|
6280 |
|
6281 | exports.createDirentFromStats = createDirentFromStats;
|
6282 | });
|
6283 |
|
6284 | var path_1 = createCommonjsModule(function (module, exports) {
|
6285 |
|
6286 | Object.defineProperty(exports, "__esModule", {
|
6287 | value: true
|
6288 | });
|
6289 | exports.removeLeadingDotSegment = exports.escape = exports.makeAbsolute = exports.unixify = void 0;
|
6290 | const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2;
|
6291 |
|
6292 | const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
|
6293 | |
6294 |
|
6295 |
|
6296 |
|
6297 | function unixify(filepath) {
|
6298 | return filepath.replace(/\\/g, '/');
|
6299 | }
|
6300 |
|
6301 | exports.unixify = unixify;
|
6302 |
|
6303 | function makeAbsolute(cwd, filepath) {
|
6304 | return path__default['default'].resolve(cwd, filepath);
|
6305 | }
|
6306 |
|
6307 | exports.makeAbsolute = makeAbsolute;
|
6308 |
|
6309 | function escape(pattern) {
|
6310 | return pattern.replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
|
6311 | }
|
6312 |
|
6313 | exports.escape = escape;
|
6314 |
|
6315 | function removeLeadingDotSegment(entry) {
|
6316 |
|
6317 |
|
6318 | if (entry.charAt(0) === '.') {
|
6319 | const secondCharactery = entry.charAt(1);
|
6320 |
|
6321 | if (secondCharactery === '/' || secondCharactery === '\\') {
|
6322 | return entry.slice(LEADING_DOT_SEGMENT_CHARACTERS_COUNT);
|
6323 | }
|
6324 | }
|
6325 |
|
6326 | return entry;
|
6327 | }
|
6328 |
|
6329 | exports.removeLeadingDotSegment = removeLeadingDotSegment;
|
6330 | });
|
6331 |
|
6332 |
|
6333 |
|
6334 |
|
6335 |
|
6336 |
|
6337 |
|
6338 | var isExtglob = function isExtglob(str) {
|
6339 | if (typeof str !== 'string' || str === '') {
|
6340 | return false;
|
6341 | }
|
6342 |
|
6343 | var match;
|
6344 |
|
6345 | while (match = /(\\).|([@?!+*]\(.*\))/g.exec(str)) {
|
6346 | if (match[2]) return true;
|
6347 | str = str.slice(match.index + match[0].length);
|
6348 | }
|
6349 |
|
6350 | return false;
|
6351 | };
|
6352 |
|
6353 |
|
6354 |
|
6355 |
|
6356 |
|
6357 |
|
6358 |
|
6359 |
|
6360 | var chars = {
|
6361 | '{': '}',
|
6362 | '(': ')',
|
6363 | '[': ']'
|
6364 | };
|
6365 | var strictRegex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
|
6366 | var relaxedRegex = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
|
6367 |
|
6368 | var isGlob = function isGlob(str, options) {
|
6369 | if (typeof str !== 'string' || str === '') {
|
6370 | return false;
|
6371 | }
|
6372 |
|
6373 | if (isExtglob(str)) {
|
6374 | return true;
|
6375 | }
|
6376 |
|
6377 | var regex = strictRegex;
|
6378 | var match;
|
6379 |
|
6380 | if (options && options.strict === false) {
|
6381 | regex = relaxedRegex;
|
6382 | }
|
6383 |
|
6384 | while (match = regex.exec(str)) {
|
6385 | if (match[2]) return true;
|
6386 | var idx = match.index + match[0].length;
|
6387 |
|
6388 |
|
6389 | var open = match[1];
|
6390 | var close = open ? chars[open] : null;
|
6391 |
|
6392 | if (open && close) {
|
6393 | var n = str.indexOf(close, idx);
|
6394 |
|
6395 | if (n !== -1) {
|
6396 | idx = n + 1;
|
6397 | }
|
6398 | }
|
6399 |
|
6400 | str = str.slice(idx);
|
6401 | }
|
6402 |
|
6403 | return false;
|
6404 | };
|
6405 |
|
6406 | var pathPosixDirname = path__default['default'].posix.dirname;
|
6407 | var isWin32 = os__default['default'].platform() === 'win32';
|
6408 | var slash = '/';
|
6409 | var backslash = /\\/g;
|
6410 | var enclosure = /[\{\[].*[\/]*.*[\}\]]$/;
|
6411 | var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
|
6412 | var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
|
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 | var globParent = function globParent(str, opts) {
|
6420 | var options = Object.assign({
|
6421 | flipBackslashes: true
|
6422 | }, opts);
|
6423 |
|
6424 | if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
|
6425 | str = str.replace(backslash, slash);
|
6426 | }
|
6427 |
|
6428 |
|
6429 | if (enclosure.test(str)) {
|
6430 | str += slash;
|
6431 | }
|
6432 |
|
6433 |
|
6434 | str += 'a';
|
6435 |
|
6436 | do {
|
6437 | str = pathPosixDirname(str);
|
6438 | } while (isGlob(str) || globby.test(str));
|
6439 |
|
6440 |
|
6441 | return str.replace(escaped, '$1');
|
6442 | };
|
6443 |
|
6444 | var utils = createCommonjsModule(function (module, exports) {
|
6445 |
|
6446 | exports.isInteger = num => {
|
6447 | if (typeof num === 'number') {
|
6448 | return Number.isInteger(num);
|
6449 | }
|
6450 |
|
6451 | if (typeof num === 'string' && num.trim() !== '') {
|
6452 | return Number.isInteger(Number(num));
|
6453 | }
|
6454 |
|
6455 | return false;
|
6456 | };
|
6457 | |
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 | exports.find = (node, type) => node.nodes.find(node => node.type === type);
|
6463 | |
6464 |
|
6465 |
|
6466 |
|
6467 |
|
6468 | exports.exceedsLimit = (min, max, step = 1, limit) => {
|
6469 | if (limit === false) return false;
|
6470 | if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
|
6471 | return (Number(max) - Number(min)) / Number(step) >= limit;
|
6472 | };
|
6473 | |
6474 |
|
6475 |
|
6476 |
|
6477 |
|
6478 | exports.escapeNode = (block, n = 0, type) => {
|
6479 | let node = block.nodes[n];
|
6480 | if (!node) return;
|
6481 |
|
6482 | if (type && node.type === type || node.type === 'open' || node.type === 'close') {
|
6483 | if (node.escaped !== true) {
|
6484 | node.value = '\\' + node.value;
|
6485 | node.escaped = true;
|
6486 | }
|
6487 | }
|
6488 | };
|
6489 | |
6490 |
|
6491 |
|
6492 |
|
6493 |
|
6494 | exports.encloseBrace = node => {
|
6495 | if (node.type !== 'brace') return false;
|
6496 |
|
6497 | if (node.commas >> 0 + node.ranges >> 0 === 0) {
|
6498 | node.invalid = true;
|
6499 | return true;
|
6500 | }
|
6501 |
|
6502 | return false;
|
6503 | };
|
6504 | |
6505 |
|
6506 |
|
6507 |
|
6508 |
|
6509 | exports.isInvalidBrace = block => {
|
6510 | if (block.type !== 'brace') return false;
|
6511 | if (block.invalid === true || block.dollar) return true;
|
6512 |
|
6513 | if (block.commas >> 0 + block.ranges >> 0 === 0) {
|
6514 | block.invalid = true;
|
6515 | return true;
|
6516 | }
|
6517 |
|
6518 | if (block.open !== true || block.close !== true) {
|
6519 | block.invalid = true;
|
6520 | return true;
|
6521 | }
|
6522 |
|
6523 | return false;
|
6524 | };
|
6525 | |
6526 |
|
6527 |
|
6528 |
|
6529 |
|
6530 | exports.isOpenOrClose = node => {
|
6531 | if (node.type === 'open' || node.type === 'close') {
|
6532 | return true;
|
6533 | }
|
6534 |
|
6535 | return node.open === true || node.close === true;
|
6536 | };
|
6537 | |
6538 |
|
6539 |
|
6540 |
|
6541 |
|
6542 | exports.reduce = nodes => nodes.reduce((acc, node) => {
|
6543 | if (node.type === 'text') acc.push(node.value);
|
6544 | if (node.type === 'range') node.type = 'text';
|
6545 | return acc;
|
6546 | }, []);
|
6547 | |
6548 |
|
6549 |
|
6550 |
|
6551 |
|
6552 | exports.flatten = (...args) => {
|
6553 | const result = [];
|
6554 |
|
6555 | const flat = arr => {
|
6556 | for (let i = 0; i < arr.length; i++) {
|
6557 | let ele = arr[i];
|
6558 | Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
|
6559 | }
|
6560 |
|
6561 | return result;
|
6562 | };
|
6563 |
|
6564 | flat(args);
|
6565 | return result;
|
6566 | };
|
6567 | });
|
6568 |
|
6569 | var stringify = (ast, options = {}) => {
|
6570 | let stringify = (node, parent = {}) => {
|
6571 | let invalidBlock = options.escapeInvalid && utils.isInvalidBrace(parent);
|
6572 | let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
6573 | let output = '';
|
6574 |
|
6575 | if (node.value) {
|
6576 | if ((invalidBlock || invalidNode) && utils.isOpenOrClose(node)) {
|
6577 | return '\\' + node.value;
|
6578 | }
|
6579 |
|
6580 | return node.value;
|
6581 | }
|
6582 |
|
6583 | if (node.value) {
|
6584 | return node.value;
|
6585 | }
|
6586 |
|
6587 | if (node.nodes) {
|
6588 | for (let child of node.nodes) {
|
6589 | output += stringify(child);
|
6590 | }
|
6591 | }
|
6592 |
|
6593 | return output;
|
6594 | };
|
6595 |
|
6596 | return stringify(ast);
|
6597 | };
|
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 | var isNumber$1 = function (num) {
|
6607 | if (typeof num === 'number') {
|
6608 | return num - num === 0;
|
6609 | }
|
6610 |
|
6611 | if (typeof num === 'string' && num.trim() !== '') {
|
6612 | return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
|
6613 | }
|
6614 |
|
6615 | return false;
|
6616 | };
|
6617 |
|
6618 | const toRegexRange = (min, max, options) => {
|
6619 | if (isNumber$1(min) === false) {
|
6620 | throw new TypeError('toRegexRange: expected the first argument to be a number');
|
6621 | }
|
6622 |
|
6623 | if (max === void 0 || min === max) {
|
6624 | return String(min);
|
6625 | }
|
6626 |
|
6627 | if (isNumber$1(max) === false) {
|
6628 | throw new TypeError('toRegexRange: expected the second argument to be a number.');
|
6629 | }
|
6630 |
|
6631 | let opts = Object.assign({
|
6632 | relaxZeros: true
|
6633 | }, options);
|
6634 |
|
6635 | if (typeof opts.strictZeros === 'boolean') {
|
6636 | opts.relaxZeros = opts.strictZeros === false;
|
6637 | }
|
6638 |
|
6639 | let relax = String(opts.relaxZeros);
|
6640 | let shorthand = String(opts.shorthand);
|
6641 | let capture = String(opts.capture);
|
6642 | let wrap = String(opts.wrap);
|
6643 | let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
|
6644 |
|
6645 | if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
|
6646 | return toRegexRange.cache[cacheKey].result;
|
6647 | }
|
6648 |
|
6649 | let a = Math.min(min, max);
|
6650 | let b = Math.max(min, max);
|
6651 |
|
6652 | if (Math.abs(a - b) === 1) {
|
6653 | let result = min + '|' + max;
|
6654 |
|
6655 | if (opts.capture) {
|
6656 | return `(${result})`;
|
6657 | }
|
6658 |
|
6659 | if (opts.wrap === false) {
|
6660 | return result;
|
6661 | }
|
6662 |
|
6663 | return `(?:${result})`;
|
6664 | }
|
6665 |
|
6666 | let isPadded = hasPadding(min) || hasPadding(max);
|
6667 | let state = {
|
6668 | min,
|
6669 | max,
|
6670 | a,
|
6671 | b
|
6672 | };
|
6673 | let positives = [];
|
6674 | let negatives = [];
|
6675 |
|
6676 | if (isPadded) {
|
6677 | state.isPadded = isPadded;
|
6678 | state.maxLen = String(state.max).length;
|
6679 | }
|
6680 |
|
6681 | if (a < 0) {
|
6682 | let newMin = b < 0 ? Math.abs(b) : 1;
|
6683 | negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
|
6684 | a = state.a = 0;
|
6685 | }
|
6686 |
|
6687 | if (b >= 0) {
|
6688 | positives = splitToPatterns(a, b, state, opts);
|
6689 | }
|
6690 |
|
6691 | state.negatives = negatives;
|
6692 | state.positives = positives;
|
6693 | state.result = collatePatterns(negatives, positives);
|
6694 |
|
6695 | if (opts.capture === true) {
|
6696 | state.result = `(${state.result})`;
|
6697 | } else if (opts.wrap !== false && positives.length + negatives.length > 1) {
|
6698 | state.result = `(?:${state.result})`;
|
6699 | }
|
6700 |
|
6701 | toRegexRange.cache[cacheKey] = state;
|
6702 | return state.result;
|
6703 | };
|
6704 |
|
6705 | function collatePatterns(neg, pos, options) {
|
6706 | let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
|
6707 | let onlyPositive = filterPatterns(pos, neg, '', false) || [];
|
6708 | let intersected = filterPatterns(neg, pos, '-?', true) || [];
|
6709 | let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
|
6710 | return subpatterns.join('|');
|
6711 | }
|
6712 |
|
6713 | function splitToRanges(min, max) {
|
6714 | let nines = 1;
|
6715 | let zeros = 1;
|
6716 | let stop = countNines(min, nines);
|
6717 | let stops = new Set([max]);
|
6718 |
|
6719 | while (min <= stop && stop <= max) {
|
6720 | stops.add(stop);
|
6721 | nines += 1;
|
6722 | stop = countNines(min, nines);
|
6723 | }
|
6724 |
|
6725 | stop = countZeros(max + 1, zeros) - 1;
|
6726 |
|
6727 | while (min < stop && stop <= max) {
|
6728 | stops.add(stop);
|
6729 | zeros += 1;
|
6730 | stop = countZeros(max + 1, zeros) - 1;
|
6731 | }
|
6732 |
|
6733 | stops = [...stops];
|
6734 | stops.sort(compare);
|
6735 | return stops;
|
6736 | }
|
6737 |
|
6738 |
|
6739 |
|
6740 |
|
6741 |
|
6742 |
|
6743 |
|
6744 |
|
6745 | function rangeToPattern(start, stop, options) {
|
6746 | if (start === stop) {
|
6747 | return {
|
6748 | pattern: start,
|
6749 | count: [],
|
6750 | digits: 0
|
6751 | };
|
6752 | }
|
6753 |
|
6754 | let zipped = zip(start, stop);
|
6755 | let digits = zipped.length;
|
6756 | let pattern = '';
|
6757 | let count = 0;
|
6758 |
|
6759 | for (let i = 0; i < digits; i++) {
|
6760 | let [startDigit, stopDigit] = zipped[i];
|
6761 |
|
6762 | if (startDigit === stopDigit) {
|
6763 | pattern += startDigit;
|
6764 | } else if (startDigit !== '0' || stopDigit !== '9') {
|
6765 | pattern += toCharacterClass(startDigit, stopDigit);
|
6766 | } else {
|
6767 | count++;
|
6768 | }
|
6769 | }
|
6770 |
|
6771 | if (count) {
|
6772 | pattern += options.shorthand === true ? '\\d' : '[0-9]';
|
6773 | }
|
6774 |
|
6775 | return {
|
6776 | pattern,
|
6777 | count: [count],
|
6778 | digits
|
6779 | };
|
6780 | }
|
6781 |
|
6782 | function splitToPatterns(min, max, tok, options) {
|
6783 | let ranges = splitToRanges(min, max);
|
6784 | let tokens = [];
|
6785 | let start = min;
|
6786 | let prev;
|
6787 |
|
6788 | for (let i = 0; i < ranges.length; i++) {
|
6789 | let max = ranges[i];
|
6790 | let obj = rangeToPattern(String(start), String(max), options);
|
6791 | let zeros = '';
|
6792 |
|
6793 | if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
|
6794 | if (prev.count.length > 1) {
|
6795 | prev.count.pop();
|
6796 | }
|
6797 |
|
6798 | prev.count.push(obj.count[0]);
|
6799 | prev.string = prev.pattern + toQuantifier(prev.count);
|
6800 | start = max + 1;
|
6801 | continue;
|
6802 | }
|
6803 |
|
6804 | if (tok.isPadded) {
|
6805 | zeros = padZeros(max, tok, options);
|
6806 | }
|
6807 |
|
6808 | obj.string = zeros + obj.pattern + toQuantifier(obj.count);
|
6809 | tokens.push(obj);
|
6810 | start = max + 1;
|
6811 | prev = obj;
|
6812 | }
|
6813 |
|
6814 | return tokens;
|
6815 | }
|
6816 |
|
6817 | function filterPatterns(arr, comparison, prefix, intersection, options) {
|
6818 | let result = [];
|
6819 |
|
6820 | for (let ele of arr) {
|
6821 | let {
|
6822 | string
|
6823 | } = ele;
|
6824 |
|
6825 | if (!intersection && !contains(comparison, 'string', string)) {
|
6826 | result.push(prefix + string);
|
6827 | }
|
6828 |
|
6829 |
|
6830 | if (intersection && contains(comparison, 'string', string)) {
|
6831 | result.push(prefix + string);
|
6832 | }
|
6833 | }
|
6834 |
|
6835 | return result;
|
6836 | }
|
6837 |
|
6838 |
|
6839 |
|
6840 |
|
6841 |
|
6842 | function zip(a, b) {
|
6843 | let arr = [];
|
6844 |
|
6845 | for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
|
6846 |
|
6847 | return arr;
|
6848 | }
|
6849 |
|
6850 | function compare(a, b) {
|
6851 | return a > b ? 1 : b > a ? -1 : 0;
|
6852 | }
|
6853 |
|
6854 | function contains(arr, key, val) {
|
6855 | return arr.some(ele => ele[key] === val);
|
6856 | }
|
6857 |
|
6858 | function countNines(min, len) {
|
6859 | return Number(String(min).slice(0, -len) + '9'.repeat(len));
|
6860 | }
|
6861 |
|
6862 | function countZeros(integer, zeros) {
|
6863 | return integer - integer % Math.pow(10, zeros);
|
6864 | }
|
6865 |
|
6866 | function toQuantifier(digits) {
|
6867 | let [start = 0, stop = ''] = digits;
|
6868 |
|
6869 | if (stop || start > 1) {
|
6870 | return `{${start + (stop ? ',' + stop : '')}}`;
|
6871 | }
|
6872 |
|
6873 | return '';
|
6874 | }
|
6875 |
|
6876 | function toCharacterClass(a, b, options) {
|
6877 | return `[${a}${b - a === 1 ? '' : '-'}${b}]`;
|
6878 | }
|
6879 |
|
6880 | function hasPadding(str) {
|
6881 | return /^-?(0+)\d/.test(str);
|
6882 | }
|
6883 |
|
6884 | function padZeros(value, tok, options) {
|
6885 | if (!tok.isPadded) {
|
6886 | return value;
|
6887 | }
|
6888 |
|
6889 | let diff = Math.abs(tok.maxLen - String(value).length);
|
6890 | let relax = options.relaxZeros !== false;
|
6891 |
|
6892 | switch (diff) {
|
6893 | case 0:
|
6894 | return '';
|
6895 |
|
6896 | case 1:
|
6897 | return relax ? '0?' : '0';
|
6898 |
|
6899 | case 2:
|
6900 | return relax ? '0{0,2}' : '00';
|
6901 |
|
6902 | default:
|
6903 | {
|
6904 | return relax ? `0{0,${diff}}` : `0{${diff}}`;
|
6905 | }
|
6906 | }
|
6907 | }
|
6908 |
|
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 | toRegexRange.cache = {};
|
6914 |
|
6915 | toRegexRange.clearCache = () => toRegexRange.cache = {};
|
6916 |
|
6917 |
|
6918 |
|
6919 |
|
6920 |
|
6921 | var toRegexRange_1 = toRegexRange;
|
6922 |
|
6923 | const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
6924 |
|
6925 | const transform = toNumber => {
|
6926 | return value => toNumber === true ? Number(value) : String(value);
|
6927 | };
|
6928 |
|
6929 | const isValidValue = value => {
|
6930 | return typeof value === 'number' || typeof value === 'string' && value !== '';
|
6931 | };
|
6932 |
|
6933 | const isNumber$2 = num => Number.isInteger(+num);
|
6934 |
|
6935 | const zeros = input => {
|
6936 | let value = `${input}`;
|
6937 | let index = -1;
|
6938 | if (value[0] === '-') value = value.slice(1);
|
6939 | if (value === '0') return false;
|
6940 |
|
6941 | while (value[++index] === '0');
|
6942 |
|
6943 | return index > 0;
|
6944 | };
|
6945 |
|
6946 | const stringify$1 = (start, end, options) => {
|
6947 | if (typeof start === 'string' || typeof end === 'string') {
|
6948 | return true;
|
6949 | }
|
6950 |
|
6951 | return options.stringify === true;
|
6952 | };
|
6953 |
|
6954 | const pad = (input, maxLength, toNumber) => {
|
6955 | if (maxLength > 0) {
|
6956 | let dash = input[0] === '-' ? '-' : '';
|
6957 | if (dash) input = input.slice(1);
|
6958 | input = dash + input.padStart(dash ? maxLength - 1 : maxLength, '0');
|
6959 | }
|
6960 |
|
6961 | if (toNumber === false) {
|
6962 | return String(input);
|
6963 | }
|
6964 |
|
6965 | return input;
|
6966 | };
|
6967 |
|
6968 | const toMaxLen = (input, maxLength) => {
|
6969 | let negative = input[0] === '-' ? '-' : '';
|
6970 |
|
6971 | if (negative) {
|
6972 | input = input.slice(1);
|
6973 | maxLength--;
|
6974 | }
|
6975 |
|
6976 | while (input.length < maxLength) input = '0' + input;
|
6977 |
|
6978 | return negative ? '-' + input : input;
|
6979 | };
|
6980 |
|
6981 | const toSequence = (parts, options) => {
|
6982 | parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
6983 | parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
6984 | let prefix = options.capture ? '' : '?:';
|
6985 | let positives = '';
|
6986 | let negatives = '';
|
6987 | let result;
|
6988 |
|
6989 | if (parts.positives.length) {
|
6990 | positives = parts.positives.join('|');
|
6991 | }
|
6992 |
|
6993 | if (parts.negatives.length) {
|
6994 | negatives = `-(${prefix}${parts.negatives.join('|')})`;
|
6995 | }
|
6996 |
|
6997 | if (positives && negatives) {
|
6998 | result = `${positives}|${negatives}`;
|
6999 | } else {
|
7000 | result = positives || negatives;
|
7001 | }
|
7002 |
|
7003 | if (options.wrap) {
|
7004 | return `(${prefix}${result})`;
|
7005 | }
|
7006 |
|
7007 | return result;
|
7008 | };
|
7009 |
|
7010 | const toRange = (a, b, isNumbers, options) => {
|
7011 | if (isNumbers) {
|
7012 | return toRegexRange_1(a, b, Object.assign({
|
7013 | wrap: false
|
7014 | }, options));
|
7015 | }
|
7016 |
|
7017 | let start = String.fromCharCode(a);
|
7018 | if (a === b) return start;
|
7019 | let stop = String.fromCharCode(b);
|
7020 | return `[${start}-${stop}]`;
|
7021 | };
|
7022 |
|
7023 | const toRegex = (start, end, options) => {
|
7024 | if (Array.isArray(start)) {
|
7025 | let wrap = options.wrap === true;
|
7026 | let prefix = options.capture ? '' : '?:';
|
7027 | return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
|
7028 | }
|
7029 |
|
7030 | return toRegexRange_1(start, end, options);
|
7031 | };
|
7032 |
|
7033 | const rangeError = (...args) => {
|
7034 | return new RangeError('Invalid range arguments: ' + util__default['default'].inspect(...args));
|
7035 | };
|
7036 |
|
7037 | const invalidRange = (start, end, options) => {
|
7038 | if (options.strictRanges === true) throw rangeError([start, end]);
|
7039 | return [];
|
7040 | };
|
7041 |
|
7042 | const invalidStep = (step, options) => {
|
7043 | if (options.strictRanges === true) {
|
7044 | throw new TypeError(`Expected step "${step}" to be a number`);
|
7045 | }
|
7046 |
|
7047 | return [];
|
7048 | };
|
7049 |
|
7050 | const fillNumbers = (start, end, step = 1, options = {}) => {
|
7051 | let a = Number(start);
|
7052 | let b = Number(end);
|
7053 |
|
7054 | if (!Number.isInteger(a) || !Number.isInteger(b)) {
|
7055 | if (options.strictRanges === true) throw rangeError([start, end]);
|
7056 | return [];
|
7057 | }
|
7058 |
|
7059 |
|
7060 | if (a === 0) a = 0;
|
7061 | if (b === 0) b = 0;
|
7062 | let descending = a > b;
|
7063 | let startString = String(start);
|
7064 | let endString = String(end);
|
7065 | let stepString = String(step);
|
7066 | step = Math.max(Math.abs(step), 1);
|
7067 | let padded = zeros(startString) || zeros(endString) || zeros(stepString);
|
7068 | let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
|
7069 | let toNumber = padded === false && stringify$1(start, end, options) === false;
|
7070 | let format = options.transform || transform(toNumber);
|
7071 |
|
7072 | if (options.toRegex && step === 1) {
|
7073 | return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
|
7074 | }
|
7075 |
|
7076 | let parts = {
|
7077 | negatives: [],
|
7078 | positives: []
|
7079 | };
|
7080 |
|
7081 | let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
|
7082 |
|
7083 | let range = [];
|
7084 | let index = 0;
|
7085 |
|
7086 | while (descending ? a >= b : a <= b) {
|
7087 | if (options.toRegex === true && step > 1) {
|
7088 | push(a);
|
7089 | } else {
|
7090 | range.push(pad(format(a, index), maxLen, toNumber));
|
7091 | }
|
7092 |
|
7093 | a = descending ? a - step : a + step;
|
7094 | index++;
|
7095 | }
|
7096 |
|
7097 | if (options.toRegex === true) {
|
7098 | return step > 1 ? toSequence(parts, options) : toRegex(range, null, Object.assign({
|
7099 | wrap: false
|
7100 | }, options));
|
7101 | }
|
7102 |
|
7103 | return range;
|
7104 | };
|
7105 |
|
7106 | const fillLetters = (start, end, step = 1, options = {}) => {
|
7107 | if (!isNumber$2(start) && start.length > 1 || !isNumber$2(end) && end.length > 1) {
|
7108 | return invalidRange(start, end, options);
|
7109 | }
|
7110 |
|
7111 | let format = options.transform || (val => String.fromCharCode(val));
|
7112 |
|
7113 | let a = `${start}`.charCodeAt(0);
|
7114 | let b = `${end}`.charCodeAt(0);
|
7115 | let descending = a > b;
|
7116 | let min = Math.min(a, b);
|
7117 | let max = Math.max(a, b);
|
7118 |
|
7119 | if (options.toRegex && step === 1) {
|
7120 | return toRange(min, max, false, options);
|
7121 | }
|
7122 |
|
7123 | let range = [];
|
7124 | let index = 0;
|
7125 |
|
7126 | while (descending ? a >= b : a <= b) {
|
7127 | range.push(format(a, index));
|
7128 | a = descending ? a - step : a + step;
|
7129 | index++;
|
7130 | }
|
7131 |
|
7132 | if (options.toRegex === true) {
|
7133 | return toRegex(range, null, {
|
7134 | wrap: false,
|
7135 | options
|
7136 | });
|
7137 | }
|
7138 |
|
7139 | return range;
|
7140 | };
|
7141 |
|
7142 | const fill = (start, end, step, options = {}) => {
|
7143 | if (end == null && isValidValue(start)) {
|
7144 | return [start];
|
7145 | }
|
7146 |
|
7147 | if (!isValidValue(start) || !isValidValue(end)) {
|
7148 | return invalidRange(start, end, options);
|
7149 | }
|
7150 |
|
7151 | if (typeof step === 'function') {
|
7152 | return fill(start, end, 1, {
|
7153 | transform: step
|
7154 | });
|
7155 | }
|
7156 |
|
7157 | if (isObject$1(step)) {
|
7158 | return fill(start, end, 0, step);
|
7159 | }
|
7160 |
|
7161 | let opts = Object.assign({}, options);
|
7162 | if (opts.capture === true) opts.wrap = true;
|
7163 | step = step || opts.step || 1;
|
7164 |
|
7165 | if (!isNumber$2(step)) {
|
7166 | if (step != null && !isObject$1(step)) return invalidStep(step, opts);
|
7167 | return fill(start, end, 1, step);
|
7168 | }
|
7169 |
|
7170 | if (isNumber$2(start) && isNumber$2(end)) {
|
7171 | return fillNumbers(start, end, step, opts);
|
7172 | }
|
7173 |
|
7174 | return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
|
7175 | };
|
7176 |
|
7177 | var fillRange = fill;
|
7178 |
|
7179 | const compile = (ast, options = {}) => {
|
7180 | let walk = (node, parent = {}) => {
|
7181 | let invalidBlock = utils.isInvalidBrace(parent);
|
7182 | let invalidNode = node.invalid === true && options.escapeInvalid === true;
|
7183 | let invalid = invalidBlock === true || invalidNode === true;
|
7184 | let prefix = options.escapeInvalid === true ? '\\' : '';
|
7185 | let output = '';
|
7186 |
|
7187 | if (node.isOpen === true) {
|
7188 | return prefix + node.value;
|
7189 | }
|
7190 |
|
7191 | if (node.isClose === true) {
|
7192 | return prefix + node.value;
|
7193 | }
|
7194 |
|
7195 | if (node.type === 'open') {
|
7196 | return invalid ? prefix + node.value : '(';
|
7197 | }
|
7198 |
|
7199 | if (node.type === 'close') {
|
7200 | return invalid ? prefix + node.value : ')';
|
7201 | }
|
7202 |
|
7203 | if (node.type === 'comma') {
|
7204 | return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
|
7205 | }
|
7206 |
|
7207 | if (node.value) {
|
7208 | return node.value;
|
7209 | }
|
7210 |
|
7211 | if (node.nodes && node.ranges > 0) {
|
7212 | let args = utils.reduce(node.nodes);
|
7213 | let range = fillRange(...args, Object.assign({}, options, {
|
7214 | wrap: false,
|
7215 | toRegex: true
|
7216 | }));
|
7217 |
|
7218 | if (range.length !== 0) {
|
7219 | return args.length > 1 && range.length > 1 ? `(${range})` : range;
|
7220 | }
|
7221 | }
|
7222 |
|
7223 | if (node.nodes) {
|
7224 | for (let child of node.nodes) {
|
7225 | output += walk(child, node);
|
7226 | }
|
7227 | }
|
7228 |
|
7229 | return output;
|
7230 | };
|
7231 |
|
7232 | return walk(ast);
|
7233 | };
|
7234 |
|
7235 | var compile_1 = compile;
|
7236 |
|
7237 | const append = (queue = '', stash = '', enclose = false) => {
|
7238 | let result = [];
|
7239 | queue = [].concat(queue);
|
7240 | stash = [].concat(stash);
|
7241 | if (!stash.length) return queue;
|
7242 |
|
7243 | if (!queue.length) {
|
7244 | return enclose ? utils.flatten(stash).map(ele => `{${ele}}`) : stash;
|
7245 | }
|
7246 |
|
7247 | for (let item of queue) {
|
7248 | if (Array.isArray(item)) {
|
7249 | for (let value of item) {
|
7250 | result.push(append(value, stash, enclose));
|
7251 | }
|
7252 | } else {
|
7253 | for (let ele of stash) {
|
7254 | if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
|
7255 | result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
|
7256 | }
|
7257 | }
|
7258 | }
|
7259 |
|
7260 | return utils.flatten(result);
|
7261 | };
|
7262 |
|
7263 | const expand = (ast, options = {}) => {
|
7264 | let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
|
7265 |
|
7266 | let walk = (node, parent = {}) => {
|
7267 | node.queue = [];
|
7268 | let p = parent;
|
7269 | let q = parent.queue;
|
7270 |
|
7271 | while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
|
7272 | p = p.parent;
|
7273 | q = p.queue;
|
7274 | }
|
7275 |
|
7276 | if (node.invalid || node.dollar) {
|
7277 | q.push(append(q.pop(), stringify(node, options)));
|
7278 | return;
|
7279 | }
|
7280 |
|
7281 | if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
|
7282 | q.push(append(q.pop(), ['{}']));
|
7283 | return;
|
7284 | }
|
7285 |
|
7286 | if (node.nodes && node.ranges > 0) {
|
7287 | let args = utils.reduce(node.nodes);
|
7288 |
|
7289 | if (utils.exceedsLimit(...args, options.step, rangeLimit)) {
|
7290 | throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
|
7291 | }
|
7292 |
|
7293 | let range = fillRange(...args, options);
|
7294 |
|
7295 | if (range.length === 0) {
|
7296 | range = stringify(node, options);
|
7297 | }
|
7298 |
|
7299 | q.push(append(q.pop(), range));
|
7300 | node.nodes = [];
|
7301 | return;
|
7302 | }
|
7303 |
|
7304 | let enclose = utils.encloseBrace(node);
|
7305 | let queue = node.queue;
|
7306 | let block = node;
|
7307 |
|
7308 | while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
|
7309 | block = block.parent;
|
7310 | queue = block.queue;
|
7311 | }
|
7312 |
|
7313 | for (let i = 0; i < node.nodes.length; i++) {
|
7314 | let child = node.nodes[i];
|
7315 |
|
7316 | if (child.type === 'comma' && node.type === 'brace') {
|
7317 | if (i === 1) queue.push('');
|
7318 | queue.push('');
|
7319 | continue;
|
7320 | }
|
7321 |
|
7322 | if (child.type === 'close') {
|
7323 | q.push(append(q.pop(), queue, enclose));
|
7324 | continue;
|
7325 | }
|
7326 |
|
7327 | if (child.value && child.type !== 'open') {
|
7328 | queue.push(append(queue.pop(), child.value));
|
7329 | continue;
|
7330 | }
|
7331 |
|
7332 | if (child.nodes) {
|
7333 | walk(child, node);
|
7334 | }
|
7335 | }
|
7336 |
|
7337 | return queue;
|
7338 | };
|
7339 |
|
7340 | return utils.flatten(walk(ast));
|
7341 | };
|
7342 |
|
7343 | var expand_1 = expand;
|
7344 |
|
7345 | var constants = {
|
7346 | MAX_LENGTH: 1024 * 64,
|
7347 |
|
7348 | CHAR_0: '0',
|
7349 |
|
7350 |
|
7351 | CHAR_9: '9',
|
7352 |
|
7353 |
|
7354 |
|
7355 | CHAR_UPPERCASE_A: 'A',
|
7356 |
|
7357 |
|
7358 | CHAR_LOWERCASE_A: 'a',
|
7359 |
|
7360 |
|
7361 | CHAR_UPPERCASE_Z: 'Z',
|
7362 |
|
7363 |
|
7364 | CHAR_LOWERCASE_Z: 'z',
|
7365 |
|
7366 |
|
7367 | CHAR_LEFT_PARENTHESES: '(',
|
7368 |
|
7369 |
|
7370 | CHAR_RIGHT_PARENTHESES: ')',
|
7371 |
|
7372 |
|
7373 | CHAR_ASTERISK: '*',
|
7374 |
|
7375 |
|
7376 |
|
7377 | CHAR_AMPERSAND: '&',
|
7378 |
|
7379 |
|
7380 | CHAR_AT: '@',
|
7381 |
|
7382 |
|
7383 | CHAR_BACKSLASH: '\\',
|
7384 |
|
7385 |
|
7386 | CHAR_BACKTICK: '`',
|
7387 |
|
7388 |
|
7389 | CHAR_CARRIAGE_RETURN: '\r',
|
7390 |
|
7391 |
|
7392 | CHAR_CIRCUMFLEX_ACCENT: '^',
|
7393 |
|
7394 |
|
7395 | CHAR_COLON: ':',
|
7396 |
|
7397 |
|
7398 | CHAR_COMMA: ',',
|
7399 |
|
7400 |
|
7401 | CHAR_DOLLAR: '$',
|
7402 |
|
7403 |
|
7404 | CHAR_DOT: '.',
|
7405 |
|
7406 |
|
7407 | CHAR_DOUBLE_QUOTE: '"',
|
7408 |
|
7409 |
|
7410 | CHAR_EQUAL: '=',
|
7411 |
|
7412 |
|
7413 | CHAR_EXCLAMATION_MARK: '!',
|
7414 |
|
7415 |
|
7416 | CHAR_FORM_FEED: '\f',
|
7417 |
|
7418 |
|
7419 | CHAR_FORWARD_SLASH: '/',
|
7420 |
|
7421 |
|
7422 | CHAR_HASH: '#',
|
7423 |
|
7424 |
|
7425 | CHAR_HYPHEN_MINUS: '-',
|
7426 |
|
7427 |
|
7428 | CHAR_LEFT_ANGLE_BRACKET: '<',
|
7429 |
|
7430 |
|
7431 | CHAR_LEFT_CURLY_BRACE: '{',
|
7432 |
|
7433 |
|
7434 | CHAR_LEFT_SQUARE_BRACKET: '[',
|
7435 |
|
7436 |
|
7437 | CHAR_LINE_FEED: '\n',
|
7438 |
|
7439 |
|
7440 | CHAR_NO_BREAK_SPACE: '\u00A0',
|
7441 |
|
7442 |
|
7443 | CHAR_PERCENT: '%',
|
7444 |
|
7445 |
|
7446 | CHAR_PLUS: '+',
|
7447 |
|
7448 |
|
7449 | CHAR_QUESTION_MARK: '?',
|
7450 |
|
7451 |
|
7452 | CHAR_RIGHT_ANGLE_BRACKET: '>',
|
7453 |
|
7454 |
|
7455 | CHAR_RIGHT_CURLY_BRACE: '}',
|
7456 |
|
7457 |
|
7458 | CHAR_RIGHT_SQUARE_BRACKET: ']',
|
7459 |
|
7460 |
|
7461 | CHAR_SEMICOLON: ';',
|
7462 |
|
7463 |
|
7464 | CHAR_SINGLE_QUOTE: '\'',
|
7465 |
|
7466 |
|
7467 | CHAR_SPACE: ' ',
|
7468 |
|
7469 |
|
7470 | CHAR_TAB: '\t',
|
7471 |
|
7472 |
|
7473 | CHAR_UNDERSCORE: '_',
|
7474 |
|
7475 |
|
7476 | CHAR_VERTICAL_LINE: '|',
|
7477 |
|
7478 |
|
7479 | CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF'
|
7480 |
|
7481 |
|
7482 | };
|
7483 |
|
7484 |
|
7485 |
|
7486 |
|
7487 |
|
7488 |
|
7489 | const {
|
7490 | MAX_LENGTH,
|
7491 | CHAR_BACKSLASH,
|
7492 |
|
7493 |
|
7494 | CHAR_BACKTICK,
|
7495 |
|
7496 |
|
7497 | CHAR_COMMA,
|
7498 |
|
7499 |
|
7500 | CHAR_DOT,
|
7501 |
|
7502 |
|
7503 | CHAR_LEFT_PARENTHESES,
|
7504 |
|
7505 |
|
7506 | CHAR_RIGHT_PARENTHESES,
|
7507 |
|
7508 |
|
7509 | CHAR_LEFT_CURLY_BRACE,
|
7510 |
|
7511 |
|
7512 | CHAR_RIGHT_CURLY_BRACE,
|
7513 |
|
7514 |
|
7515 | CHAR_LEFT_SQUARE_BRACKET,
|
7516 |
|
7517 |
|
7518 | CHAR_RIGHT_SQUARE_BRACKET,
|
7519 |
|
7520 |
|
7521 | CHAR_DOUBLE_QUOTE,
|
7522 |
|
7523 |
|
7524 | CHAR_SINGLE_QUOTE,
|
7525 |
|
7526 |
|
7527 | CHAR_NO_BREAK_SPACE,
|
7528 | CHAR_ZERO_WIDTH_NOBREAK_SPACE
|
7529 | } = constants;
|
7530 |
|
7531 |
|
7532 |
|
7533 |
|
7534 | const parse = (input, options = {}) => {
|
7535 | if (typeof input !== 'string') {
|
7536 | throw new TypeError('Expected a string');
|
7537 | }
|
7538 |
|
7539 | let opts = options || {};
|
7540 | let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
7541 |
|
7542 | if (input.length > max) {
|
7543 | throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
|
7544 | }
|
7545 |
|
7546 | let ast = {
|
7547 | type: 'root',
|
7548 | input,
|
7549 | nodes: []
|
7550 | };
|
7551 | let stack = [ast];
|
7552 | let block = ast;
|
7553 | let prev = ast;
|
7554 | let brackets = 0;
|
7555 | let length = input.length;
|
7556 | let index = 0;
|
7557 | let depth = 0;
|
7558 | let value;
|
7559 | |
7560 |
|
7561 |
|
7562 |
|
7563 | const advance = () => input[index++];
|
7564 |
|
7565 | const push = node => {
|
7566 | if (node.type === 'text' && prev.type === 'dot') {
|
7567 | prev.type = 'text';
|
7568 | }
|
7569 |
|
7570 | if (prev && prev.type === 'text' && node.type === 'text') {
|
7571 | prev.value += node.value;
|
7572 | return;
|
7573 | }
|
7574 |
|
7575 | block.nodes.push(node);
|
7576 | node.parent = block;
|
7577 | node.prev = prev;
|
7578 | prev = node;
|
7579 | return node;
|
7580 | };
|
7581 |
|
7582 | push({
|
7583 | type: 'bos'
|
7584 | });
|
7585 |
|
7586 | while (index < length) {
|
7587 | block = stack[stack.length - 1];
|
7588 | value = advance();
|
7589 | |
7590 |
|
7591 |
|
7592 |
|
7593 | if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
|
7594 | continue;
|
7595 | }
|
7596 | |
7597 |
|
7598 |
|
7599 |
|
7600 |
|
7601 | if (value === CHAR_BACKSLASH) {
|
7602 | push({
|
7603 | type: 'text',
|
7604 | value: (options.keepEscaping ? value : '') + advance()
|
7605 | });
|
7606 | continue;
|
7607 | }
|
7608 | |
7609 |
|
7610 |
|
7611 |
|
7612 |
|
7613 | if (value === CHAR_RIGHT_SQUARE_BRACKET) {
|
7614 | push({
|
7615 | type: 'text',
|
7616 | value: '\\' + value
|
7617 | });
|
7618 | continue;
|
7619 | }
|
7620 | |
7621 |
|
7622 |
|
7623 |
|
7624 |
|
7625 | if (value === CHAR_LEFT_SQUARE_BRACKET) {
|
7626 | brackets++;
|
7627 | let next;
|
7628 |
|
7629 | while (index < length && (next = advance())) {
|
7630 | value += next;
|
7631 |
|
7632 | if (next === CHAR_LEFT_SQUARE_BRACKET) {
|
7633 | brackets++;
|
7634 | continue;
|
7635 | }
|
7636 |
|
7637 | if (next === CHAR_BACKSLASH) {
|
7638 | value += advance();
|
7639 | continue;
|
7640 | }
|
7641 |
|
7642 | if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
7643 | brackets--;
|
7644 |
|
7645 | if (brackets === 0) {
|
7646 | break;
|
7647 | }
|
7648 | }
|
7649 | }
|
7650 |
|
7651 | push({
|
7652 | type: 'text',
|
7653 | value
|
7654 | });
|
7655 | continue;
|
7656 | }
|
7657 | |
7658 |
|
7659 |
|
7660 |
|
7661 |
|
7662 | if (value === CHAR_LEFT_PARENTHESES) {
|
7663 | block = push({
|
7664 | type: 'paren',
|
7665 | nodes: []
|
7666 | });
|
7667 | stack.push(block);
|
7668 | push({
|
7669 | type: 'text',
|
7670 | value
|
7671 | });
|
7672 | continue;
|
7673 | }
|
7674 |
|
7675 | if (value === CHAR_RIGHT_PARENTHESES) {
|
7676 | if (block.type !== 'paren') {
|
7677 | push({
|
7678 | type: 'text',
|
7679 | value
|
7680 | });
|
7681 | continue;
|
7682 | }
|
7683 |
|
7684 | block = stack.pop();
|
7685 | push({
|
7686 | type: 'text',
|
7687 | value
|
7688 | });
|
7689 | block = stack[stack.length - 1];
|
7690 | continue;
|
7691 | }
|
7692 | |
7693 |
|
7694 |
|
7695 |
|
7696 |
|
7697 | if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
|
7698 | let open = value;
|
7699 | let next;
|
7700 |
|
7701 | if (options.keepQuotes !== true) {
|
7702 | value = '';
|
7703 | }
|
7704 |
|
7705 | while (index < length && (next = advance())) {
|
7706 | if (next === CHAR_BACKSLASH) {
|
7707 | value += next + advance();
|
7708 | continue;
|
7709 | }
|
7710 |
|
7711 | if (next === open) {
|
7712 | if (options.keepQuotes === true) value += next;
|
7713 | break;
|
7714 | }
|
7715 |
|
7716 | value += next;
|
7717 | }
|
7718 |
|
7719 | push({
|
7720 | type: 'text',
|
7721 | value
|
7722 | });
|
7723 | continue;
|
7724 | }
|
7725 | |
7726 |
|
7727 |
|
7728 |
|
7729 |
|
7730 | if (value === CHAR_LEFT_CURLY_BRACE) {
|
7731 | depth++;
|
7732 | let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
|
7733 | let brace = {
|
7734 | type: 'brace',
|
7735 | open: true,
|
7736 | close: false,
|
7737 | dollar,
|
7738 | depth,
|
7739 | commas: 0,
|
7740 | ranges: 0,
|
7741 | nodes: []
|
7742 | };
|
7743 | block = push(brace);
|
7744 | stack.push(block);
|
7745 | push({
|
7746 | type: 'open',
|
7747 | value
|
7748 | });
|
7749 | continue;
|
7750 | }
|
7751 | |
7752 |
|
7753 |
|
7754 |
|
7755 |
|
7756 | if (value === CHAR_RIGHT_CURLY_BRACE) {
|
7757 | if (block.type !== 'brace') {
|
7758 | push({
|
7759 | type: 'text',
|
7760 | value
|
7761 | });
|
7762 | continue;
|
7763 | }
|
7764 |
|
7765 | let type = 'close';
|
7766 | block = stack.pop();
|
7767 | block.close = true;
|
7768 | push({
|
7769 | type,
|
7770 | value
|
7771 | });
|
7772 | depth--;
|
7773 | block = stack[stack.length - 1];
|
7774 | continue;
|
7775 | }
|
7776 | |
7777 |
|
7778 |
|
7779 |
|
7780 |
|
7781 | if (value === CHAR_COMMA && depth > 0) {
|
7782 | if (block.ranges > 0) {
|
7783 | block.ranges = 0;
|
7784 | let open = block.nodes.shift();
|
7785 | block.nodes = [open, {
|
7786 | type: 'text',
|
7787 | value: stringify(block)
|
7788 | }];
|
7789 | }
|
7790 |
|
7791 | push({
|
7792 | type: 'comma',
|
7793 | value
|
7794 | });
|
7795 | block.commas++;
|
7796 | continue;
|
7797 | }
|
7798 | |
7799 |
|
7800 |
|
7801 |
|
7802 |
|
7803 | if (value === CHAR_DOT && depth > 0 && block.commas === 0) {
|
7804 | let siblings = block.nodes;
|
7805 |
|
7806 | if (depth === 0 || siblings.length === 0) {
|
7807 | push({
|
7808 | type: 'text',
|
7809 | value
|
7810 | });
|
7811 | continue;
|
7812 | }
|
7813 |
|
7814 | if (prev.type === 'dot') {
|
7815 | block.range = [];
|
7816 | prev.value += value;
|
7817 | prev.type = 'range';
|
7818 |
|
7819 | if (block.nodes.length !== 3 && block.nodes.length !== 5) {
|
7820 | block.invalid = true;
|
7821 | block.ranges = 0;
|
7822 | prev.type = 'text';
|
7823 | continue;
|
7824 | }
|
7825 |
|
7826 | block.ranges++;
|
7827 | block.args = [];
|
7828 | continue;
|
7829 | }
|
7830 |
|
7831 | if (prev.type === 'range') {
|
7832 | siblings.pop();
|
7833 | let before = siblings[siblings.length - 1];
|
7834 | before.value += prev.value + value;
|
7835 | prev = before;
|
7836 | block.ranges--;
|
7837 | continue;
|
7838 | }
|
7839 |
|
7840 | push({
|
7841 | type: 'dot',
|
7842 | value
|
7843 | });
|
7844 | continue;
|
7845 | }
|
7846 | |
7847 |
|
7848 |
|
7849 |
|
7850 |
|
7851 | push({
|
7852 | type: 'text',
|
7853 | value
|
7854 | });
|
7855 | }
|
7856 |
|
7857 |
|
7858 | do {
|
7859 | block = stack.pop();
|
7860 |
|
7861 | if (block.type !== 'root') {
|
7862 | block.nodes.forEach(node => {
|
7863 | if (!node.nodes) {
|
7864 | if (node.type === 'open') node.isOpen = true;
|
7865 | if (node.type === 'close') node.isClose = true;
|
7866 | if (!node.nodes) node.type = 'text';
|
7867 | node.invalid = true;
|
7868 | }
|
7869 | });
|
7870 |
|
7871 | let parent = stack[stack.length - 1];
|
7872 | let index = parent.nodes.indexOf(block);
|
7873 |
|
7874 | parent.nodes.splice(index, 1, ...block.nodes);
|
7875 | }
|
7876 | } while (stack.length > 0);
|
7877 |
|
7878 | push({
|
7879 | type: 'eos'
|
7880 | });
|
7881 | return ast;
|
7882 | };
|
7883 |
|
7884 | var parse_1 = parse;
|
7885 |
|
7886 |
|
7887 |
|
7888 |
|
7889 |
|
7890 |
|
7891 |
|
7892 |
|
7893 |
|
7894 |
|
7895 |
|
7896 |
|
7897 |
|
7898 |
|
7899 |
|
7900 |
|
7901 | const braces = (input, options = {}) => {
|
7902 | let output = [];
|
7903 |
|
7904 | if (Array.isArray(input)) {
|
7905 | for (let pattern of input) {
|
7906 | let result = braces.create(pattern, options);
|
7907 |
|
7908 | if (Array.isArray(result)) {
|
7909 | output.push(...result);
|
7910 | } else {
|
7911 | output.push(result);
|
7912 | }
|
7913 | }
|
7914 | } else {
|
7915 | output = [].concat(braces.create(input, options));
|
7916 | }
|
7917 |
|
7918 | if (options && options.expand === true && options.nodupes === true) {
|
7919 | output = [...new Set(output)];
|
7920 | }
|
7921 |
|
7922 | return output;
|
7923 | };
|
7924 |
|
7925 |
|
7926 |
|
7927 |
|
7928 |
|
7929 |
|
7930 |
|
7931 |
|
7932 |
|
7933 |
|
7934 |
|
7935 |
|
7936 |
|
7937 |
|
7938 |
|
7939 | braces.parse = (input, options = {}) => parse_1(input, options);
|
7940 |
|
7941 |
|
7942 |
|
7943 |
|
7944 |
|
7945 |
|
7946 |
|
7947 |
|
7948 |
|
7949 |
|
7950 |
|
7951 |
|
7952 |
|
7953 |
|
7954 |
|
7955 | braces.stringify = (input, options = {}) => {
|
7956 | if (typeof input === 'string') {
|
7957 | return stringify(braces.parse(input, options), options);
|
7958 | }
|
7959 |
|
7960 | return stringify(input, options);
|
7961 | };
|
7962 |
|
7963 |
|
7964 |
|
7965 |
|
7966 |
|
7967 |
|
7968 |
|
7969 |
|
7970 |
|
7971 |
|
7972 |
|
7973 |
|
7974 |
|
7975 |
|
7976 |
|
7977 |
|
7978 | braces.compile = (input, options = {}) => {
|
7979 | if (typeof input === 'string') {
|
7980 | input = braces.parse(input, options);
|
7981 | }
|
7982 |
|
7983 | return compile_1(input, options);
|
7984 | };
|
7985 |
|
7986 |
|
7987 |
|
7988 |
|
7989 |
|
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 |
|
7995 |
|
7996 |
|
7997 |
|
7998 |
|
7999 |
|
8000 |
|
8001 |
|
8002 |
|
8003 | braces.expand = (input, options = {}) => {
|
8004 | if (typeof input === 'string') {
|
8005 | input = braces.parse(input, options);
|
8006 | }
|
8007 |
|
8008 | let result = expand_1(input, options);
|
8009 |
|
8010 | if (options.noempty === true) {
|
8011 | result = result.filter(Boolean);
|
8012 | }
|
8013 |
|
8014 |
|
8015 | if (options.nodupes === true) {
|
8016 | result = [...new Set(result)];
|
8017 | }
|
8018 |
|
8019 | return result;
|
8020 | };
|
8021 |
|
8022 |
|
8023 |
|
8024 |
|
8025 |
|
8026 |
|
8027 |
|
8028 |
|
8029 |
|
8030 |
|
8031 |
|
8032 |
|
8033 |
|
8034 |
|
8035 |
|
8036 |
|
8037 |
|
8038 | braces.create = (input, options = {}) => {
|
8039 | if (input === '' || input.length < 3) {
|
8040 | return [input];
|
8041 | }
|
8042 |
|
8043 | return options.expand !== true ? braces.compile(input, options) : braces.expand(input, options);
|
8044 | };
|
8045 |
|
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 | var braces_1 = braces;
|
8051 |
|
8052 | const WIN_SLASH = '\\\\/';
|
8053 | const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
8054 |
|
8055 |
|
8056 |
|
8057 |
|
8058 | const DOT_LITERAL = '\\.';
|
8059 | const PLUS_LITERAL = '\\+';
|
8060 | const QMARK_LITERAL = '\\?';
|
8061 | const SLASH_LITERAL = '\\/';
|
8062 | const ONE_CHAR = '(?=.)';
|
8063 | const QMARK = '[^/]';
|
8064 | const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
8065 | const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
8066 | const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
8067 | const NO_DOT = `(?!${DOT_LITERAL})`;
|
8068 | const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
8069 | const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
8070 | const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
8071 | const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
8072 | const STAR = `${QMARK}*?`;
|
8073 | const POSIX_CHARS = {
|
8074 | DOT_LITERAL,
|
8075 | PLUS_LITERAL,
|
8076 | QMARK_LITERAL,
|
8077 | SLASH_LITERAL,
|
8078 | ONE_CHAR,
|
8079 | QMARK,
|
8080 | END_ANCHOR,
|
8081 | DOTS_SLASH,
|
8082 | NO_DOT,
|
8083 | NO_DOTS,
|
8084 | NO_DOT_SLASH,
|
8085 | NO_DOTS_SLASH,
|
8086 | QMARK_NO_DOT,
|
8087 | STAR,
|
8088 | START_ANCHOR
|
8089 | };
|
8090 |
|
8091 |
|
8092 |
|
8093 |
|
8094 | const WINDOWS_CHARS = Object.assign({}, POSIX_CHARS, {
|
8095 | SLASH_LITERAL: `[${WIN_SLASH}]`,
|
8096 | QMARK: WIN_NO_SLASH,
|
8097 | STAR: `${WIN_NO_SLASH}*?`,
|
8098 | DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
8099 | NO_DOT: `(?!${DOT_LITERAL})`,
|
8100 | NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
8101 | NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
8102 | NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
8103 | QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
8104 | START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
8105 | END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
|
8106 | });
|
8107 |
|
8108 |
|
8109 |
|
8110 |
|
8111 | const POSIX_REGEX_SOURCE = {
|
8112 | alnum: 'a-zA-Z0-9',
|
8113 | alpha: 'a-zA-Z',
|
8114 | ascii: '\\x00-\\x7F',
|
8115 | blank: ' \\t',
|
8116 | cntrl: '\\x00-\\x1F\\x7F',
|
8117 | digit: '0-9',
|
8118 | graph: '\\x21-\\x7E',
|
8119 | lower: 'a-z',
|
8120 | print: '\\x20-\\x7E ',
|
8121 | punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
|
8122 | space: ' \\t\\r\\n\\v\\f',
|
8123 | upper: 'A-Z',
|
8124 | word: 'A-Za-z0-9_',
|
8125 | xdigit: 'A-Fa-f0-9'
|
8126 | };
|
8127 | var constants$1 = {
|
8128 | MAX_LENGTH: 1024 * 64,
|
8129 | POSIX_REGEX_SOURCE,
|
8130 |
|
8131 | REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
8132 | REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
8133 | REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
8134 | REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
8135 | REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
8136 | REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
8137 |
|
8138 | REPLACEMENTS: {
|
8139 | '***': '*',
|
8140 | '**/**': '**',
|
8141 | '**/**/**': '**'
|
8142 | },
|
8143 |
|
8144 | CHAR_0: 48,
|
8145 |
|
8146 |
|
8147 | CHAR_9: 57,
|
8148 |
|
8149 |
|
8150 |
|
8151 | CHAR_UPPERCASE_A: 65,
|
8152 |
|
8153 |
|
8154 | CHAR_LOWERCASE_A: 97,
|
8155 |
|
8156 |
|
8157 | CHAR_UPPERCASE_Z: 90,
|
8158 |
|
8159 |
|
8160 | CHAR_LOWERCASE_Z: 122,
|
8161 |
|
8162 |
|
8163 | CHAR_LEFT_PARENTHESES: 40,
|
8164 |
|
8165 |
|
8166 | CHAR_RIGHT_PARENTHESES: 41,
|
8167 |
|
8168 |
|
8169 | CHAR_ASTERISK: 42,
|
8170 |
|
8171 |
|
8172 |
|
8173 | CHAR_AMPERSAND: 38,
|
8174 |
|
8175 |
|
8176 | CHAR_AT: 64,
|
8177 |
|
8178 |
|
8179 | CHAR_BACKWARD_SLASH: 92,
|
8180 |
|
8181 |
|
8182 | CHAR_CARRIAGE_RETURN: 13,
|
8183 |
|
8184 |
|
8185 | CHAR_CIRCUMFLEX_ACCENT: 94,
|
8186 |
|
8187 |
|
8188 | CHAR_COLON: 58,
|
8189 |
|
8190 |
|
8191 | CHAR_COMMA: 44,
|
8192 |
|
8193 |
|
8194 | CHAR_DOT: 46,
|
8195 |
|
8196 |
|
8197 | CHAR_DOUBLE_QUOTE: 34,
|
8198 |
|
8199 |
|
8200 | CHAR_EQUAL: 61,
|
8201 |
|
8202 |
|
8203 | CHAR_EXCLAMATION_MARK: 33,
|
8204 |
|
8205 |
|
8206 | CHAR_FORM_FEED: 12,
|
8207 |
|
8208 |
|
8209 | CHAR_FORWARD_SLASH: 47,
|
8210 |
|
8211 |
|
8212 | CHAR_GRAVE_ACCENT: 96,
|
8213 |
|
8214 |
|
8215 | CHAR_HASH: 35,
|
8216 |
|
8217 |
|
8218 | CHAR_HYPHEN_MINUS: 45,
|
8219 |
|
8220 |
|
8221 | CHAR_LEFT_ANGLE_BRACKET: 60,
|
8222 |
|
8223 |
|
8224 | CHAR_LEFT_CURLY_BRACE: 123,
|
8225 |
|
8226 |
|
8227 | CHAR_LEFT_SQUARE_BRACKET: 91,
|
8228 |
|
8229 |
|
8230 | CHAR_LINE_FEED: 10,
|
8231 |
|
8232 |
|
8233 | CHAR_NO_BREAK_SPACE: 160,
|
8234 |
|
8235 |
|
8236 | CHAR_PERCENT: 37,
|
8237 |
|
8238 |
|
8239 | CHAR_PLUS: 43,
|
8240 |
|
8241 |
|
8242 | CHAR_QUESTION_MARK: 63,
|
8243 |
|
8244 |
|
8245 | CHAR_RIGHT_ANGLE_BRACKET: 62,
|
8246 |
|
8247 |
|
8248 | CHAR_RIGHT_CURLY_BRACE: 125,
|
8249 |
|
8250 |
|
8251 | CHAR_RIGHT_SQUARE_BRACKET: 93,
|
8252 |
|
8253 |
|
8254 | CHAR_SEMICOLON: 59,
|
8255 |
|
8256 |
|
8257 | CHAR_SINGLE_QUOTE: 39,
|
8258 |
|
8259 |
|
8260 | CHAR_SPACE: 32,
|
8261 |
|
8262 |
|
8263 | CHAR_TAB: 9,
|
8264 |
|
8265 |
|
8266 | CHAR_UNDERSCORE: 95,
|
8267 |
|
8268 |
|
8269 | CHAR_VERTICAL_LINE: 124,
|
8270 |
|
8271 |
|
8272 | CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
8273 |
|
8274 |
|
8275 | SEP: path__default['default'].sep,
|
8276 |
|
8277 | |
8278 |
|
8279 |
|
8280 | extglobChars(chars) {
|
8281 | return {
|
8282 | '!': {
|
8283 | type: 'negate',
|
8284 | open: '(?:(?!(?:',
|
8285 | close: `))${chars.STAR})`
|
8286 | },
|
8287 | '?': {
|
8288 | type: 'qmark',
|
8289 | open: '(?:',
|
8290 | close: ')?'
|
8291 | },
|
8292 | '+': {
|
8293 | type: 'plus',
|
8294 | open: '(?:',
|
8295 | close: ')+'
|
8296 | },
|
8297 | '*': {
|
8298 | type: 'star',
|
8299 | open: '(?:',
|
8300 | close: ')*'
|
8301 | },
|
8302 | '@': {
|
8303 | type: 'at',
|
8304 | open: '(?:',
|
8305 | close: ')'
|
8306 | }
|
8307 | };
|
8308 | },
|
8309 |
|
8310 | |
8311 |
|
8312 |
|
8313 | globChars(win32) {
|
8314 | return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
8315 | }
|
8316 |
|
8317 | };
|
8318 |
|
8319 | var utils$1 = createCommonjsModule(function (module, exports) {
|
8320 |
|
8321 | const win32 = process.platform === 'win32';
|
8322 | const {
|
8323 | REGEX_BACKSLASH,
|
8324 | REGEX_REMOVE_BACKSLASH,
|
8325 | REGEX_SPECIAL_CHARS,
|
8326 | REGEX_SPECIAL_CHARS_GLOBAL
|
8327 | } = constants$1;
|
8328 |
|
8329 | exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
8330 |
|
8331 | exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
|
8332 |
|
8333 | exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
|
8334 |
|
8335 | exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
|
8336 |
|
8337 | exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
|
8338 |
|
8339 | exports.removeBackslashes = str => {
|
8340 | return str.replace(REGEX_REMOVE_BACKSLASH, match => {
|
8341 | return match === '\\' ? '' : match;
|
8342 | });
|
8343 | };
|
8344 |
|
8345 | exports.supportsLookbehinds = () => {
|
8346 | const segs = process.version.slice(1).split('.').map(Number);
|
8347 |
|
8348 | if (segs.length === 3 && segs[0] >= 9 || segs[0] === 8 && segs[1] >= 10) {
|
8349 | return true;
|
8350 | }
|
8351 |
|
8352 | return false;
|
8353 | };
|
8354 |
|
8355 | exports.isWindows = options => {
|
8356 | if (options && typeof options.windows === 'boolean') {
|
8357 | return options.windows;
|
8358 | }
|
8359 |
|
8360 | return win32 === true || path__default['default'].sep === '\\';
|
8361 | };
|
8362 |
|
8363 | exports.escapeLast = (input, char, lastIdx) => {
|
8364 | const idx = input.lastIndexOf(char, lastIdx);
|
8365 | if (idx === -1) return input;
|
8366 | if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
|
8367 | return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
8368 | };
|
8369 |
|
8370 | exports.removePrefix = (input, state = {}) => {
|
8371 | let output = input;
|
8372 |
|
8373 | if (output.startsWith('./')) {
|
8374 | output = output.slice(2);
|
8375 | state.prefix = './';
|
8376 | }
|
8377 |
|
8378 | return output;
|
8379 | };
|
8380 |
|
8381 | exports.wrapOutput = (input, state = {}, options = {}) => {
|
8382 | const prepend = options.contains ? '' : '^';
|
8383 | const append = options.contains ? '' : '$';
|
8384 | let output = `${prepend}(?:${input})${append}`;
|
8385 |
|
8386 | if (state.negated === true) {
|
8387 | output = `(?:^(?!${output}).*$)`;
|
8388 | }
|
8389 |
|
8390 | return output;
|
8391 | };
|
8392 | });
|
8393 |
|
8394 | const {
|
8395 | CHAR_ASTERISK,
|
8396 |
|
8397 |
|
8398 | CHAR_AT,
|
8399 |
|
8400 |
|
8401 | CHAR_BACKWARD_SLASH,
|
8402 |
|
8403 |
|
8404 | CHAR_COMMA: CHAR_COMMA$1,
|
8405 |
|
8406 |
|
8407 | CHAR_DOT: CHAR_DOT$1,
|
8408 |
|
8409 |
|
8410 | CHAR_EXCLAMATION_MARK,
|
8411 |
|
8412 |
|
8413 | CHAR_FORWARD_SLASH,
|
8414 |
|
8415 |
|
8416 | CHAR_LEFT_CURLY_BRACE: CHAR_LEFT_CURLY_BRACE$1,
|
8417 |
|
8418 |
|
8419 | CHAR_LEFT_PARENTHESES: CHAR_LEFT_PARENTHESES$1,
|
8420 |
|
8421 |
|
8422 | CHAR_LEFT_SQUARE_BRACKET: CHAR_LEFT_SQUARE_BRACKET$1,
|
8423 |
|
8424 |
|
8425 | CHAR_PLUS,
|
8426 |
|
8427 |
|
8428 | CHAR_QUESTION_MARK,
|
8429 |
|
8430 |
|
8431 | CHAR_RIGHT_CURLY_BRACE: CHAR_RIGHT_CURLY_BRACE$1,
|
8432 |
|
8433 |
|
8434 | CHAR_RIGHT_PARENTHESES: CHAR_RIGHT_PARENTHESES$1,
|
8435 |
|
8436 |
|
8437 | CHAR_RIGHT_SQUARE_BRACKET: CHAR_RIGHT_SQUARE_BRACKET$1
|
8438 |
|
8439 |
|
8440 | } = constants$1;
|
8441 |
|
8442 | const isPathSeparator = code => {
|
8443 | return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
8444 | };
|
8445 |
|
8446 | const depth = token => {
|
8447 | if (token.isPrefix !== true) {
|
8448 | token.depth = token.isGlobstar ? Infinity : 1;
|
8449 | }
|
8450 | };
|
8451 |
|
8452 |
|
8453 |
|
8454 |
|
8455 |
|
8456 |
|
8457 |
|
8458 |
|
8459 |
|
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 |
|
8466 |
|
8467 |
|
8468 | const scan = (input, options) => {
|
8469 | const opts = options || {};
|
8470 | const length = input.length - 1;
|
8471 | const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
8472 | const slashes = [];
|
8473 | const tokens = [];
|
8474 | const parts = [];
|
8475 | let str = input;
|
8476 | let index = -1;
|
8477 | let start = 0;
|
8478 | let lastIndex = 0;
|
8479 | let isBrace = false;
|
8480 | let isBracket = false;
|
8481 | let isGlob = false;
|
8482 | let isExtglob = false;
|
8483 | let isGlobstar = false;
|
8484 | let braceEscaped = false;
|
8485 | let backslashes = false;
|
8486 | let negated = false;
|
8487 | let finished = false;
|
8488 | let braces = 0;
|
8489 | let prev;
|
8490 | let code;
|
8491 | let token = {
|
8492 | value: '',
|
8493 | depth: 0,
|
8494 | isGlob: false
|
8495 | };
|
8496 |
|
8497 | const eos = () => index >= length;
|
8498 |
|
8499 | const peek = () => str.charCodeAt(index + 1);
|
8500 |
|
8501 | const advance = () => {
|
8502 | prev = code;
|
8503 | return str.charCodeAt(++index);
|
8504 | };
|
8505 |
|
8506 | while (index < length) {
|
8507 | code = advance();
|
8508 | let next;
|
8509 |
|
8510 | if (code === CHAR_BACKWARD_SLASH) {
|
8511 | backslashes = token.backslashes = true;
|
8512 | code = advance();
|
8513 |
|
8514 | if (code === CHAR_LEFT_CURLY_BRACE$1) {
|
8515 | braceEscaped = true;
|
8516 | }
|
8517 |
|
8518 | continue;
|
8519 | }
|
8520 |
|
8521 | if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE$1) {
|
8522 | braces++;
|
8523 |
|
8524 | while (eos() !== true && (code = advance())) {
|
8525 | if (code === CHAR_BACKWARD_SLASH) {
|
8526 | backslashes = token.backslashes = true;
|
8527 | advance();
|
8528 | continue;
|
8529 | }
|
8530 |
|
8531 | if (code === CHAR_LEFT_CURLY_BRACE$1) {
|
8532 | braces++;
|
8533 | continue;
|
8534 | }
|
8535 |
|
8536 | if (braceEscaped !== true && code === CHAR_DOT$1 && (code = advance()) === CHAR_DOT$1) {
|
8537 | isBrace = token.isBrace = true;
|
8538 | isGlob = token.isGlob = true;
|
8539 | finished = true;
|
8540 |
|
8541 | if (scanToEnd === true) {
|
8542 | continue;
|
8543 | }
|
8544 |
|
8545 | break;
|
8546 | }
|
8547 |
|
8548 | if (braceEscaped !== true && code === CHAR_COMMA$1) {
|
8549 | isBrace = token.isBrace = true;
|
8550 | isGlob = token.isGlob = true;
|
8551 | finished = true;
|
8552 |
|
8553 | if (scanToEnd === true) {
|
8554 | continue;
|
8555 | }
|
8556 |
|
8557 | break;
|
8558 | }
|
8559 |
|
8560 | if (code === CHAR_RIGHT_CURLY_BRACE$1) {
|
8561 | braces--;
|
8562 |
|
8563 | if (braces === 0) {
|
8564 | braceEscaped = false;
|
8565 | isBrace = token.isBrace = true;
|
8566 | finished = true;
|
8567 | break;
|
8568 | }
|
8569 | }
|
8570 | }
|
8571 |
|
8572 | if (scanToEnd === true) {
|
8573 | continue;
|
8574 | }
|
8575 |
|
8576 | break;
|
8577 | }
|
8578 |
|
8579 | if (code === CHAR_FORWARD_SLASH) {
|
8580 | slashes.push(index);
|
8581 | tokens.push(token);
|
8582 | token = {
|
8583 | value: '',
|
8584 | depth: 0,
|
8585 | isGlob: false
|
8586 | };
|
8587 | if (finished === true) continue;
|
8588 |
|
8589 | if (prev === CHAR_DOT$1 && index === start + 1) {
|
8590 | start += 2;
|
8591 | continue;
|
8592 | }
|
8593 |
|
8594 | lastIndex = index + 1;
|
8595 | continue;
|
8596 | }
|
8597 |
|
8598 | if (opts.noext !== true) {
|
8599 | const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
8600 |
|
8601 | if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES$1) {
|
8602 | isGlob = token.isGlob = true;
|
8603 | isExtglob = token.isExtglob = true;
|
8604 | finished = true;
|
8605 |
|
8606 | if (scanToEnd === true) {
|
8607 | while (eos() !== true && (code = advance())) {
|
8608 | if (code === CHAR_BACKWARD_SLASH) {
|
8609 | backslashes = token.backslashes = true;
|
8610 | code = advance();
|
8611 | continue;
|
8612 | }
|
8613 |
|
8614 | if (code === CHAR_RIGHT_PARENTHESES$1) {
|
8615 | isGlob = token.isGlob = true;
|
8616 | finished = true;
|
8617 | break;
|
8618 | }
|
8619 | }
|
8620 |
|
8621 | continue;
|
8622 | }
|
8623 |
|
8624 | break;
|
8625 | }
|
8626 | }
|
8627 |
|
8628 | if (code === CHAR_ASTERISK) {
|
8629 | if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
8630 | isGlob = token.isGlob = true;
|
8631 | finished = true;
|
8632 |
|
8633 | if (scanToEnd === true) {
|
8634 | continue;
|
8635 | }
|
8636 |
|
8637 | break;
|
8638 | }
|
8639 |
|
8640 | if (code === CHAR_QUESTION_MARK) {
|
8641 | isGlob = token.isGlob = true;
|
8642 | finished = true;
|
8643 |
|
8644 | if (scanToEnd === true) {
|
8645 | continue;
|
8646 | }
|
8647 |
|
8648 | break;
|
8649 | }
|
8650 |
|
8651 | if (code === CHAR_LEFT_SQUARE_BRACKET$1) {
|
8652 | while (eos() !== true && (next = advance())) {
|
8653 | if (next === CHAR_BACKWARD_SLASH) {
|
8654 | backslashes = token.backslashes = true;
|
8655 | advance();
|
8656 | continue;
|
8657 | }
|
8658 |
|
8659 | if (next === CHAR_RIGHT_SQUARE_BRACKET$1) {
|
8660 | isBracket = token.isBracket = true;
|
8661 | isGlob = token.isGlob = true;
|
8662 | finished = true;
|
8663 |
|
8664 | if (scanToEnd === true) {
|
8665 | continue;
|
8666 | }
|
8667 |
|
8668 | break;
|
8669 | }
|
8670 | }
|
8671 | }
|
8672 |
|
8673 | if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
8674 | negated = token.negated = true;
|
8675 | start++;
|
8676 | continue;
|
8677 | }
|
8678 |
|
8679 | if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES$1) {
|
8680 | isGlob = token.isGlob = true;
|
8681 |
|
8682 | if (scanToEnd === true) {
|
8683 | while (eos() !== true && (code = advance())) {
|
8684 | if (code === CHAR_LEFT_PARENTHESES$1) {
|
8685 | backslashes = token.backslashes = true;
|
8686 | code = advance();
|
8687 | continue;
|
8688 | }
|
8689 |
|
8690 | if (code === CHAR_RIGHT_PARENTHESES$1) {
|
8691 | finished = true;
|
8692 | break;
|
8693 | }
|
8694 | }
|
8695 |
|
8696 | continue;
|
8697 | }
|
8698 |
|
8699 | break;
|
8700 | }
|
8701 |
|
8702 | if (isGlob === true) {
|
8703 | finished = true;
|
8704 |
|
8705 | if (scanToEnd === true) {
|
8706 | continue;
|
8707 | }
|
8708 |
|
8709 | break;
|
8710 | }
|
8711 | }
|
8712 |
|
8713 | if (opts.noext === true) {
|
8714 | isExtglob = false;
|
8715 | isGlob = false;
|
8716 | }
|
8717 |
|
8718 | let base = str;
|
8719 | let prefix = '';
|
8720 | let glob = '';
|
8721 |
|
8722 | if (start > 0) {
|
8723 | prefix = str.slice(0, start);
|
8724 | str = str.slice(start);
|
8725 | lastIndex -= start;
|
8726 | }
|
8727 |
|
8728 | if (base && isGlob === true && lastIndex > 0) {
|
8729 | base = str.slice(0, lastIndex);
|
8730 | glob = str.slice(lastIndex);
|
8731 | } else if (isGlob === true) {
|
8732 | base = '';
|
8733 | glob = str;
|
8734 | } else {
|
8735 | base = str;
|
8736 | }
|
8737 |
|
8738 | if (base && base !== '' && base !== '/' && base !== str) {
|
8739 | if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
8740 | base = base.slice(0, -1);
|
8741 | }
|
8742 | }
|
8743 |
|
8744 | if (opts.unescape === true) {
|
8745 | if (glob) glob = utils$1.removeBackslashes(glob);
|
8746 |
|
8747 | if (base && backslashes === true) {
|
8748 | base = utils$1.removeBackslashes(base);
|
8749 | }
|
8750 | }
|
8751 |
|
8752 | const state = {
|
8753 | prefix,
|
8754 | input,
|
8755 | start,
|
8756 | base,
|
8757 | glob,
|
8758 | isBrace,
|
8759 | isBracket,
|
8760 | isGlob,
|
8761 | isExtglob,
|
8762 | isGlobstar,
|
8763 | negated
|
8764 | };
|
8765 |
|
8766 | if (opts.tokens === true) {
|
8767 | state.maxDepth = 0;
|
8768 |
|
8769 | if (!isPathSeparator(code)) {
|
8770 | tokens.push(token);
|
8771 | }
|
8772 |
|
8773 | state.tokens = tokens;
|
8774 | }
|
8775 |
|
8776 | if (opts.parts === true || opts.tokens === true) {
|
8777 | let prevIndex;
|
8778 |
|
8779 | for (let idx = 0; idx < slashes.length; idx++) {
|
8780 | const n = prevIndex ? prevIndex + 1 : start;
|
8781 | const i = slashes[idx];
|
8782 | const value = input.slice(n, i);
|
8783 |
|
8784 | if (opts.tokens) {
|
8785 | if (idx === 0 && start !== 0) {
|
8786 | tokens[idx].isPrefix = true;
|
8787 | tokens[idx].value = prefix;
|
8788 | } else {
|
8789 | tokens[idx].value = value;
|
8790 | }
|
8791 |
|
8792 | depth(tokens[idx]);
|
8793 | state.maxDepth += tokens[idx].depth;
|
8794 | }
|
8795 |
|
8796 | if (idx !== 0 || value !== '') {
|
8797 | parts.push(value);
|
8798 | }
|
8799 |
|
8800 | prevIndex = i;
|
8801 | }
|
8802 |
|
8803 | if (prevIndex && prevIndex + 1 < input.length) {
|
8804 | const value = input.slice(prevIndex + 1);
|
8805 | parts.push(value);
|
8806 |
|
8807 | if (opts.tokens) {
|
8808 | tokens[tokens.length - 1].value = value;
|
8809 | depth(tokens[tokens.length - 1]);
|
8810 | state.maxDepth += tokens[tokens.length - 1].depth;
|
8811 | }
|
8812 | }
|
8813 |
|
8814 | state.slashes = slashes;
|
8815 | state.parts = parts;
|
8816 | }
|
8817 |
|
8818 | return state;
|
8819 | };
|
8820 |
|
8821 | var scan_1 = scan;
|
8822 |
|
8823 |
|
8824 |
|
8825 |
|
8826 |
|
8827 |
|
8828 | const {
|
8829 | MAX_LENGTH: MAX_LENGTH$1,
|
8830 | POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
|
8831 | REGEX_NON_SPECIAL_CHARS,
|
8832 | REGEX_SPECIAL_CHARS_BACKREF,
|
8833 | REPLACEMENTS
|
8834 | } = constants$1;
|
8835 |
|
8836 |
|
8837 |
|
8838 |
|
8839 | const expandRange = (args, options) => {
|
8840 | if (typeof options.expandRange === 'function') {
|
8841 | return options.expandRange(...args, options);
|
8842 | }
|
8843 |
|
8844 | args.sort();
|
8845 | const value = `[${args.join('-')}]`;
|
8846 |
|
8847 | try {
|
8848 |
|
8849 | new RegExp(value);
|
8850 | } catch (ex) {
|
8851 | return args.map(v => utils$1.escapeRegex(v)).join('..');
|
8852 | }
|
8853 |
|
8854 | return value;
|
8855 | };
|
8856 |
|
8857 |
|
8858 |
|
8859 |
|
8860 |
|
8861 | const syntaxError = (type, char) => {
|
8862 | return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
8863 | };
|
8864 |
|
8865 |
|
8866 |
|
8867 |
|
8868 |
|
8869 |
|
8870 |
|
8871 |
|
8872 | const parse$1 = (input, options) => {
|
8873 | if (typeof input !== 'string') {
|
8874 | throw new TypeError('Expected a string');
|
8875 | }
|
8876 |
|
8877 | input = REPLACEMENTS[input] || input;
|
8878 | const opts = Object.assign({}, options);
|
8879 | const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
|
8880 | let len = input.length;
|
8881 |
|
8882 | if (len > max) {
|
8883 | throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
8884 | }
|
8885 |
|
8886 | const bos = {
|
8887 | type: 'bos',
|
8888 | value: '',
|
8889 | output: opts.prepend || ''
|
8890 | };
|
8891 | const tokens = [bos];
|
8892 | const capture = opts.capture ? '' : '?:';
|
8893 | const win32 = utils$1.isWindows(options);
|
8894 |
|
8895 | const PLATFORM_CHARS = constants$1.globChars(win32);
|
8896 | const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
|
8897 | const {
|
8898 | DOT_LITERAL,
|
8899 | PLUS_LITERAL,
|
8900 | SLASH_LITERAL,
|
8901 | ONE_CHAR,
|
8902 | DOTS_SLASH,
|
8903 | NO_DOT,
|
8904 | NO_DOT_SLASH,
|
8905 | NO_DOTS_SLASH,
|
8906 | QMARK,
|
8907 | QMARK_NO_DOT,
|
8908 | STAR,
|
8909 | START_ANCHOR
|
8910 | } = PLATFORM_CHARS;
|
8911 |
|
8912 | const globstar = opts => {
|
8913 | return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
8914 | };
|
8915 |
|
8916 | const nodot = opts.dot ? '' : NO_DOT;
|
8917 | const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
8918 | let star = opts.bash === true ? globstar(opts) : STAR;
|
8919 |
|
8920 | if (opts.capture) {
|
8921 | star = `(${star})`;
|
8922 | }
|
8923 |
|
8924 |
|
8925 | if (typeof opts.noext === 'boolean') {
|
8926 | opts.noextglob = opts.noext;
|
8927 | }
|
8928 |
|
8929 | const state = {
|
8930 | input,
|
8931 | index: -1,
|
8932 | start: 0,
|
8933 | dot: opts.dot === true,
|
8934 | consumed: '',
|
8935 | output: '',
|
8936 | prefix: '',
|
8937 | backtrack: false,
|
8938 | negated: false,
|
8939 | brackets: 0,
|
8940 | braces: 0,
|
8941 | parens: 0,
|
8942 | quotes: 0,
|
8943 | globstar: false,
|
8944 | tokens
|
8945 | };
|
8946 | input = utils$1.removePrefix(input, state);
|
8947 | len = input.length;
|
8948 | const extglobs = [];
|
8949 | const braces = [];
|
8950 | const stack = [];
|
8951 | let prev = bos;
|
8952 | let value;
|
8953 | |
8954 |
|
8955 |
|
8956 |
|
8957 | const eos = () => state.index === len - 1;
|
8958 |
|
8959 | const peek = state.peek = (n = 1) => input[state.index + n];
|
8960 |
|
8961 | const advance = state.advance = () => input[++state.index];
|
8962 |
|
8963 | const remaining = () => input.slice(state.index + 1);
|
8964 |
|
8965 | const consume = (value = '', num = 0) => {
|
8966 | state.consumed += value;
|
8967 | state.index += num;
|
8968 | };
|
8969 |
|
8970 | const append = token => {
|
8971 | state.output += token.output != null ? token.output : token.value;
|
8972 | consume(token.value);
|
8973 | };
|
8974 |
|
8975 | const negate = () => {
|
8976 | let count = 1;
|
8977 |
|
8978 | while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
|
8979 | advance();
|
8980 | state.start++;
|
8981 | count++;
|
8982 | }
|
8983 |
|
8984 | if (count % 2 === 0) {
|
8985 | return false;
|
8986 | }
|
8987 |
|
8988 | state.negated = true;
|
8989 | state.start++;
|
8990 | return true;
|
8991 | };
|
8992 |
|
8993 | const increment = type => {
|
8994 | state[type]++;
|
8995 | stack.push(type);
|
8996 | };
|
8997 |
|
8998 | const decrement = type => {
|
8999 | state[type]--;
|
9000 | stack.pop();
|
9001 | };
|
9002 | |
9003 |
|
9004 |
|
9005 |
|
9006 |
|
9007 |
|
9008 |
|
9009 |
|
9010 |
|
9011 | const push = tok => {
|
9012 | if (prev.type === 'globstar') {
|
9013 | const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
|
9014 | const isExtglob = tok.extglob === true || extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
|
9015 |
|
9016 | if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
|
9017 | state.output = state.output.slice(0, -prev.output.length);
|
9018 | prev.type = 'star';
|
9019 | prev.value = '*';
|
9020 | prev.output = star;
|
9021 | state.output += prev.output;
|
9022 | }
|
9023 | }
|
9024 |
|
9025 | if (extglobs.length && tok.type !== 'paren' && !EXTGLOB_CHARS[tok.value]) {
|
9026 | extglobs[extglobs.length - 1].inner += tok.value;
|
9027 | }
|
9028 |
|
9029 | if (tok.value || tok.output) append(tok);
|
9030 |
|
9031 | if (prev && prev.type === 'text' && tok.type === 'text') {
|
9032 | prev.value += tok.value;
|
9033 | prev.output = (prev.output || '') + tok.value;
|
9034 | return;
|
9035 | }
|
9036 |
|
9037 | tok.prev = prev;
|
9038 | tokens.push(tok);
|
9039 | prev = tok;
|
9040 | };
|
9041 |
|
9042 | const extglobOpen = (type, value) => {
|
9043 | const token = Object.assign({}, EXTGLOB_CHARS[value], {
|
9044 | conditions: 1,
|
9045 | inner: ''
|
9046 | });
|
9047 | token.prev = prev;
|
9048 | token.parens = state.parens;
|
9049 | token.output = state.output;
|
9050 | const output = (opts.capture ? '(' : '') + token.open;
|
9051 | increment('parens');
|
9052 | push({
|
9053 | type,
|
9054 | value,
|
9055 | output: state.output ? '' : ONE_CHAR
|
9056 | });
|
9057 | push({
|
9058 | type: 'paren',
|
9059 | extglob: true,
|
9060 | value: advance(),
|
9061 | output
|
9062 | });
|
9063 | extglobs.push(token);
|
9064 | };
|
9065 |
|
9066 | const extglobClose = token => {
|
9067 | let output = token.close + (opts.capture ? ')' : '');
|
9068 |
|
9069 | if (token.type === 'negate') {
|
9070 | let extglobStar = star;
|
9071 |
|
9072 | if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
|
9073 | extglobStar = globstar(opts);
|
9074 | }
|
9075 |
|
9076 | if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
9077 | output = token.close = `)$))${extglobStar}`;
|
9078 | }
|
9079 |
|
9080 | if (token.prev.type === 'bos' && eos()) {
|
9081 | state.negatedExtglob = true;
|
9082 | }
|
9083 | }
|
9084 |
|
9085 | push({
|
9086 | type: 'paren',
|
9087 | extglob: true,
|
9088 | value,
|
9089 | output
|
9090 | });
|
9091 | decrement('parens');
|
9092 | };
|
9093 | |
9094 |
|
9095 |
|
9096 |
|
9097 |
|
9098 | if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
9099 | let backslashes = false;
|
9100 | let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
9101 | if (first === '\\') {
|
9102 | backslashes = true;
|
9103 | return m;
|
9104 | }
|
9105 |
|
9106 | if (first === '?') {
|
9107 | if (esc) {
|
9108 | return esc + first + (rest ? QMARK.repeat(rest.length) : '');
|
9109 | }
|
9110 |
|
9111 | if (index === 0) {
|
9112 | return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
|
9113 | }
|
9114 |
|
9115 | return QMARK.repeat(chars.length);
|
9116 | }
|
9117 |
|
9118 | if (first === '.') {
|
9119 | return DOT_LITERAL.repeat(chars.length);
|
9120 | }
|
9121 |
|
9122 | if (first === '*') {
|
9123 | if (esc) {
|
9124 | return esc + first + (rest ? star : '');
|
9125 | }
|
9126 |
|
9127 | return star;
|
9128 | }
|
9129 |
|
9130 | return esc ? m : `\\${m}`;
|
9131 | });
|
9132 |
|
9133 | if (backslashes === true) {
|
9134 | if (opts.unescape === true) {
|
9135 | output = output.replace(/\\/g, '');
|
9136 | } else {
|
9137 | output = output.replace(/\\+/g, m => {
|
9138 | return m.length % 2 === 0 ? '\\\\' : m ? '\\' : '';
|
9139 | });
|
9140 | }
|
9141 | }
|
9142 |
|
9143 | if (output === input && opts.contains === true) {
|
9144 | state.output = input;
|
9145 | return state;
|
9146 | }
|
9147 |
|
9148 | state.output = utils$1.wrapOutput(output, state, options);
|
9149 | return state;
|
9150 | }
|
9151 | |
9152 |
|
9153 |
|
9154 |
|
9155 |
|
9156 | while (!eos()) {
|
9157 | value = advance();
|
9158 |
|
9159 | if (value === '\u0000') {
|
9160 | continue;
|
9161 | }
|
9162 | |
9163 |
|
9164 |
|
9165 |
|
9166 |
|
9167 | if (value === '\\') {
|
9168 | const next = peek();
|
9169 |
|
9170 | if (next === '/' && opts.bash !== true) {
|
9171 | continue;
|
9172 | }
|
9173 |
|
9174 | if (next === '.' || next === ';') {
|
9175 | continue;
|
9176 | }
|
9177 |
|
9178 | if (!next) {
|
9179 | value += '\\';
|
9180 | push({
|
9181 | type: 'text',
|
9182 | value
|
9183 | });
|
9184 | continue;
|
9185 | }
|
9186 |
|
9187 |
|
9188 | const match = /^\\+/.exec(remaining());
|
9189 | let slashes = 0;
|
9190 |
|
9191 | if (match && match[0].length > 2) {
|
9192 | slashes = match[0].length;
|
9193 | state.index += slashes;
|
9194 |
|
9195 | if (slashes % 2 !== 0) {
|
9196 | value += '\\';
|
9197 | }
|
9198 | }
|
9199 |
|
9200 | if (opts.unescape === true) {
|
9201 | value = advance() || '';
|
9202 | } else {
|
9203 | value += advance() || '';
|
9204 | }
|
9205 |
|
9206 | if (state.brackets === 0) {
|
9207 | push({
|
9208 | type: 'text',
|
9209 | value
|
9210 | });
|
9211 | continue;
|
9212 | }
|
9213 | }
|
9214 | |
9215 |
|
9216 |
|
9217 |
|
9218 |
|
9219 |
|
9220 | if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
|
9221 | if (opts.posix !== false && value === ':') {
|
9222 | const inner = prev.value.slice(1);
|
9223 |
|
9224 | if (inner.includes('[')) {
|
9225 | prev.posix = true;
|
9226 |
|
9227 | if (inner.includes(':')) {
|
9228 | const idx = prev.value.lastIndexOf('[');
|
9229 | const pre = prev.value.slice(0, idx);
|
9230 | const rest = prev.value.slice(idx + 2);
|
9231 | const posix = POSIX_REGEX_SOURCE$1[rest];
|
9232 |
|
9233 | if (posix) {
|
9234 | prev.value = pre + posix;
|
9235 | state.backtrack = true;
|
9236 | advance();
|
9237 |
|
9238 | if (!bos.output && tokens.indexOf(prev) === 1) {
|
9239 | bos.output = ONE_CHAR;
|
9240 | }
|
9241 |
|
9242 | continue;
|
9243 | }
|
9244 | }
|
9245 | }
|
9246 | }
|
9247 |
|
9248 | if (value === '[' && peek() !== ':' || value === '-' && peek() === ']') {
|
9249 | value = `\\${value}`;
|
9250 | }
|
9251 |
|
9252 | if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
|
9253 | value = `\\${value}`;
|
9254 | }
|
9255 |
|
9256 | if (opts.posix === true && value === '!' && prev.value === '[') {
|
9257 | value = '^';
|
9258 | }
|
9259 |
|
9260 | prev.value += value;
|
9261 | append({
|
9262 | value
|
9263 | });
|
9264 | continue;
|
9265 | }
|
9266 | |
9267 |
|
9268 |
|
9269 |
|
9270 |
|
9271 |
|
9272 | if (state.quotes === 1 && value !== '"') {
|
9273 | value = utils$1.escapeRegex(value);
|
9274 | prev.value += value;
|
9275 | append({
|
9276 | value
|
9277 | });
|
9278 | continue;
|
9279 | }
|
9280 | |
9281 |
|
9282 |
|
9283 |
|
9284 |
|
9285 | if (value === '"') {
|
9286 | state.quotes = state.quotes === 1 ? 0 : 1;
|
9287 |
|
9288 | if (opts.keepQuotes === true) {
|
9289 | push({
|
9290 | type: 'text',
|
9291 | value
|
9292 | });
|
9293 | }
|
9294 |
|
9295 | continue;
|
9296 | }
|
9297 | |
9298 |
|
9299 |
|
9300 |
|
9301 |
|
9302 | if (value === '(') {
|
9303 | increment('parens');
|
9304 | push({
|
9305 | type: 'paren',
|
9306 | value
|
9307 | });
|
9308 | continue;
|
9309 | }
|
9310 |
|
9311 | if (value === ')') {
|
9312 | if (state.parens === 0 && opts.strictBrackets === true) {
|
9313 | throw new SyntaxError(syntaxError('opening', '('));
|
9314 | }
|
9315 |
|
9316 | const extglob = extglobs[extglobs.length - 1];
|
9317 |
|
9318 | if (extglob && state.parens === extglob.parens + 1) {
|
9319 | extglobClose(extglobs.pop());
|
9320 | continue;
|
9321 | }
|
9322 |
|
9323 | push({
|
9324 | type: 'paren',
|
9325 | value,
|
9326 | output: state.parens ? ')' : '\\)'
|
9327 | });
|
9328 | decrement('parens');
|
9329 | continue;
|
9330 | }
|
9331 | |
9332 |
|
9333 |
|
9334 |
|
9335 |
|
9336 | if (value === '[') {
|
9337 | if (opts.nobracket === true || !remaining().includes(']')) {
|
9338 | if (opts.nobracket !== true && opts.strictBrackets === true) {
|
9339 | throw new SyntaxError(syntaxError('closing', ']'));
|
9340 | }
|
9341 |
|
9342 | value = `\\${value}`;
|
9343 | } else {
|
9344 | increment('brackets');
|
9345 | }
|
9346 |
|
9347 | push({
|
9348 | type: 'bracket',
|
9349 | value
|
9350 | });
|
9351 | continue;
|
9352 | }
|
9353 |
|
9354 | if (value === ']') {
|
9355 | if (opts.nobracket === true || prev && prev.type === 'bracket' && prev.value.length === 1) {
|
9356 | push({
|
9357 | type: 'text',
|
9358 | value,
|
9359 | output: `\\${value}`
|
9360 | });
|
9361 | continue;
|
9362 | }
|
9363 |
|
9364 | if (state.brackets === 0) {
|
9365 | if (opts.strictBrackets === true) {
|
9366 | throw new SyntaxError(syntaxError('opening', '['));
|
9367 | }
|
9368 |
|
9369 | push({
|
9370 | type: 'text',
|
9371 | value,
|
9372 | output: `\\${value}`
|
9373 | });
|
9374 | continue;
|
9375 | }
|
9376 |
|
9377 | decrement('brackets');
|
9378 | const prevValue = prev.value.slice(1);
|
9379 |
|
9380 | if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
|
9381 | value = `/${value}`;
|
9382 | }
|
9383 |
|
9384 | prev.value += value;
|
9385 | append({
|
9386 | value
|
9387 | });
|
9388 |
|
9389 |
|
9390 | if (opts.literalBrackets === false || utils$1.hasRegexChars(prevValue)) {
|
9391 | continue;
|
9392 | }
|
9393 |
|
9394 | const escaped = utils$1.escapeRegex(prev.value);
|
9395 | state.output = state.output.slice(0, -prev.value.length);
|
9396 |
|
9397 |
|
9398 | if (opts.literalBrackets === true) {
|
9399 | state.output += escaped;
|
9400 | prev.value = escaped;
|
9401 | continue;
|
9402 | }
|
9403 |
|
9404 |
|
9405 | prev.value = `(${capture}${escaped}|${prev.value})`;
|
9406 | state.output += prev.value;
|
9407 | continue;
|
9408 | }
|
9409 | |
9410 |
|
9411 |
|
9412 |
|
9413 |
|
9414 | if (value === '{' && opts.nobrace !== true) {
|
9415 | increment('braces');
|
9416 | const open = {
|
9417 | type: 'brace',
|
9418 | value,
|
9419 | output: '(',
|
9420 | outputIndex: state.output.length,
|
9421 | tokensIndex: state.tokens.length
|
9422 | };
|
9423 | braces.push(open);
|
9424 | push(open);
|
9425 | continue;
|
9426 | }
|
9427 |
|
9428 | if (value === '}') {
|
9429 | const brace = braces[braces.length - 1];
|
9430 |
|
9431 | if (opts.nobrace === true || !brace) {
|
9432 | push({
|
9433 | type: 'text',
|
9434 | value,
|
9435 | output: value
|
9436 | });
|
9437 | continue;
|
9438 | }
|
9439 |
|
9440 | let output = ')';
|
9441 |
|
9442 | if (brace.dots === true) {
|
9443 | const arr = tokens.slice();
|
9444 | const range = [];
|
9445 |
|
9446 | for (let i = arr.length - 1; i >= 0; i--) {
|
9447 | tokens.pop();
|
9448 |
|
9449 | if (arr[i].type === 'brace') {
|
9450 | break;
|
9451 | }
|
9452 |
|
9453 | if (arr[i].type !== 'dots') {
|
9454 | range.unshift(arr[i].value);
|
9455 | }
|
9456 | }
|
9457 |
|
9458 | output = expandRange(range, opts);
|
9459 | state.backtrack = true;
|
9460 | }
|
9461 |
|
9462 | if (brace.comma !== true && brace.dots !== true) {
|
9463 | const out = state.output.slice(0, brace.outputIndex);
|
9464 | const toks = state.tokens.slice(brace.tokensIndex);
|
9465 | brace.value = brace.output = '\\{';
|
9466 | value = output = '\\}';
|
9467 | state.output = out;
|
9468 |
|
9469 | for (const t of toks) {
|
9470 | state.output += t.output || t.value;
|
9471 | }
|
9472 | }
|
9473 |
|
9474 | push({
|
9475 | type: 'brace',
|
9476 | value,
|
9477 | output
|
9478 | });
|
9479 | decrement('braces');
|
9480 | braces.pop();
|
9481 | continue;
|
9482 | }
|
9483 | |
9484 |
|
9485 |
|
9486 |
|
9487 |
|
9488 | if (value === '|') {
|
9489 | if (extglobs.length > 0) {
|
9490 | extglobs[extglobs.length - 1].conditions++;
|
9491 | }
|
9492 |
|
9493 | push({
|
9494 | type: 'text',
|
9495 | value
|
9496 | });
|
9497 | continue;
|
9498 | }
|
9499 | |
9500 |
|
9501 |
|
9502 |
|
9503 |
|
9504 | if (value === ',') {
|
9505 | let output = value;
|
9506 | const brace = braces[braces.length - 1];
|
9507 |
|
9508 | if (brace && stack[stack.length - 1] === 'braces') {
|
9509 | brace.comma = true;
|
9510 | output = '|';
|
9511 | }
|
9512 |
|
9513 | push({
|
9514 | type: 'comma',
|
9515 | value,
|
9516 | output
|
9517 | });
|
9518 | continue;
|
9519 | }
|
9520 | |
9521 |
|
9522 |
|
9523 |
|
9524 |
|
9525 | if (value === '/') {
|
9526 |
|
9527 |
|
9528 |
|
9529 |
|
9530 | if (prev.type === 'dot' && state.index === state.start + 1) {
|
9531 | state.start = state.index + 1;
|
9532 | state.consumed = '';
|
9533 | state.output = '';
|
9534 | tokens.pop();
|
9535 | prev = bos;
|
9536 |
|
9537 | continue;
|
9538 | }
|
9539 |
|
9540 | push({
|
9541 | type: 'slash',
|
9542 | value,
|
9543 | output: SLASH_LITERAL
|
9544 | });
|
9545 | continue;
|
9546 | }
|
9547 | |
9548 |
|
9549 |
|
9550 |
|
9551 |
|
9552 | if (value === '.') {
|
9553 | if (state.braces > 0 && prev.type === 'dot') {
|
9554 | if (prev.value === '.') prev.output = DOT_LITERAL;
|
9555 | const brace = braces[braces.length - 1];
|
9556 | prev.type = 'dots';
|
9557 | prev.output += value;
|
9558 | prev.value += value;
|
9559 | brace.dots = true;
|
9560 | continue;
|
9561 | }
|
9562 |
|
9563 | if (state.braces + state.parens === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
|
9564 | push({
|
9565 | type: 'text',
|
9566 | value,
|
9567 | output: DOT_LITERAL
|
9568 | });
|
9569 | continue;
|
9570 | }
|
9571 |
|
9572 | push({
|
9573 | type: 'dot',
|
9574 | value,
|
9575 | output: DOT_LITERAL
|
9576 | });
|
9577 | continue;
|
9578 | }
|
9579 | |
9580 |
|
9581 |
|
9582 |
|
9583 |
|
9584 | if (value === '?') {
|
9585 | const isGroup = prev && prev.value === '(';
|
9586 |
|
9587 | if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
9588 | extglobOpen('qmark', value);
|
9589 | continue;
|
9590 | }
|
9591 |
|
9592 | if (prev && prev.type === 'paren') {
|
9593 | const next = peek();
|
9594 | let output = value;
|
9595 |
|
9596 | if (next === '<' && !utils$1.supportsLookbehinds()) {
|
9597 | throw new Error('Node.js v10 or higher is required for regex lookbehinds');
|
9598 | }
|
9599 |
|
9600 | if (prev.value === '(' && !/[!=<:]/.test(next) || next === '<' && !/<([!=]|\w+>)/.test(remaining())) {
|
9601 | output = `\\${value}`;
|
9602 | }
|
9603 |
|
9604 | push({
|
9605 | type: 'text',
|
9606 | value,
|
9607 | output
|
9608 | });
|
9609 | continue;
|
9610 | }
|
9611 |
|
9612 | if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
|
9613 | push({
|
9614 | type: 'qmark',
|
9615 | value,
|
9616 | output: QMARK_NO_DOT
|
9617 | });
|
9618 | continue;
|
9619 | }
|
9620 |
|
9621 | push({
|
9622 | type: 'qmark',
|
9623 | value,
|
9624 | output: QMARK
|
9625 | });
|
9626 | continue;
|
9627 | }
|
9628 | |
9629 |
|
9630 |
|
9631 |
|
9632 |
|
9633 | if (value === '!') {
|
9634 | if (opts.noextglob !== true && peek() === '(') {
|
9635 | if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
|
9636 | extglobOpen('negate', value);
|
9637 | continue;
|
9638 | }
|
9639 | }
|
9640 |
|
9641 | if (opts.nonegate !== true && state.index === 0) {
|
9642 | negate();
|
9643 | continue;
|
9644 | }
|
9645 | }
|
9646 | |
9647 |
|
9648 |
|
9649 |
|
9650 |
|
9651 | if (value === '+') {
|
9652 | if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
9653 | extglobOpen('plus', value);
|
9654 | continue;
|
9655 | }
|
9656 |
|
9657 | if (prev && prev.value === '(' || opts.regex === false) {
|
9658 | push({
|
9659 | type: 'plus',
|
9660 | value,
|
9661 | output: PLUS_LITERAL
|
9662 | });
|
9663 | continue;
|
9664 | }
|
9665 |
|
9666 | if (prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace') || state.parens > 0) {
|
9667 | push({
|
9668 | type: 'plus',
|
9669 | value
|
9670 | });
|
9671 | continue;
|
9672 | }
|
9673 |
|
9674 | push({
|
9675 | type: 'plus',
|
9676 | value: PLUS_LITERAL
|
9677 | });
|
9678 | continue;
|
9679 | }
|
9680 | |
9681 |
|
9682 |
|
9683 |
|
9684 |
|
9685 | if (value === '@') {
|
9686 | if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
|
9687 | push({
|
9688 | type: 'at',
|
9689 | extglob: true,
|
9690 | value,
|
9691 | output: ''
|
9692 | });
|
9693 | continue;
|
9694 | }
|
9695 |
|
9696 | push({
|
9697 | type: 'text',
|
9698 | value
|
9699 | });
|
9700 | continue;
|
9701 | }
|
9702 | |
9703 |
|
9704 |
|
9705 |
|
9706 |
|
9707 | if (value !== '*') {
|
9708 | if (value === '$' || value === '^') {
|
9709 | value = `\\${value}`;
|
9710 | }
|
9711 |
|
9712 | const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
9713 |
|
9714 | if (match) {
|
9715 | value += match[0];
|
9716 | state.index += match[0].length;
|
9717 | }
|
9718 |
|
9719 | push({
|
9720 | type: 'text',
|
9721 | value
|
9722 | });
|
9723 | continue;
|
9724 | }
|
9725 | |
9726 |
|
9727 |
|
9728 |
|
9729 |
|
9730 | if (prev && (prev.type === 'globstar' || prev.star === true)) {
|
9731 | prev.type = 'star';
|
9732 | prev.star = true;
|
9733 | prev.value += value;
|
9734 | prev.output = star;
|
9735 | state.backtrack = true;
|
9736 | state.globstar = true;
|
9737 | consume(value);
|
9738 | continue;
|
9739 | }
|
9740 |
|
9741 | let rest = remaining();
|
9742 |
|
9743 | if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
9744 | extglobOpen('star', value);
|
9745 | continue;
|
9746 | }
|
9747 |
|
9748 | if (prev.type === 'star') {
|
9749 | if (opts.noglobstar === true) {
|
9750 | consume(value);
|
9751 | continue;
|
9752 | }
|
9753 |
|
9754 | const prior = prev.prev;
|
9755 | const before = prior.prev;
|
9756 | const isStart = prior.type === 'slash' || prior.type === 'bos';
|
9757 | const afterStar = before && (before.type === 'star' || before.type === 'globstar');
|
9758 |
|
9759 | if (opts.bash === true && (!isStart || rest[0] && rest[0] !== '/')) {
|
9760 | push({
|
9761 | type: 'star',
|
9762 | value,
|
9763 | output: ''
|
9764 | });
|
9765 | continue;
|
9766 | }
|
9767 |
|
9768 | const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
|
9769 | const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
|
9770 |
|
9771 | if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
|
9772 | push({
|
9773 | type: 'star',
|
9774 | value,
|
9775 | output: ''
|
9776 | });
|
9777 | continue;
|
9778 | }
|
9779 |
|
9780 |
|
9781 | while (rest.slice(0, 3) === '/**') {
|
9782 | const after = input[state.index + 4];
|
9783 |
|
9784 | if (after && after !== '/') {
|
9785 | break;
|
9786 | }
|
9787 |
|
9788 | rest = rest.slice(3);
|
9789 | consume('/**', 3);
|
9790 | }
|
9791 |
|
9792 | if (prior.type === 'bos' && eos()) {
|
9793 | prev.type = 'globstar';
|
9794 | prev.value += value;
|
9795 | prev.output = globstar(opts);
|
9796 | state.output = prev.output;
|
9797 | state.globstar = true;
|
9798 | consume(value);
|
9799 | continue;
|
9800 | }
|
9801 |
|
9802 | if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
|
9803 | state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
9804 | prior.output = `(?:${prior.output}`;
|
9805 | prev.type = 'globstar';
|
9806 | prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
|
9807 | prev.value += value;
|
9808 | state.globstar = true;
|
9809 | state.output += prior.output + prev.output;
|
9810 | consume(value);
|
9811 | continue;
|
9812 | }
|
9813 |
|
9814 | if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
|
9815 | const end = rest[1] !== void 0 ? '|$' : '';
|
9816 | state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
9817 | prior.output = `(?:${prior.output}`;
|
9818 | prev.type = 'globstar';
|
9819 | prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
9820 | prev.value += value;
|
9821 | state.output += prior.output + prev.output;
|
9822 | state.globstar = true;
|
9823 | consume(value + advance());
|
9824 | push({
|
9825 | type: 'slash',
|
9826 | value: '/',
|
9827 | output: ''
|
9828 | });
|
9829 | continue;
|
9830 | }
|
9831 |
|
9832 | if (prior.type === 'bos' && rest[0] === '/') {
|
9833 | prev.type = 'globstar';
|
9834 | prev.value += value;
|
9835 | prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
9836 | state.output = prev.output;
|
9837 | state.globstar = true;
|
9838 | consume(value + advance());
|
9839 | push({
|
9840 | type: 'slash',
|
9841 | value: '/',
|
9842 | output: ''
|
9843 | });
|
9844 | continue;
|
9845 | }
|
9846 |
|
9847 |
|
9848 | state.output = state.output.slice(0, -prev.output.length);
|
9849 |
|
9850 | prev.type = 'globstar';
|
9851 | prev.output = globstar(opts);
|
9852 | prev.value += value;
|
9853 |
|
9854 | state.output += prev.output;
|
9855 | state.globstar = true;
|
9856 | consume(value);
|
9857 | continue;
|
9858 | }
|
9859 |
|
9860 | const token = {
|
9861 | type: 'star',
|
9862 | value,
|
9863 | output: star
|
9864 | };
|
9865 |
|
9866 | if (opts.bash === true) {
|
9867 | token.output = '.*?';
|
9868 |
|
9869 | if (prev.type === 'bos' || prev.type === 'slash') {
|
9870 | token.output = nodot + token.output;
|
9871 | }
|
9872 |
|
9873 | push(token);
|
9874 | continue;
|
9875 | }
|
9876 |
|
9877 | if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
|
9878 | token.output = value;
|
9879 | push(token);
|
9880 | continue;
|
9881 | }
|
9882 |
|
9883 | if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
|
9884 | if (prev.type === 'dot') {
|
9885 | state.output += NO_DOT_SLASH;
|
9886 | prev.output += NO_DOT_SLASH;
|
9887 | } else if (opts.dot === true) {
|
9888 | state.output += NO_DOTS_SLASH;
|
9889 | prev.output += NO_DOTS_SLASH;
|
9890 | } else {
|
9891 | state.output += nodot;
|
9892 | prev.output += nodot;
|
9893 | }
|
9894 |
|
9895 | if (peek() !== '*') {
|
9896 | state.output += ONE_CHAR;
|
9897 | prev.output += ONE_CHAR;
|
9898 | }
|
9899 | }
|
9900 |
|
9901 | push(token);
|
9902 | }
|
9903 |
|
9904 | while (state.brackets > 0) {
|
9905 | if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
|
9906 | state.output = utils$1.escapeLast(state.output, '[');
|
9907 | decrement('brackets');
|
9908 | }
|
9909 |
|
9910 | while (state.parens > 0) {
|
9911 | if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
|
9912 | state.output = utils$1.escapeLast(state.output, '(');
|
9913 | decrement('parens');
|
9914 | }
|
9915 |
|
9916 | while (state.braces > 0) {
|
9917 | if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
|
9918 | state.output = utils$1.escapeLast(state.output, '{');
|
9919 | decrement('braces');
|
9920 | }
|
9921 |
|
9922 | if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
|
9923 | push({
|
9924 | type: 'maybe_slash',
|
9925 | value: '',
|
9926 | output: `${SLASH_LITERAL}?`
|
9927 | });
|
9928 | }
|
9929 |
|
9930 |
|
9931 | if (state.backtrack === true) {
|
9932 | state.output = '';
|
9933 |
|
9934 | for (const token of state.tokens) {
|
9935 | state.output += token.output != null ? token.output : token.value;
|
9936 |
|
9937 | if (token.suffix) {
|
9938 | state.output += token.suffix;
|
9939 | }
|
9940 | }
|
9941 | }
|
9942 |
|
9943 | return state;
|
9944 | };
|
9945 |
|
9946 |
|
9947 |
|
9948 |
|
9949 |
|
9950 |
|
9951 |
|
9952 | parse$1.fastpaths = (input, options) => {
|
9953 | const opts = Object.assign({}, options);
|
9954 | const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
|
9955 | const len = input.length;
|
9956 |
|
9957 | if (len > max) {
|
9958 | throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
9959 | }
|
9960 |
|
9961 | input = REPLACEMENTS[input] || input;
|
9962 | const win32 = utils$1.isWindows(options);
|
9963 |
|
9964 | const {
|
9965 | DOT_LITERAL,
|
9966 | SLASH_LITERAL,
|
9967 | ONE_CHAR,
|
9968 | DOTS_SLASH,
|
9969 | NO_DOT,
|
9970 | NO_DOTS,
|
9971 | NO_DOTS_SLASH,
|
9972 | STAR,
|
9973 | START_ANCHOR
|
9974 | } = constants$1.globChars(win32);
|
9975 | const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
9976 | const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
9977 | const capture = opts.capture ? '' : '?:';
|
9978 | const state = {
|
9979 | negated: false,
|
9980 | prefix: ''
|
9981 | };
|
9982 | let star = opts.bash === true ? '.*?' : STAR;
|
9983 |
|
9984 | if (opts.capture) {
|
9985 | star = `(${star})`;
|
9986 | }
|
9987 |
|
9988 | const globstar = opts => {
|
9989 | if (opts.noglobstar === true) return star;
|
9990 | return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
9991 | };
|
9992 |
|
9993 | const create = str => {
|
9994 | switch (str) {
|
9995 | case '*':
|
9996 | return `${nodot}${ONE_CHAR}${star}`;
|
9997 |
|
9998 | case '.*':
|
9999 | return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
10000 |
|
10001 | case '*.*':
|
10002 | return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
10003 |
|
10004 | case '*/*':
|
10005 | return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
10006 |
|
10007 | case '**':
|
10008 | return nodot + globstar(opts);
|
10009 |
|
10010 | case '**/*':
|
10011 | return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
10012 |
|
10013 | case '**/*.*':
|
10014 | return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
10015 |
|
10016 | case '**/.*':
|
10017 | return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
10018 |
|
10019 | default:
|
10020 | {
|
10021 | const match = /^(.*?)\.(\w+)$/.exec(str);
|
10022 | if (!match) return;
|
10023 | const source = create(match[1]);
|
10024 | if (!source) return;
|
10025 | return source + DOT_LITERAL + match[2];
|
10026 | }
|
10027 | }
|
10028 | };
|
10029 |
|
10030 | const output = utils$1.removePrefix(input, state);
|
10031 | let source = create(output);
|
10032 |
|
10033 | if (source && opts.strictSlashes !== true) {
|
10034 | source += `${SLASH_LITERAL}?`;
|
10035 | }
|
10036 |
|
10037 | return source;
|
10038 | };
|
10039 |
|
10040 | var parse_1$1 = parse$1;
|
10041 |
|
10042 | const isObject$2 = val => val && typeof val === 'object' && !Array.isArray(val);
|
10043 |
|
10044 |
|
10045 |
|
10046 |
|
10047 |
|
10048 |
|
10049 |
|
10050 |
|
10051 |
|
10052 |
|
10053 |
|
10054 |
|
10055 |
|
10056 |
|
10057 |
|
10058 |
|
10059 |
|
10060 |
|
10061 |
|
10062 |
|
10063 |
|
10064 |
|
10065 |
|
10066 | const picomatch = (glob, options, returnState = false) => {
|
10067 | if (Array.isArray(glob)) {
|
10068 | const fns = glob.map(input => picomatch(input, options, returnState));
|
10069 |
|
10070 | const arrayMatcher = str => {
|
10071 | for (const isMatch of fns) {
|
10072 | const state = isMatch(str);
|
10073 | if (state) return state;
|
10074 | }
|
10075 |
|
10076 | return false;
|
10077 | };
|
10078 |
|
10079 | return arrayMatcher;
|
10080 | }
|
10081 |
|
10082 | const isState = isObject$2(glob) && glob.tokens && glob.input;
|
10083 |
|
10084 | if (glob === '' || typeof glob !== 'string' && !isState) {
|
10085 | throw new TypeError('Expected pattern to be a non-empty string');
|
10086 | }
|
10087 |
|
10088 | const opts = options || {};
|
10089 | const posix = utils$1.isWindows(options);
|
10090 | const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true);
|
10091 | const state = regex.state;
|
10092 | delete regex.state;
|
10093 |
|
10094 | let isIgnored = () => false;
|
10095 |
|
10096 | if (opts.ignore) {
|
10097 | const ignoreOpts = Object.assign({}, options, {
|
10098 | ignore: null,
|
10099 | onMatch: null,
|
10100 | onResult: null
|
10101 | });
|
10102 | isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
|
10103 | }
|
10104 |
|
10105 | const matcher = (input, returnObject = false) => {
|
10106 | const {
|
10107 | isMatch,
|
10108 | match,
|
10109 | output
|
10110 | } = picomatch.test(input, regex, options, {
|
10111 | glob,
|
10112 | posix
|
10113 | });
|
10114 | const result = {
|
10115 | glob,
|
10116 | state,
|
10117 | regex,
|
10118 | posix,
|
10119 | input,
|
10120 | output,
|
10121 | match,
|
10122 | isMatch
|
10123 | };
|
10124 |
|
10125 | if (typeof opts.onResult === 'function') {
|
10126 | opts.onResult(result);
|
10127 | }
|
10128 |
|
10129 | if (isMatch === false) {
|
10130 | result.isMatch = false;
|
10131 | return returnObject ? result : false;
|
10132 | }
|
10133 |
|
10134 | if (isIgnored(input)) {
|
10135 | if (typeof opts.onIgnore === 'function') {
|
10136 | opts.onIgnore(result);
|
10137 | }
|
10138 |
|
10139 | result.isMatch = false;
|
10140 | return returnObject ? result : false;
|
10141 | }
|
10142 |
|
10143 | if (typeof opts.onMatch === 'function') {
|
10144 | opts.onMatch(result);
|
10145 | }
|
10146 |
|
10147 | return returnObject ? result : true;
|
10148 | };
|
10149 |
|
10150 | if (returnState) {
|
10151 | matcher.state = state;
|
10152 | }
|
10153 |
|
10154 | return matcher;
|
10155 | };
|
10156 |
|
10157 |
|
10158 |
|
10159 |
|
10160 |
|
10161 |
|
10162 |
|
10163 |
|
10164 |
|
10165 |
|
10166 |
|
10167 |
|
10168 |
|
10169 |
|
10170 |
|
10171 |
|
10172 |
|
10173 |
|
10174 | picomatch.test = (input, regex, options, {
|
10175 | glob,
|
10176 | posix
|
10177 | } = {}) => {
|
10178 | if (typeof input !== 'string') {
|
10179 | throw new TypeError('Expected input to be a string');
|
10180 | }
|
10181 |
|
10182 | if (input === '') {
|
10183 | return {
|
10184 | isMatch: false,
|
10185 | output: ''
|
10186 | };
|
10187 | }
|
10188 |
|
10189 | const opts = options || {};
|
10190 | const format = opts.format || (posix ? utils$1.toPosixSlashes : null);
|
10191 | let match = input === glob;
|
10192 | let output = match && format ? format(input) : input;
|
10193 |
|
10194 | if (match === false) {
|
10195 | output = format ? format(input) : input;
|
10196 | match = output === glob;
|
10197 | }
|
10198 |
|
10199 | if (match === false || opts.capture === true) {
|
10200 | if (opts.matchBase === true || opts.basename === true) {
|
10201 | match = picomatch.matchBase(input, regex, options, posix);
|
10202 | } else {
|
10203 | match = regex.exec(output);
|
10204 | }
|
10205 | }
|
10206 |
|
10207 | return {
|
10208 | isMatch: Boolean(match),
|
10209 | match,
|
10210 | output
|
10211 | };
|
10212 | };
|
10213 |
|
10214 |
|
10215 |
|
10216 |
|
10217 |
|
10218 |
|
10219 |
|
10220 |
|
10221 |
|
10222 |
|
10223 |
|
10224 |
|
10225 |
|
10226 |
|
10227 |
|
10228 | picomatch.matchBase = (input, glob, options, posix = utils$1.isWindows(options)) => {
|
10229 | const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
10230 | return regex.test(path__default['default'].basename(input));
|
10231 | };
|
10232 |
|
10233 |
|
10234 |
|
10235 |
|
10236 |
|
10237 |
|
10238 |
|
10239 |
|
10240 |
|
10241 |
|
10242 |
|
10243 |
|
10244 |
|
10245 |
|
10246 |
|
10247 |
|
10248 |
|
10249 |
|
10250 | picomatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
|
10251 |
|
10252 |
|
10253 |
|
10254 |
|
10255 |
|
10256 |
|
10257 |
|
10258 |
|
10259 |
|
10260 |
|
10261 |
|
10262 |
|
10263 |
|
10264 |
|
10265 |
|
10266 | picomatch.parse = (pattern, options) => {
|
10267 | if (Array.isArray(pattern)) return pattern.map(p => picomatch.parse(p, options));
|
10268 | return parse_1$1(pattern, Object.assign({}, options, {
|
10269 | fastpaths: false
|
10270 | }));
|
10271 | };
|
10272 |
|
10273 |
|
10274 |
|
10275 |
|
10276 |
|
10277 |
|
10278 |
|
10279 |
|
10280 |
|
10281 |
|
10282 |
|
10283 |
|
10284 |
|
10285 |
|
10286 |
|
10287 |
|
10288 |
|
10289 |
|
10290 |
|
10291 |
|
10292 |
|
10293 |
|
10294 |
|
10295 |
|
10296 |
|
10297 |
|
10298 |
|
10299 |
|
10300 | picomatch.scan = (input, options) => scan_1(input, options);
|
10301 |
|
10302 |
|
10303 |
|
10304 |
|
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 |
|
10317 |
|
10318 |
|
10319 | picomatch.compileRe = (parsed, options, returnOutput = false, returnState = false) => {
|
10320 | if (returnOutput === true) {
|
10321 | return parsed.output;
|
10322 | }
|
10323 |
|
10324 | const opts = options || {};
|
10325 | const prepend = opts.contains ? '' : '^';
|
10326 | const append = opts.contains ? '' : '$';
|
10327 | let source = `${prepend}(?:${parsed.output})${append}`;
|
10328 |
|
10329 | if (parsed && parsed.negated === true) {
|
10330 | source = `^(?!${source}).*$`;
|
10331 | }
|
10332 |
|
10333 | const regex = picomatch.toRegex(source, options);
|
10334 |
|
10335 | if (returnState === true) {
|
10336 | regex.state = parsed;
|
10337 | }
|
10338 |
|
10339 | return regex;
|
10340 | };
|
10341 |
|
10342 | picomatch.makeRe = (input, options, returnOutput = false, returnState = false) => {
|
10343 | if (!input || typeof input !== 'string') {
|
10344 | throw new TypeError('Expected a non-empty string');
|
10345 | }
|
10346 |
|
10347 | const opts = options || {};
|
10348 | let parsed = {
|
10349 | negated: false,
|
10350 | fastpaths: true
|
10351 | };
|
10352 | let prefix = '';
|
10353 | let output;
|
10354 |
|
10355 | if (input.startsWith('./')) {
|
10356 | input = input.slice(2);
|
10357 | prefix = parsed.prefix = './';
|
10358 | }
|
10359 |
|
10360 | if (opts.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
|
10361 | output = parse_1$1.fastpaths(input, options);
|
10362 | }
|
10363 |
|
10364 | if (output === undefined) {
|
10365 | parsed = parse_1$1(input, options);
|
10366 | parsed.prefix = prefix + (parsed.prefix || '');
|
10367 | } else {
|
10368 | parsed.output = output;
|
10369 | }
|
10370 |
|
10371 | return picomatch.compileRe(parsed, options, returnOutput, returnState);
|
10372 | };
|
10373 |
|
10374 |
|
10375 |
|
10376 |
|
10377 |
|
10378 |
|
10379 |
|
10380 |
|
10381 |
|
10382 |
|
10383 |
|
10384 |
|
10385 |
|
10386 |
|
10387 |
|
10388 |
|
10389 |
|
10390 |
|
10391 | picomatch.toRegex = (source, options) => {
|
10392 | try {
|
10393 | const opts = options || {};
|
10394 | return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
|
10395 | } catch (err) {
|
10396 | if (options && options.debug === true) throw err;
|
10397 | return /$^/;
|
10398 | }
|
10399 | };
|
10400 |
|
10401 |
|
10402 |
|
10403 |
|
10404 |
|
10405 |
|
10406 | picomatch.constants = constants$1;
|
10407 |
|
10408 |
|
10409 |
|
10410 |
|
10411 | var picomatch_1 = picomatch;
|
10412 |
|
10413 | var picomatch$1 = picomatch_1;
|
10414 |
|
10415 | const isEmptyString = val => typeof val === 'string' && (val === '' || val === './');
|
10416 |
|
10417 |
|
10418 |
|
10419 |
|
10420 |
|
10421 |
|
10422 |
|
10423 |
|
10424 |
|
10425 |
|
10426 |
|
10427 |
|
10428 |
|
10429 |
|
10430 |
|
10431 |
|
10432 |
|
10433 |
|
10434 |
|
10435 | const micromatch = (list, patterns, options) => {
|
10436 | patterns = [].concat(patterns);
|
10437 | list = [].concat(list);
|
10438 | let omit = new Set();
|
10439 | let keep = new Set();
|
10440 | let items = new Set();
|
10441 | let negatives = 0;
|
10442 |
|
10443 | let onResult = state => {
|
10444 | items.add(state.output);
|
10445 |
|
10446 | if (options && options.onResult) {
|
10447 | options.onResult(state);
|
10448 | }
|
10449 | };
|
10450 |
|
10451 | for (let i = 0; i < patterns.length; i++) {
|
10452 | let isMatch = picomatch$1(String(patterns[i]), Object.assign({}, options, {
|
10453 | onResult
|
10454 | }), true);
|
10455 | let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
|
10456 | if (negated) negatives++;
|
10457 |
|
10458 | for (let item of list) {
|
10459 | let matched = isMatch(item, true);
|
10460 | let match = negated ? !matched.isMatch : matched.isMatch;
|
10461 | if (!match) continue;
|
10462 |
|
10463 | if (negated) {
|
10464 | omit.add(matched.output);
|
10465 | } else {
|
10466 | omit.delete(matched.output);
|
10467 | keep.add(matched.output);
|
10468 | }
|
10469 | }
|
10470 | }
|
10471 |
|
10472 | let result = negatives === patterns.length ? [...items] : [...keep];
|
10473 | let matches = result.filter(item => !omit.has(item));
|
10474 |
|
10475 | if (options && matches.length === 0) {
|
10476 | if (options.failglob === true) {
|
10477 | throw new Error(`No matches found for "${patterns.join(', ')}"`);
|
10478 | }
|
10479 |
|
10480 | if (options.nonull === true || options.nullglob === true) {
|
10481 | return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
|
10482 | }
|
10483 | }
|
10484 |
|
10485 | return matches;
|
10486 | };
|
10487 |
|
10488 |
|
10489 |
|
10490 |
|
10491 |
|
10492 | micromatch.match = micromatch;
|
10493 |
|
10494 |
|
10495 |
|
10496 |
|
10497 |
|
10498 |
|
10499 |
|
10500 |
|
10501 |
|
10502 |
|
10503 |
|
10504 |
|
10505 |
|
10506 |
|
10507 |
|
10508 |
|
10509 |
|
10510 |
|
10511 |
|
10512 | micromatch.matcher = (pattern, options) => picomatch$1(pattern, options);
|
10513 |
|
10514 |
|
10515 |
|
10516 |
|
10517 |
|
10518 |
|
10519 |
|
10520 |
|
10521 |
|
10522 |
|
10523 |
|
10524 |
|
10525 |
|
10526 |
|
10527 |
|
10528 |
|
10529 |
|
10530 |
|
10531 | micromatch.isMatch = (str, patterns, options) => picomatch$1(patterns, options)(str);
|
10532 |
|
10533 |
|
10534 |
|
10535 |
|
10536 |
|
10537 | micromatch.any = micromatch.isMatch;
|
10538 |
|
10539 |
|
10540 |
|
10541 |
|
10542 |
|
10543 |
|
10544 |
|
10545 |
|
10546 |
|
10547 |
|
10548 |
|
10549 |
|
10550 |
|
10551 |
|
10552 |
|
10553 |
|
10554 |
|
10555 | micromatch.not = (list, patterns, options = {}) => {
|
10556 | patterns = [].concat(patterns).map(String);
|
10557 | let result = new Set();
|
10558 | let items = [];
|
10559 |
|
10560 | let onResult = state => {
|
10561 | if (options.onResult) options.onResult(state);
|
10562 | items.push(state.output);
|
10563 | };
|
10564 |
|
10565 | let matches = micromatch(list, patterns, Object.assign({}, options, {
|
10566 | onResult
|
10567 | }));
|
10568 |
|
10569 | for (let item of items) {
|
10570 | if (!matches.includes(item)) {
|
10571 | result.add(item);
|
10572 | }
|
10573 | }
|
10574 |
|
10575 | return [...result];
|
10576 | };
|
10577 |
|
10578 |
|
10579 |
|
10580 |
|
10581 |
|
10582 |
|
10583 |
|
10584 |
|
10585 |
|
10586 |
|
10587 |
|
10588 |
|
10589 |
|
10590 |
|
10591 |
|
10592 |
|
10593 |
|
10594 |
|
10595 |
|
10596 |
|
10597 |
|
10598 | micromatch.contains = (str, pattern, options) => {
|
10599 | if (typeof str !== 'string') {
|
10600 | throw new TypeError(`Expected a string: "${util__default['default'].inspect(str)}"`);
|
10601 | }
|
10602 |
|
10603 | if (Array.isArray(pattern)) {
|
10604 | return pattern.some(p => micromatch.contains(str, p, options));
|
10605 | }
|
10606 |
|
10607 | if (typeof pattern === 'string') {
|
10608 | if (isEmptyString(str) || isEmptyString(pattern)) {
|
10609 | return false;
|
10610 | }
|
10611 |
|
10612 | if (str.includes(pattern) || str.startsWith('./') && str.slice(2).includes(pattern)) {
|
10613 | return true;
|
10614 | }
|
10615 | }
|
10616 |
|
10617 | return micromatch.isMatch(str, pattern, Object.assign({}, options, {
|
10618 | contains: true
|
10619 | }));
|
10620 | };
|
10621 |
|
10622 |
|
10623 |
|
10624 |
|
10625 |
|
10626 |
|
10627 |
|
10628 |
|
10629 |
|
10630 |
|
10631 |
|
10632 |
|
10633 |
|
10634 |
|
10635 |
|
10636 |
|
10637 |
|
10638 |
|
10639 |
|
10640 |
|
10641 |
|
10642 | micromatch.matchKeys = (obj, patterns, options) => {
|
10643 | if (!utils$1.isObject(obj)) {
|
10644 | throw new TypeError('Expected the first argument to be an object');
|
10645 | }
|
10646 |
|
10647 | let keys = micromatch(Object.keys(obj), patterns, options);
|
10648 | let res = {};
|
10649 |
|
10650 | for (let key of keys) res[key] = obj[key];
|
10651 |
|
10652 | return res;
|
10653 | };
|
10654 |
|
10655 |
|
10656 |
|
10657 |
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 |
|
10663 |
|
10664 |
|
10665 |
|
10666 |
|
10667 |
|
10668 |
|
10669 |
|
10670 |
|
10671 |
|
10672 |
|
10673 |
|
10674 | micromatch.some = (list, patterns, options) => {
|
10675 | let items = [].concat(list);
|
10676 |
|
10677 | for (let pattern of [].concat(patterns)) {
|
10678 | let isMatch = picomatch$1(String(pattern), options);
|
10679 |
|
10680 | if (items.some(item => isMatch(item))) {
|
10681 | return true;
|
10682 | }
|
10683 | }
|
10684 |
|
10685 | return false;
|
10686 | };
|
10687 |
|
10688 |
|
10689 |
|
10690 |
|
10691 |
|
10692 |
|
10693 |
|
10694 |
|
10695 |
|
10696 |
|
10697 |
|
10698 |
|
10699 |
|
10700 |
|
10701 |
|
10702 |
|
10703 |
|
10704 |
|
10705 |
|
10706 |
|
10707 |
|
10708 |
|
10709 |
|
10710 |
|
10711 |
|
10712 | micromatch.every = (list, patterns, options) => {
|
10713 | let items = [].concat(list);
|
10714 |
|
10715 | for (let pattern of [].concat(patterns)) {
|
10716 | let isMatch = picomatch$1(String(pattern), options);
|
10717 |
|
10718 | if (!items.every(item => isMatch(item))) {
|
10719 | return false;
|
10720 | }
|
10721 | }
|
10722 |
|
10723 | return true;
|
10724 | };
|
10725 |
|
10726 |
|
10727 |
|
10728 |
|
10729 |
|
10730 |
|
10731 |
|
10732 |
|
10733 |
|
10734 |
|
10735 |
|
10736 |
|
10737 |
|
10738 |
|
10739 |
|
10740 |
|
10741 |
|
10742 |
|
10743 |
|
10744 |
|
10745 |
|
10746 |
|
10747 |
|
10748 |
|
10749 |
|
10750 |
|
10751 |
|
10752 |
|
10753 | micromatch.all = (str, patterns, options) => {
|
10754 | if (typeof str !== 'string') {
|
10755 | throw new TypeError(`Expected a string: "${util__default['default'].inspect(str)}"`);
|
10756 | }
|
10757 |
|
10758 | return [].concat(patterns).every(p => picomatch$1(p, options)(str));
|
10759 | };
|
10760 |
|
10761 |
|
10762 |
|
10763 |
|
10764 |
|
10765 |
|
10766 |
|
10767 |
|
10768 |
|
10769 |
|
10770 |
|
10771 |
|
10772 |
|
10773 |
|
10774 |
|
10775 |
|
10776 |
|
10777 |
|
10778 |
|
10779 |
|
10780 | micromatch.capture = (glob, input, options) => {
|
10781 | let posix = utils$1.isWindows(options);
|
10782 | let regex = picomatch$1.makeRe(String(glob), Object.assign({}, options, {
|
10783 | capture: true
|
10784 | }));
|
10785 | let match = regex.exec(posix ? utils$1.toPosixSlashes(input) : input);
|
10786 |
|
10787 | if (match) {
|
10788 | return match.slice(1).map(v => v === void 0 ? '' : v);
|
10789 | }
|
10790 | };
|
10791 |
|
10792 |
|
10793 |
|
10794 |
|
10795 |
|
10796 |
|
10797 |
|
10798 |
|
10799 |
|
10800 |
|
10801 |
|
10802 |
|
10803 |
|
10804 |
|
10805 |
|
10806 |
|
10807 |
|
10808 | micromatch.makeRe = (...args) => picomatch$1.makeRe(...args);
|
10809 |
|
10810 |
|
10811 |
|
10812 |
|
10813 |
|
10814 |
|
10815 |
|
10816 |
|
10817 |
|
10818 |
|
10819 |
|
10820 |
|
10821 |
|
10822 |
|
10823 |
|
10824 | micromatch.scan = (...args) => picomatch$1.scan(...args);
|
10825 |
|
10826 |
|
10827 |
|
10828 |
|
10829 |
|
10830 |
|
10831 |
|
10832 |
|
10833 |
|
10834 |
|
10835 |
|
10836 |
|
10837 |
|
10838 |
|
10839 |
|
10840 | micromatch.parse = (patterns, options) => {
|
10841 | let res = [];
|
10842 |
|
10843 | for (let pattern of [].concat(patterns || [])) {
|
10844 | for (let str of braces_1(String(pattern), options)) {
|
10845 | res.push(picomatch$1.parse(str, options));
|
10846 | }
|
10847 | }
|
10848 |
|
10849 | return res;
|
10850 | };
|
10851 |
|
10852 |
|
10853 |
|
10854 |
|
10855 |
|
10856 |
|
10857 |
|
10858 |
|
10859 |
|
10860 |
|
10861 |
|
10862 |
|
10863 |
|
10864 |
|
10865 |
|
10866 |
|
10867 |
|
10868 |
|
10869 | micromatch.braces = (pattern, options) => {
|
10870 | if (typeof pattern !== 'string') throw new TypeError('Expected a string');
|
10871 |
|
10872 | if (options && options.nobrace === true || !/\{.*\}/.test(pattern)) {
|
10873 | return [pattern];
|
10874 | }
|
10875 |
|
10876 | return braces_1(pattern, options);
|
10877 | };
|
10878 |
|
10879 |
|
10880 |
|
10881 |
|
10882 |
|
10883 | micromatch.braceExpand = (pattern, options) => {
|
10884 | if (typeof pattern !== 'string') throw new TypeError('Expected a string');
|
10885 | return micromatch.braces(pattern, Object.assign({}, options, {
|
10886 | expand: true
|
10887 | }));
|
10888 | };
|
10889 |
|
10890 |
|
10891 |
|
10892 |
|
10893 |
|
10894 | var micromatch_1 = micromatch;
|
10895 |
|
10896 | var pattern = createCommonjsModule(function (module, exports) {
|
10897 |
|
10898 | Object.defineProperty(exports, "__esModule", {
|
10899 | value: true
|
10900 | });
|
10901 | exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0;
|
10902 | const GLOBSTAR = '**';
|
10903 | const ESCAPE_SYMBOL = '\\';
|
10904 | const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
|
10905 | const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[.*]/;
|
10906 | const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\(.*\|.*\)/;
|
10907 | const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/;
|
10908 | const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/;
|
10909 |
|
10910 | function isStaticPattern(pattern, options = {}) {
|
10911 | return !isDynamicPattern(pattern, options);
|
10912 | }
|
10913 |
|
10914 | exports.isStaticPattern = isStaticPattern;
|
10915 |
|
10916 | function isDynamicPattern(pattern, options = {}) {
|
10917 | |
10918 |
|
10919 |
|
10920 |
|
10921 |
|
10922 | if (pattern === '') {
|
10923 | return false;
|
10924 | }
|
10925 | |
10926 |
|
10927 |
|
10928 |
|
10929 |
|
10930 |
|
10931 | if (options.caseSensitiveMatch === false || pattern.includes(ESCAPE_SYMBOL)) {
|
10932 | return true;
|
10933 | }
|
10934 |
|
10935 | if (COMMON_GLOB_SYMBOLS_RE.test(pattern) || REGEX_CHARACTER_CLASS_SYMBOLS_RE.test(pattern) || REGEX_GROUP_SYMBOLS_RE.test(pattern)) {
|
10936 | return true;
|
10937 | }
|
10938 |
|
10939 | if (options.extglob !== false && GLOB_EXTENSION_SYMBOLS_RE.test(pattern)) {
|
10940 | return true;
|
10941 | }
|
10942 |
|
10943 | if (options.braceExpansion !== false && BRACE_EXPANSIONS_SYMBOLS_RE.test(pattern)) {
|
10944 | return true;
|
10945 | }
|
10946 |
|
10947 | return false;
|
10948 | }
|
10949 |
|
10950 | exports.isDynamicPattern = isDynamicPattern;
|
10951 |
|
10952 | function convertToPositivePattern(pattern) {
|
10953 | return isNegativePattern(pattern) ? pattern.slice(1) : pattern;
|
10954 | }
|
10955 |
|
10956 | exports.convertToPositivePattern = convertToPositivePattern;
|
10957 |
|
10958 | function convertToNegativePattern(pattern) {
|
10959 | return '!' + pattern;
|
10960 | }
|
10961 |
|
10962 | exports.convertToNegativePattern = convertToNegativePattern;
|
10963 |
|
10964 | function isNegativePattern(pattern) {
|
10965 | return pattern.startsWith('!') && pattern[1] !== '(';
|
10966 | }
|
10967 |
|
10968 | exports.isNegativePattern = isNegativePattern;
|
10969 |
|
10970 | function isPositivePattern(pattern) {
|
10971 | return !isNegativePattern(pattern);
|
10972 | }
|
10973 |
|
10974 | exports.isPositivePattern = isPositivePattern;
|
10975 |
|
10976 | function getNegativePatterns(patterns) {
|
10977 | return patterns.filter(isNegativePattern);
|
10978 | }
|
10979 |
|
10980 | exports.getNegativePatterns = getNegativePatterns;
|
10981 |
|
10982 | function getPositivePatterns(patterns) {
|
10983 | return patterns.filter(isPositivePattern);
|
10984 | }
|
10985 |
|
10986 | exports.getPositivePatterns = getPositivePatterns;
|
10987 |
|
10988 | function getBaseDirectory(pattern) {
|
10989 | return globParent(pattern, {
|
10990 | flipBackslashes: false
|
10991 | });
|
10992 | }
|
10993 |
|
10994 | exports.getBaseDirectory = getBaseDirectory;
|
10995 |
|
10996 | function hasGlobStar(pattern) {
|
10997 | return pattern.includes(GLOBSTAR);
|
10998 | }
|
10999 |
|
11000 | exports.hasGlobStar = hasGlobStar;
|
11001 |
|
11002 | function endsWithSlashGlobStar(pattern) {
|
11003 | return pattern.endsWith('/' + GLOBSTAR);
|
11004 | }
|
11005 |
|
11006 | exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
|
11007 |
|
11008 | function isAffectDepthOfReadingPattern(pattern) {
|
11009 | const basename = path__default['default'].basename(pattern);
|
11010 | return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
|
11011 | }
|
11012 |
|
11013 | exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
|
11014 |
|
11015 | function expandPatternsWithBraceExpansion(patterns) {
|
11016 | return patterns.reduce((collection, pattern) => {
|
11017 | return collection.concat(expandBraceExpansion(pattern));
|
11018 | }, []);
|
11019 | }
|
11020 |
|
11021 | exports.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
|
11022 |
|
11023 | function expandBraceExpansion(pattern) {
|
11024 | return micromatch_1.braces(pattern, {
|
11025 | expand: true,
|
11026 | nodupes: true
|
11027 | });
|
11028 | }
|
11029 |
|
11030 | exports.expandBraceExpansion = expandBraceExpansion;
|
11031 |
|
11032 | function getPatternParts(pattern, options) {
|
11033 | let {
|
11034 | parts
|
11035 | } = picomatch$1.scan(pattern, Object.assign(Object.assign({}, options), {
|
11036 | parts: true
|
11037 | }));
|
11038 | |
11039 |
|
11040 |
|
11041 |
|
11042 |
|
11043 | if (parts.length === 0) {
|
11044 | parts = [pattern];
|
11045 | }
|
11046 | |
11047 |
|
11048 |
|
11049 |
|
11050 |
|
11051 |
|
11052 | if (parts[0].startsWith('/')) {
|
11053 | parts[0] = parts[0].slice(1);
|
11054 | parts.unshift('');
|
11055 | }
|
11056 |
|
11057 | return parts;
|
11058 | }
|
11059 |
|
11060 | exports.getPatternParts = getPatternParts;
|
11061 |
|
11062 | function makeRe(pattern, options) {
|
11063 | return micromatch_1.makeRe(pattern, options);
|
11064 | }
|
11065 |
|
11066 | exports.makeRe = makeRe;
|
11067 |
|
11068 | function convertPatternsToRe(patterns, options) {
|
11069 | return patterns.map(pattern => makeRe(pattern, options));
|
11070 | }
|
11071 |
|
11072 | exports.convertPatternsToRe = convertPatternsToRe;
|
11073 |
|
11074 | function matchAny(entry, patternsRe) {
|
11075 | return patternsRe.some(patternRe => patternRe.test(entry));
|
11076 | }
|
11077 |
|
11078 | exports.matchAny = matchAny;
|
11079 | });
|
11080 |
|
11081 |
|
11082 |
|
11083 |
|
11084 |
|
11085 |
|
11086 |
|
11087 |
|
11088 |
|
11089 |
|
11090 | const PassThrough = stream_1__default['default'].PassThrough;
|
11091 | const slice = Array.prototype.slice;
|
11092 | var merge2_1 = merge2;
|
11093 |
|
11094 | function merge2() {
|
11095 | const streamsQueue = [];
|
11096 | const args = slice.call(arguments);
|
11097 | let merging = false;
|
11098 | let options = args[args.length - 1];
|
11099 |
|
11100 | if (options && !Array.isArray(options) && options.pipe == null) {
|
11101 | args.pop();
|
11102 | } else {
|
11103 | options = {};
|
11104 | }
|
11105 |
|
11106 | const doEnd = options.end !== false;
|
11107 | const doPipeError = options.pipeError === true;
|
11108 |
|
11109 | if (options.objectMode == null) {
|
11110 | options.objectMode = true;
|
11111 | }
|
11112 |
|
11113 | if (options.highWaterMark == null) {
|
11114 | options.highWaterMark = 64 * 1024;
|
11115 | }
|
11116 |
|
11117 | const mergedStream = PassThrough(options);
|
11118 |
|
11119 | function addStream() {
|
11120 | for (let i = 0, len = arguments.length; i < len; i++) {
|
11121 | streamsQueue.push(pauseStreams(arguments[i], options));
|
11122 | }
|
11123 |
|
11124 | mergeStream();
|
11125 | return this;
|
11126 | }
|
11127 |
|
11128 | function mergeStream() {
|
11129 | if (merging) {
|
11130 | return;
|
11131 | }
|
11132 |
|
11133 | merging = true;
|
11134 | let streams = streamsQueue.shift();
|
11135 |
|
11136 | if (!streams) {
|
11137 | process.nextTick(endStream);
|
11138 | return;
|
11139 | }
|
11140 |
|
11141 | if (!Array.isArray(streams)) {
|
11142 | streams = [streams];
|
11143 | }
|
11144 |
|
11145 | let pipesCount = streams.length + 1;
|
11146 |
|
11147 | function next() {
|
11148 | if (--pipesCount > 0) {
|
11149 | return;
|
11150 | }
|
11151 |
|
11152 | merging = false;
|
11153 | mergeStream();
|
11154 | }
|
11155 |
|
11156 | function pipe(stream) {
|
11157 | function onend() {
|
11158 | stream.removeListener('merge2UnpipeEnd', onend);
|
11159 | stream.removeListener('end', onend);
|
11160 |
|
11161 | if (doPipeError) {
|
11162 | stream.removeListener('error', onerror);
|
11163 | }
|
11164 |
|
11165 | next();
|
11166 | }
|
11167 |
|
11168 | function onerror(err) {
|
11169 | mergedStream.emit('error', err);
|
11170 | }
|
11171 |
|
11172 |
|
11173 | if (stream._readableState.endEmitted) {
|
11174 | return next();
|
11175 | }
|
11176 |
|
11177 | stream.on('merge2UnpipeEnd', onend);
|
11178 | stream.on('end', onend);
|
11179 |
|
11180 | if (doPipeError) {
|
11181 | stream.on('error', onerror);
|
11182 | }
|
11183 |
|
11184 | stream.pipe(mergedStream, {
|
11185 | end: false
|
11186 | });
|
11187 |
|
11188 | stream.resume();
|
11189 | }
|
11190 |
|
11191 | for (let i = 0; i < streams.length; i++) {
|
11192 | pipe(streams[i]);
|
11193 | }
|
11194 |
|
11195 | next();
|
11196 | }
|
11197 |
|
11198 | function endStream() {
|
11199 | merging = false;
|
11200 |
|
11201 | mergedStream.emit('queueDrain');
|
11202 |
|
11203 | if (doEnd) {
|
11204 | mergedStream.end();
|
11205 | }
|
11206 | }
|
11207 |
|
11208 | mergedStream.setMaxListeners(0);
|
11209 | mergedStream.add = addStream;
|
11210 | mergedStream.on('unpipe', function (stream) {
|
11211 | stream.emit('merge2UnpipeEnd');
|
11212 | });
|
11213 |
|
11214 | if (args.length) {
|
11215 | addStream.apply(null, args);
|
11216 | }
|
11217 |
|
11218 | return mergedStream;
|
11219 | }
|
11220 |
|
11221 |
|
11222 | function pauseStreams(streams, options) {
|
11223 | if (!Array.isArray(streams)) {
|
11224 |
|
11225 | if (!streams._readableState && streams.pipe) {
|
11226 | streams = streams.pipe(PassThrough(options));
|
11227 | }
|
11228 |
|
11229 | if (!streams._readableState || !streams.pause || !streams.pipe) {
|
11230 | throw new Error('Only readable stream can be merged.');
|
11231 | }
|
11232 |
|
11233 | streams.pause();
|
11234 | } else {
|
11235 | for (let i = 0, len = streams.length; i < len; i++) {
|
11236 | streams[i] = pauseStreams(streams[i], options);
|
11237 | }
|
11238 | }
|
11239 |
|
11240 | return streams;
|
11241 | }
|
11242 |
|
11243 | var stream = createCommonjsModule(function (module, exports) {
|
11244 |
|
11245 | Object.defineProperty(exports, "__esModule", {
|
11246 | value: true
|
11247 | });
|
11248 | exports.merge = void 0;
|
11249 |
|
11250 | function merge(streams) {
|
11251 | const mergedStream = merge2_1(streams);
|
11252 | streams.forEach(stream => {
|
11253 | stream.once('error', error => mergedStream.emit('error', error));
|
11254 | });
|
11255 | mergedStream.once('close', () => propagateCloseEventToSources(streams));
|
11256 | mergedStream.once('end', () => propagateCloseEventToSources(streams));
|
11257 | return mergedStream;
|
11258 | }
|
11259 |
|
11260 | exports.merge = merge;
|
11261 |
|
11262 | function propagateCloseEventToSources(streams) {
|
11263 | streams.forEach(stream => stream.emit('close'));
|
11264 | }
|
11265 | });
|
11266 |
|
11267 | var string = createCommonjsModule(function (module, exports) {
|
11268 |
|
11269 | Object.defineProperty(exports, "__esModule", {
|
11270 | value: true
|
11271 | });
|
11272 | exports.isEmpty = exports.isString = void 0;
|
11273 |
|
11274 | function isString(input) {
|
11275 | return typeof input === 'string';
|
11276 | }
|
11277 |
|
11278 | exports.isString = isString;
|
11279 |
|
11280 | function isEmpty(input) {
|
11281 | return input === '';
|
11282 | }
|
11283 |
|
11284 | exports.isEmpty = isEmpty;
|
11285 | });
|
11286 |
|
11287 | var utils$2 = createCommonjsModule(function (module, exports) {
|
11288 |
|
11289 | Object.defineProperty(exports, "__esModule", {
|
11290 | value: true
|
11291 | });
|
11292 | exports.string = exports.stream = exports.pattern = exports.path = exports.fs = exports.errno = exports.array = void 0;
|
11293 | exports.array = array;
|
11294 | exports.errno = errno;
|
11295 | exports.fs = fs;
|
11296 | exports.path = path_1;
|
11297 | exports.pattern = pattern;
|
11298 | exports.stream = stream;
|
11299 | exports.string = string;
|
11300 | });
|
11301 |
|
11302 | var tasks = createCommonjsModule(function (module, exports) {
|
11303 |
|
11304 | Object.defineProperty(exports, "__esModule", {
|
11305 | value: true
|
11306 | });
|
11307 | exports.convertPatternGroupToTask = exports.convertPatternGroupsToTasks = exports.groupPatternsByBaseDirectory = exports.getNegativePatternsAsPositive = exports.getPositivePatterns = exports.convertPatternsToTasks = exports.generate = void 0;
|
11308 |
|
11309 | function generate(patterns, settings) {
|
11310 | const positivePatterns = getPositivePatterns(patterns);
|
11311 | const negativePatterns = getNegativePatternsAsPositive(patterns, settings.ignore);
|
11312 | const staticPatterns = positivePatterns.filter(pattern => utils$2.pattern.isStaticPattern(pattern, settings));
|
11313 | const dynamicPatterns = positivePatterns.filter(pattern => utils$2.pattern.isDynamicPattern(pattern, settings));
|
11314 | const staticTasks = convertPatternsToTasks(staticPatterns, negativePatterns,
|
11315 |
|
11316 | false);
|
11317 | const dynamicTasks = convertPatternsToTasks(dynamicPatterns, negativePatterns,
|
11318 |
|
11319 | true);
|
11320 | return staticTasks.concat(dynamicTasks);
|
11321 | }
|
11322 |
|
11323 | exports.generate = generate;
|
11324 |
|
11325 | function convertPatternsToTasks(positive, negative, dynamic) {
|
11326 | const positivePatternsGroup = groupPatternsByBaseDirectory(positive);
|
11327 |
|
11328 |
|
11329 | if ('.' in positivePatternsGroup) {
|
11330 | const task = convertPatternGroupToTask('.', positive, negative, dynamic);
|
11331 | return [task];
|
11332 | }
|
11333 |
|
11334 | return convertPatternGroupsToTasks(positivePatternsGroup, negative, dynamic);
|
11335 | }
|
11336 |
|
11337 | exports.convertPatternsToTasks = convertPatternsToTasks;
|
11338 |
|
11339 | function getPositivePatterns(patterns) {
|
11340 | return utils$2.pattern.getPositivePatterns(patterns);
|
11341 | }
|
11342 |
|
11343 | exports.getPositivePatterns = getPositivePatterns;
|
11344 |
|
11345 | function getNegativePatternsAsPositive(patterns, ignore) {
|
11346 | const negative = utils$2.pattern.getNegativePatterns(patterns).concat(ignore);
|
11347 | const positive = negative.map(utils$2.pattern.convertToPositivePattern);
|
11348 | return positive;
|
11349 | }
|
11350 |
|
11351 | exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
|
11352 |
|
11353 | function groupPatternsByBaseDirectory(patterns) {
|
11354 | const group = {};
|
11355 | return patterns.reduce((collection, pattern) => {
|
11356 | const base = utils$2.pattern.getBaseDirectory(pattern);
|
11357 |
|
11358 | if (base in collection) {
|
11359 | collection[base].push(pattern);
|
11360 | } else {
|
11361 | collection[base] = [pattern];
|
11362 | }
|
11363 |
|
11364 | return collection;
|
11365 | }, group);
|
11366 | }
|
11367 |
|
11368 | exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
|
11369 |
|
11370 | function convertPatternGroupsToTasks(positive, negative, dynamic) {
|
11371 | return Object.keys(positive).map(base => {
|
11372 | return convertPatternGroupToTask(base, positive[base], negative, dynamic);
|
11373 | });
|
11374 | }
|
11375 |
|
11376 | exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
|
11377 |
|
11378 | function convertPatternGroupToTask(base, positive, negative, dynamic) {
|
11379 | return {
|
11380 | dynamic,
|
11381 | positive,
|
11382 | negative,
|
11383 | base,
|
11384 | patterns: [].concat(positive, negative.map(utils$2.pattern.convertToNegativePattern))
|
11385 | };
|
11386 | }
|
11387 |
|
11388 | exports.convertPatternGroupToTask = convertPatternGroupToTask;
|
11389 | });
|
11390 |
|
11391 | var async = createCommonjsModule(function (module, exports) {
|
11392 |
|
11393 | Object.defineProperty(exports, "__esModule", {
|
11394 | value: true
|
11395 | });
|
11396 |
|
11397 | function read(path, settings, callback) {
|
11398 | settings.fs.lstat(path, (lstatError, lstat) => {
|
11399 | if (lstatError !== null) {
|
11400 | return callFailureCallback(callback, lstatError);
|
11401 | }
|
11402 |
|
11403 | if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
|
11404 | return callSuccessCallback(callback, lstat);
|
11405 | }
|
11406 |
|
11407 | settings.fs.stat(path, (statError, stat) => {
|
11408 | if (statError !== null) {
|
11409 | if (settings.throwErrorOnBrokenSymbolicLink) {
|
11410 | return callFailureCallback(callback, statError);
|
11411 | }
|
11412 |
|
11413 | return callSuccessCallback(callback, lstat);
|
11414 | }
|
11415 |
|
11416 | if (settings.markSymbolicLink) {
|
11417 | stat.isSymbolicLink = () => true;
|
11418 | }
|
11419 |
|
11420 | callSuccessCallback(callback, stat);
|
11421 | });
|
11422 | });
|
11423 | }
|
11424 |
|
11425 | exports.read = read;
|
11426 |
|
11427 | function callFailureCallback(callback, error) {
|
11428 | callback(error);
|
11429 | }
|
11430 |
|
11431 | function callSuccessCallback(callback, result) {
|
11432 | callback(null, result);
|
11433 | }
|
11434 | });
|
11435 |
|
11436 | var sync = createCommonjsModule(function (module, exports) {
|
11437 |
|
11438 | Object.defineProperty(exports, "__esModule", {
|
11439 | value: true
|
11440 | });
|
11441 |
|
11442 | function read(path, settings) {
|
11443 | const lstat = settings.fs.lstatSync(path);
|
11444 |
|
11445 | if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
|
11446 | return lstat;
|
11447 | }
|
11448 |
|
11449 | try {
|
11450 | const stat = settings.fs.statSync(path);
|
11451 |
|
11452 | if (settings.markSymbolicLink) {
|
11453 | stat.isSymbolicLink = () => true;
|
11454 | }
|
11455 |
|
11456 | return stat;
|
11457 | } catch (error) {
|
11458 | if (!settings.throwErrorOnBrokenSymbolicLink) {
|
11459 | return lstat;
|
11460 | }
|
11461 |
|
11462 | throw error;
|
11463 | }
|
11464 | }
|
11465 |
|
11466 | exports.read = read;
|
11467 | });
|
11468 |
|
11469 | var fs_1 = createCommonjsModule(function (module, exports) {
|
11470 |
|
11471 | Object.defineProperty(exports, "__esModule", {
|
11472 | value: true
|
11473 | });
|
11474 | exports.FILE_SYSTEM_ADAPTER = {
|
11475 | lstat: fs__default['default'].lstat,
|
11476 | stat: fs__default['default'].stat,
|
11477 | lstatSync: fs__default['default'].lstatSync,
|
11478 | statSync: fs__default['default'].statSync
|
11479 | };
|
11480 |
|
11481 | function createFileSystemAdapter(fsMethods) {
|
11482 | if (fsMethods === undefined) {
|
11483 | return exports.FILE_SYSTEM_ADAPTER;
|
11484 | }
|
11485 |
|
11486 | return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
|
11487 | }
|
11488 |
|
11489 | exports.createFileSystemAdapter = createFileSystemAdapter;
|
11490 | });
|
11491 |
|
11492 | var settings = createCommonjsModule(function (module, exports) {
|
11493 |
|
11494 | Object.defineProperty(exports, "__esModule", {
|
11495 | value: true
|
11496 | });
|
11497 |
|
11498 | class Settings {
|
11499 | constructor(_options = {}) {
|
11500 | this._options = _options;
|
11501 | this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
|
11502 | this.fs = fs_1.createFileSystemAdapter(this._options.fs);
|
11503 | this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false);
|
11504 | this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
11505 | }
|
11506 |
|
11507 | _getValue(option, value) {
|
11508 | return option === undefined ? value : option;
|
11509 | }
|
11510 |
|
11511 | }
|
11512 |
|
11513 | exports.default = Settings;
|
11514 | });
|
11515 |
|
11516 | var out = createCommonjsModule(function (module, exports) {
|
11517 |
|
11518 | Object.defineProperty(exports, "__esModule", {
|
11519 | value: true
|
11520 | });
|
11521 | exports.Settings = settings.default;
|
11522 |
|
11523 | function stat(path, optionsOrSettingsOrCallback, callback) {
|
11524 | if (typeof optionsOrSettingsOrCallback === 'function') {
|
11525 | return async.read(path, getSettings(), optionsOrSettingsOrCallback);
|
11526 | }
|
11527 |
|
11528 | async.read(path, getSettings(optionsOrSettingsOrCallback), callback);
|
11529 | }
|
11530 |
|
11531 | exports.stat = stat;
|
11532 |
|
11533 | function statSync(path, optionsOrSettings) {
|
11534 | const settings = getSettings(optionsOrSettings);
|
11535 | return sync.read(path, settings);
|
11536 | }
|
11537 |
|
11538 | exports.statSync = statSync;
|
11539 |
|
11540 | function getSettings(settingsOrOptions = {}) {
|
11541 | if (settingsOrOptions instanceof settings.default) {
|
11542 | return settingsOrOptions;
|
11543 | }
|
11544 |
|
11545 | return new settings.default(settingsOrOptions);
|
11546 | }
|
11547 | });
|
11548 |
|
11549 | var runParallel_1 = runParallel;
|
11550 |
|
11551 | function runParallel(tasks, cb) {
|
11552 | var results, pending, keys;
|
11553 | var isSync = true;
|
11554 |
|
11555 | if (Array.isArray(tasks)) {
|
11556 | results = [];
|
11557 | pending = tasks.length;
|
11558 | } else {
|
11559 | keys = Object.keys(tasks);
|
11560 | results = {};
|
11561 | pending = keys.length;
|
11562 | }
|
11563 |
|
11564 | function done(err) {
|
11565 | function end() {
|
11566 | if (cb) cb(err, results);
|
11567 | cb = null;
|
11568 | }
|
11569 |
|
11570 | if (isSync) process.nextTick(end);else end();
|
11571 | }
|
11572 |
|
11573 | function each(i, err, result) {
|
11574 | results[i] = result;
|
11575 |
|
11576 | if (--pending === 0 || err) {
|
11577 | done(err);
|
11578 | }
|
11579 | }
|
11580 |
|
11581 | if (!pending) {
|
11582 |
|
11583 | done(null);
|
11584 | } else if (keys) {
|
11585 |
|
11586 | keys.forEach(function (key) {
|
11587 | tasks[key](function (err, result) {
|
11588 | each(key, err, result);
|
11589 | });
|
11590 | });
|
11591 | } else {
|
11592 |
|
11593 | tasks.forEach(function (task, i) {
|
11594 | task(function (err, result) {
|
11595 | each(i, err, result);
|
11596 | });
|
11597 | });
|
11598 | }
|
11599 |
|
11600 | isSync = false;
|
11601 | }
|
11602 |
|
11603 | var constants$2 = createCommonjsModule(function (module, exports) {
|
11604 |
|
11605 | Object.defineProperty(exports, "__esModule", {
|
11606 | value: true
|
11607 | });
|
11608 | const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');
|
11609 | const MAJOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
|
11610 | const MINOR_VERSION = parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);
|
11611 | const SUPPORTED_MAJOR_VERSION = 10;
|
11612 | const SUPPORTED_MINOR_VERSION = 10;
|
11613 | const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
|
11614 | const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
|
11615 | |
11616 |
|
11617 |
|
11618 |
|
11619 | exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
|
11620 | });
|
11621 |
|
11622 | var fs$1 = createCommonjsModule(function (module, exports) {
|
11623 |
|
11624 | Object.defineProperty(exports, "__esModule", {
|
11625 | value: true
|
11626 | });
|
11627 |
|
11628 | class DirentFromStats {
|
11629 | constructor(name, stats) {
|
11630 | this.name = name;
|
11631 | this.isBlockDevice = stats.isBlockDevice.bind(stats);
|
11632 | this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
|
11633 | this.isDirectory = stats.isDirectory.bind(stats);
|
11634 | this.isFIFO = stats.isFIFO.bind(stats);
|
11635 | this.isFile = stats.isFile.bind(stats);
|
11636 | this.isSocket = stats.isSocket.bind(stats);
|
11637 | this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
|
11638 | }
|
11639 |
|
11640 | }
|
11641 |
|
11642 | function createDirentFromStats(name, stats) {
|
11643 | return new DirentFromStats(name, stats);
|
11644 | }
|
11645 |
|
11646 | exports.createDirentFromStats = createDirentFromStats;
|
11647 | });
|
11648 |
|
11649 | var utils$3 = createCommonjsModule(function (module, exports) {
|
11650 |
|
11651 | Object.defineProperty(exports, "__esModule", {
|
11652 | value: true
|
11653 | });
|
11654 | exports.fs = fs$1;
|
11655 | });
|
11656 |
|
11657 | var async$1 = createCommonjsModule(function (module, exports) {
|
11658 |
|
11659 | Object.defineProperty(exports, "__esModule", {
|
11660 | value: true
|
11661 | });
|
11662 |
|
11663 | function read(directory, settings, callback) {
|
11664 | if (!settings.stats && constants$2.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
|
11665 | return readdirWithFileTypes(directory, settings, callback);
|
11666 | }
|
11667 |
|
11668 | return readdir(directory, settings, callback);
|
11669 | }
|
11670 |
|
11671 | exports.read = read;
|
11672 |
|
11673 | function readdirWithFileTypes(directory, settings, callback) {
|
11674 | settings.fs.readdir(directory, {
|
11675 | withFileTypes: true
|
11676 | }, (readdirError, dirents) => {
|
11677 | if (readdirError !== null) {
|
11678 | return callFailureCallback(callback, readdirError);
|
11679 | }
|
11680 |
|
11681 | const entries = dirents.map(dirent => ({
|
11682 | dirent,
|
11683 | name: dirent.name,
|
11684 | path: `${directory}${settings.pathSegmentSeparator}${dirent.name}`
|
11685 | }));
|
11686 |
|
11687 | if (!settings.followSymbolicLinks) {
|
11688 | return callSuccessCallback(callback, entries);
|
11689 | }
|
11690 |
|
11691 | const tasks = entries.map(entry => makeRplTaskEntry(entry, settings));
|
11692 | runParallel_1(tasks, (rplError, rplEntries) => {
|
11693 | if (rplError !== null) {
|
11694 | return callFailureCallback(callback, rplError);
|
11695 | }
|
11696 |
|
11697 | callSuccessCallback(callback, rplEntries);
|
11698 | });
|
11699 | });
|
11700 | }
|
11701 |
|
11702 | exports.readdirWithFileTypes = readdirWithFileTypes;
|
11703 |
|
11704 | function makeRplTaskEntry(entry, settings) {
|
11705 | return done => {
|
11706 | if (!entry.dirent.isSymbolicLink()) {
|
11707 | return done(null, entry);
|
11708 | }
|
11709 |
|
11710 | settings.fs.stat(entry.path, (statError, stats) => {
|
11711 | if (statError !== null) {
|
11712 | if (settings.throwErrorOnBrokenSymbolicLink) {
|
11713 | return done(statError);
|
11714 | }
|
11715 |
|
11716 | return done(null, entry);
|
11717 | }
|
11718 |
|
11719 | entry.dirent = utils$3.fs.createDirentFromStats(entry.name, stats);
|
11720 | return done(null, entry);
|
11721 | });
|
11722 | };
|
11723 | }
|
11724 |
|
11725 | function readdir(directory, settings, callback) {
|
11726 | settings.fs.readdir(directory, (readdirError, names) => {
|
11727 | if (readdirError !== null) {
|
11728 | return callFailureCallback(callback, readdirError);
|
11729 | }
|
11730 |
|
11731 | const filepaths = names.map(name => `${directory}${settings.pathSegmentSeparator}${name}`);
|
11732 | const tasks = filepaths.map(filepath => {
|
11733 | return done => out.stat(filepath, settings.fsStatSettings, done);
|
11734 | });
|
11735 | runParallel_1(tasks, (rplError, results) => {
|
11736 | if (rplError !== null) {
|
11737 | return callFailureCallback(callback, rplError);
|
11738 | }
|
11739 |
|
11740 | const entries = [];
|
11741 | names.forEach((name, index) => {
|
11742 | const stats = results[index];
|
11743 | const entry = {
|
11744 | name,
|
11745 | path: filepaths[index],
|
11746 | dirent: utils$3.fs.createDirentFromStats(name, stats)
|
11747 | };
|
11748 |
|
11749 | if (settings.stats) {
|
11750 | entry.stats = stats;
|
11751 | }
|
11752 |
|
11753 | entries.push(entry);
|
11754 | });
|
11755 | callSuccessCallback(callback, entries);
|
11756 | });
|
11757 | });
|
11758 | }
|
11759 |
|
11760 | exports.readdir = readdir;
|
11761 |
|
11762 | function callFailureCallback(callback, error) {
|
11763 | callback(error);
|
11764 | }
|
11765 |
|
11766 | function callSuccessCallback(callback, result) {
|
11767 | callback(null, result);
|
11768 | }
|
11769 | });
|
11770 |
|
11771 | var sync$1 = createCommonjsModule(function (module, exports) {
|
11772 |
|
11773 | Object.defineProperty(exports, "__esModule", {
|
11774 | value: true
|
11775 | });
|
11776 |
|
11777 | function read(directory, settings) {
|
11778 | if (!settings.stats && constants$2.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
|
11779 | return readdirWithFileTypes(directory, settings);
|
11780 | }
|
11781 |
|
11782 | return readdir(directory, settings);
|
11783 | }
|
11784 |
|
11785 | exports.read = read;
|
11786 |
|
11787 | function readdirWithFileTypes(directory, settings) {
|
11788 | const dirents = settings.fs.readdirSync(directory, {
|
11789 | withFileTypes: true
|
11790 | });
|
11791 | return dirents.map(dirent => {
|
11792 | const entry = {
|
11793 | dirent,
|
11794 | name: dirent.name,
|
11795 | path: `${directory}${settings.pathSegmentSeparator}${dirent.name}`
|
11796 | };
|
11797 |
|
11798 | if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) {
|
11799 | try {
|
11800 | const stats = settings.fs.statSync(entry.path);
|
11801 | entry.dirent = utils$3.fs.createDirentFromStats(entry.name, stats);
|
11802 | } catch (error) {
|
11803 | if (settings.throwErrorOnBrokenSymbolicLink) {
|
11804 | throw error;
|
11805 | }
|
11806 | }
|
11807 | }
|
11808 |
|
11809 | return entry;
|
11810 | });
|
11811 | }
|
11812 |
|
11813 | exports.readdirWithFileTypes = readdirWithFileTypes;
|
11814 |
|
11815 | function readdir(directory, settings) {
|
11816 | const names = settings.fs.readdirSync(directory);
|
11817 | return names.map(name => {
|
11818 | const entryPath = `${directory}${settings.pathSegmentSeparator}${name}`;
|
11819 | const stats = out.statSync(entryPath, settings.fsStatSettings);
|
11820 | const entry = {
|
11821 | name,
|
11822 | path: entryPath,
|
11823 | dirent: utils$3.fs.createDirentFromStats(name, stats)
|
11824 | };
|
11825 |
|
11826 | if (settings.stats) {
|
11827 | entry.stats = stats;
|
11828 | }
|
11829 |
|
11830 | return entry;
|
11831 | });
|
11832 | }
|
11833 |
|
11834 | exports.readdir = readdir;
|
11835 | });
|
11836 |
|
11837 | var fs_1$1 = createCommonjsModule(function (module, exports) {
|
11838 |
|
11839 | Object.defineProperty(exports, "__esModule", {
|
11840 | value: true
|
11841 | });
|
11842 | exports.FILE_SYSTEM_ADAPTER = {
|
11843 | lstat: fs__default['default'].lstat,
|
11844 | stat: fs__default['default'].stat,
|
11845 | lstatSync: fs__default['default'].lstatSync,
|
11846 | statSync: fs__default['default'].statSync,
|
11847 | readdir: fs__default['default'].readdir,
|
11848 | readdirSync: fs__default['default'].readdirSync
|
11849 | };
|
11850 |
|
11851 | function createFileSystemAdapter(fsMethods) {
|
11852 | if (fsMethods === undefined) {
|
11853 | return exports.FILE_SYSTEM_ADAPTER;
|
11854 | }
|
11855 |
|
11856 | return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
|
11857 | }
|
11858 |
|
11859 | exports.createFileSystemAdapter = createFileSystemAdapter;
|
11860 | });
|
11861 |
|
11862 | var settings$1 = createCommonjsModule(function (module, exports) {
|
11863 |
|
11864 | Object.defineProperty(exports, "__esModule", {
|
11865 | value: true
|
11866 | });
|
11867 |
|
11868 | class Settings {
|
11869 | constructor(_options = {}) {
|
11870 | this._options = _options;
|
11871 | this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
|
11872 | this.fs = fs_1$1.createFileSystemAdapter(this._options.fs);
|
11873 | this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path__default['default'].sep);
|
11874 | this.stats = this._getValue(this._options.stats, false);
|
11875 | this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
11876 | this.fsStatSettings = new out.Settings({
|
11877 | followSymbolicLink: this.followSymbolicLinks,
|
11878 | fs: this.fs,
|
11879 | throwErrorOnBrokenSymbolicLink: this.throwErrorOnBrokenSymbolicLink
|
11880 | });
|
11881 | }
|
11882 |
|
11883 | _getValue(option, value) {
|
11884 | return option === undefined ? value : option;
|
11885 | }
|
11886 |
|
11887 | }
|
11888 |
|
11889 | exports.default = Settings;
|
11890 | });
|
11891 |
|
11892 | var out$1 = createCommonjsModule(function (module, exports) {
|
11893 |
|
11894 | Object.defineProperty(exports, "__esModule", {
|
11895 | value: true
|
11896 | });
|
11897 | exports.Settings = settings$1.default;
|
11898 |
|
11899 | function scandir(path, optionsOrSettingsOrCallback, callback) {
|
11900 | if (typeof optionsOrSettingsOrCallback === 'function') {
|
11901 | return async$1.read(path, getSettings(), optionsOrSettingsOrCallback);
|
11902 | }
|
11903 |
|
11904 | async$1.read(path, getSettings(optionsOrSettingsOrCallback), callback);
|
11905 | }
|
11906 |
|
11907 | exports.scandir = scandir;
|
11908 |
|
11909 | function scandirSync(path, optionsOrSettings) {
|
11910 | const settings = getSettings(optionsOrSettings);
|
11911 | return sync$1.read(path, settings);
|
11912 | }
|
11913 |
|
11914 | exports.scandirSync = scandirSync;
|
11915 |
|
11916 | function getSettings(settingsOrOptions = {}) {
|
11917 | if (settingsOrOptions instanceof settings$1.default) {
|
11918 | return settingsOrOptions;
|
11919 | }
|
11920 |
|
11921 | return new settings$1.default(settingsOrOptions);
|
11922 | }
|
11923 | });
|
11924 |
|
11925 | function reusify(Constructor) {
|
11926 | var head = new Constructor();
|
11927 | var tail = head;
|
11928 |
|
11929 | function get() {
|
11930 | var current = head;
|
11931 |
|
11932 | if (current.next) {
|
11933 | head = current.next;
|
11934 | } else {
|
11935 | head = new Constructor();
|
11936 | tail = head;
|
11937 | }
|
11938 |
|
11939 | current.next = null;
|
11940 | return current;
|
11941 | }
|
11942 |
|
11943 | function release(obj) {
|
11944 | tail.next = obj;
|
11945 | tail = obj;
|
11946 | }
|
11947 |
|
11948 | return {
|
11949 | get: get,
|
11950 | release: release
|
11951 | };
|
11952 | }
|
11953 |
|
11954 | var reusify_1 = reusify;
|
11955 |
|
11956 | function fastqueue(context, worker, concurrency) {
|
11957 | if (typeof context === 'function') {
|
11958 | concurrency = worker;
|
11959 | worker = context;
|
11960 | context = null;
|
11961 | }
|
11962 |
|
11963 | var cache = reusify_1(Task);
|
11964 | var queueHead = null;
|
11965 | var queueTail = null;
|
11966 | var _running = 0;
|
11967 | var self = {
|
11968 | push: push,
|
11969 | drain: noop,
|
11970 | saturated: noop,
|
11971 | pause: pause,
|
11972 | paused: false,
|
11973 | concurrency: concurrency,
|
11974 | running: running,
|
11975 | resume: resume,
|
11976 | idle: idle,
|
11977 | length: length,
|
11978 | getQueue: getQueue,
|
11979 | unshift: unshift,
|
11980 | empty: noop,
|
11981 | kill: kill,
|
11982 | killAndDrain: killAndDrain
|
11983 | };
|
11984 | return self;
|
11985 |
|
11986 | function running() {
|
11987 | return _running;
|
11988 | }
|
11989 |
|
11990 | function pause() {
|
11991 | self.paused = true;
|
11992 | }
|
11993 |
|
11994 | function length() {
|
11995 | var current = queueHead;
|
11996 | var counter = 0;
|
11997 |
|
11998 | while (current) {
|
11999 | current = current.next;
|
12000 | counter++;
|
12001 | }
|
12002 |
|
12003 | return counter;
|
12004 | }
|
12005 |
|
12006 | function getQueue() {
|
12007 | var current = queueHead;
|
12008 | var tasks = [];
|
12009 |
|
12010 | while (current) {
|
12011 | tasks.push(current.value);
|
12012 | current = current.next;
|
12013 | }
|
12014 |
|
12015 | return tasks;
|
12016 | }
|
12017 |
|
12018 | function resume() {
|
12019 | if (!self.paused) return;
|
12020 | self.paused = false;
|
12021 |
|
12022 | for (var i = 0; i < self.concurrency; i++) {
|
12023 | _running++;
|
12024 | release();
|
12025 | }
|
12026 | }
|
12027 |
|
12028 | function idle() {
|
12029 | return _running === 0 && self.length() === 0;
|
12030 | }
|
12031 |
|
12032 | function push(value, done) {
|
12033 | var current = cache.get();
|
12034 | current.context = context;
|
12035 | current.release = release;
|
12036 | current.value = value;
|
12037 | current.callback = done || noop;
|
12038 |
|
12039 | if (_running === self.concurrency || self.paused) {
|
12040 | if (queueTail) {
|
12041 | queueTail.next = current;
|
12042 | queueTail = current;
|
12043 | } else {
|
12044 | queueHead = current;
|
12045 | queueTail = current;
|
12046 | self.saturated();
|
12047 | }
|
12048 | } else {
|
12049 | _running++;
|
12050 | worker.call(context, current.value, current.worked);
|
12051 | }
|
12052 | }
|
12053 |
|
12054 | function unshift(value, done) {
|
12055 | var current = cache.get();
|
12056 | current.context = context;
|
12057 | current.release = release;
|
12058 | current.value = value;
|
12059 | current.callback = done || noop;
|
12060 |
|
12061 | if (_running === self.concurrency || self.paused) {
|
12062 | if (queueHead) {
|
12063 | current.next = queueHead;
|
12064 | queueHead = current;
|
12065 | } else {
|
12066 | queueHead = current;
|
12067 | queueTail = current;
|
12068 | self.saturated();
|
12069 | }
|
12070 | } else {
|
12071 | _running++;
|
12072 | worker.call(context, current.value, current.worked);
|
12073 | }
|
12074 | }
|
12075 |
|
12076 | function release(holder) {
|
12077 | if (holder) {
|
12078 | cache.release(holder);
|
12079 | }
|
12080 |
|
12081 | var next = queueHead;
|
12082 |
|
12083 | if (next) {
|
12084 | if (!self.paused) {
|
12085 | if (queueTail === queueHead) {
|
12086 | queueTail = null;
|
12087 | }
|
12088 |
|
12089 | queueHead = next.next;
|
12090 | next.next = null;
|
12091 | worker.call(context, next.value, next.worked);
|
12092 |
|
12093 | if (queueTail === null) {
|
12094 | self.empty();
|
12095 | }
|
12096 | } else {
|
12097 | _running--;
|
12098 | }
|
12099 | } else if (--_running === 0) {
|
12100 | self.drain();
|
12101 | }
|
12102 | }
|
12103 |
|
12104 | function kill() {
|
12105 | queueHead = null;
|
12106 | queueTail = null;
|
12107 | self.drain = noop;
|
12108 | }
|
12109 |
|
12110 | function killAndDrain() {
|
12111 | queueHead = null;
|
12112 | queueTail = null;
|
12113 | self.drain();
|
12114 | self.drain = noop;
|
12115 | }
|
12116 | }
|
12117 |
|
12118 | function noop() {}
|
12119 |
|
12120 | function Task() {
|
12121 | this.value = null;
|
12122 | this.callback = noop;
|
12123 | this.next = null;
|
12124 | this.release = noop;
|
12125 | this.context = null;
|
12126 | var self = this;
|
12127 |
|
12128 | this.worked = function worked(err, result) {
|
12129 | var callback = self.callback;
|
12130 | self.value = null;
|
12131 | self.callback = noop;
|
12132 | callback.call(self.context, err, result);
|
12133 | self.release(self);
|
12134 | };
|
12135 | }
|
12136 |
|
12137 | var queue = fastqueue;
|
12138 |
|
12139 | var common = createCommonjsModule(function (module, exports) {
|
12140 |
|
12141 | Object.defineProperty(exports, "__esModule", {
|
12142 | value: true
|
12143 | });
|
12144 |
|
12145 | function isFatalError(settings, error) {
|
12146 | if (settings.errorFilter === null) {
|
12147 | return true;
|
12148 | }
|
12149 |
|
12150 | return !settings.errorFilter(error);
|
12151 | }
|
12152 |
|
12153 | exports.isFatalError = isFatalError;
|
12154 |
|
12155 | function isAppliedFilter(filter, value) {
|
12156 | return filter === null || filter(value);
|
12157 | }
|
12158 |
|
12159 | exports.isAppliedFilter = isAppliedFilter;
|
12160 |
|
12161 | function replacePathSegmentSeparator(filepath, separator) {
|
12162 | return filepath.split(/[\\/]/).join(separator);
|
12163 | }
|
12164 |
|
12165 | exports.replacePathSegmentSeparator = replacePathSegmentSeparator;
|
12166 |
|
12167 | function joinPathSegments(a, b, separator) {
|
12168 | if (a === '') {
|
12169 | return b;
|
12170 | }
|
12171 |
|
12172 | return a + separator + b;
|
12173 | }
|
12174 |
|
12175 | exports.joinPathSegments = joinPathSegments;
|
12176 | });
|
12177 |
|
12178 | var reader = createCommonjsModule(function (module, exports) {
|
12179 |
|
12180 | Object.defineProperty(exports, "__esModule", {
|
12181 | value: true
|
12182 | });
|
12183 |
|
12184 | class Reader {
|
12185 | constructor(_root, _settings) {
|
12186 | this._root = _root;
|
12187 | this._settings = _settings;
|
12188 | this._root = common.replacePathSegmentSeparator(_root, _settings.pathSegmentSeparator);
|
12189 | }
|
12190 |
|
12191 | }
|
12192 |
|
12193 | exports.default = Reader;
|
12194 | });
|
12195 |
|
12196 | var async$2 = createCommonjsModule(function (module, exports) {
|
12197 |
|
12198 | Object.defineProperty(exports, "__esModule", {
|
12199 | value: true
|
12200 | });
|
12201 |
|
12202 | class AsyncReader extends reader.default {
|
12203 | constructor(_root, _settings) {
|
12204 | super(_root, _settings);
|
12205 | this._settings = _settings;
|
12206 | this._scandir = out$1.scandir;
|
12207 | this._emitter = new events_1__default['default'].EventEmitter();
|
12208 | this._queue = queue(this._worker.bind(this), this._settings.concurrency);
|
12209 | this._isFatalError = false;
|
12210 | this._isDestroyed = false;
|
12211 |
|
12212 | this._queue.drain = () => {
|
12213 | if (!this._isFatalError) {
|
12214 | this._emitter.emit('end');
|
12215 | }
|
12216 | };
|
12217 | }
|
12218 |
|
12219 | read() {
|
12220 | this._isFatalError = false;
|
12221 | this._isDestroyed = false;
|
12222 | setImmediate(() => {
|
12223 | this._pushToQueue(this._root, this._settings.basePath);
|
12224 | });
|
12225 | return this._emitter;
|
12226 | }
|
12227 |
|
12228 | destroy() {
|
12229 | if (this._isDestroyed) {
|
12230 | throw new Error('The reader is already destroyed');
|
12231 | }
|
12232 |
|
12233 | this._isDestroyed = true;
|
12234 |
|
12235 | this._queue.killAndDrain();
|
12236 | }
|
12237 |
|
12238 | onEntry(callback) {
|
12239 | this._emitter.on('entry', callback);
|
12240 | }
|
12241 |
|
12242 | onError(callback) {
|
12243 | this._emitter.once('error', callback);
|
12244 | }
|
12245 |
|
12246 | onEnd(callback) {
|
12247 | this._emitter.once('end', callback);
|
12248 | }
|
12249 |
|
12250 | _pushToQueue(directory, base) {
|
12251 | const queueItem = {
|
12252 | directory,
|
12253 | base
|
12254 | };
|
12255 |
|
12256 | this._queue.push(queueItem, error => {
|
12257 | if (error !== null) {
|
12258 | this._handleError(error);
|
12259 | }
|
12260 | });
|
12261 | }
|
12262 |
|
12263 | _worker(item, done) {
|
12264 | this._scandir(item.directory, this._settings.fsScandirSettings, (error, entries) => {
|
12265 | if (error !== null) {
|
12266 | return done(error, undefined);
|
12267 | }
|
12268 |
|
12269 | for (const entry of entries) {
|
12270 | this._handleEntry(entry, item.base);
|
12271 | }
|
12272 |
|
12273 | done(null, undefined);
|
12274 | });
|
12275 | }
|
12276 |
|
12277 | _handleError(error) {
|
12278 | if (!common.isFatalError(this._settings, error)) {
|
12279 | return;
|
12280 | }
|
12281 |
|
12282 | this._isFatalError = true;
|
12283 | this._isDestroyed = true;
|
12284 |
|
12285 | this._emitter.emit('error', error);
|
12286 | }
|
12287 |
|
12288 | _handleEntry(entry, base) {
|
12289 | if (this._isDestroyed || this._isFatalError) {
|
12290 | return;
|
12291 | }
|
12292 |
|
12293 | const fullpath = entry.path;
|
12294 |
|
12295 | if (base !== undefined) {
|
12296 | entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
|
12297 | }
|
12298 |
|
12299 | if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
|
12300 | this._emitEntry(entry);
|
12301 | }
|
12302 |
|
12303 | if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
|
12304 | this._pushToQueue(fullpath, entry.path);
|
12305 | }
|
12306 | }
|
12307 |
|
12308 | _emitEntry(entry) {
|
12309 | this._emitter.emit('entry', entry);
|
12310 | }
|
12311 |
|
12312 | }
|
12313 |
|
12314 | exports.default = AsyncReader;
|
12315 | });
|
12316 |
|
12317 | var async$3 = createCommonjsModule(function (module, exports) {
|
12318 |
|
12319 | Object.defineProperty(exports, "__esModule", {
|
12320 | value: true
|
12321 | });
|
12322 |
|
12323 | class AsyncProvider {
|
12324 | constructor(_root, _settings) {
|
12325 | this._root = _root;
|
12326 | this._settings = _settings;
|
12327 | this._reader = new async$2.default(this._root, this._settings);
|
12328 | this._storage = new Set();
|
12329 | }
|
12330 |
|
12331 | read(callback) {
|
12332 | this._reader.onError(error => {
|
12333 | callFailureCallback(callback, error);
|
12334 | });
|
12335 |
|
12336 | this._reader.onEntry(entry => {
|
12337 | this._storage.add(entry);
|
12338 | });
|
12339 |
|
12340 | this._reader.onEnd(() => {
|
12341 | callSuccessCallback(callback, [...this._storage]);
|
12342 | });
|
12343 |
|
12344 | this._reader.read();
|
12345 | }
|
12346 |
|
12347 | }
|
12348 |
|
12349 | exports.default = AsyncProvider;
|
12350 |
|
12351 | function callFailureCallback(callback, error) {
|
12352 | callback(error);
|
12353 | }
|
12354 |
|
12355 | function callSuccessCallback(callback, entries) {
|
12356 | callback(null, entries);
|
12357 | }
|
12358 | });
|
12359 |
|
12360 | var stream$1 = createCommonjsModule(function (module, exports) {
|
12361 |
|
12362 | Object.defineProperty(exports, "__esModule", {
|
12363 | value: true
|
12364 | });
|
12365 |
|
12366 | class StreamProvider {
|
12367 | constructor(_root, _settings) {
|
12368 | this._root = _root;
|
12369 | this._settings = _settings;
|
12370 | this._reader = new async$2.default(this._root, this._settings);
|
12371 | this._stream = new stream_1__default['default'].Readable({
|
12372 | objectMode: true,
|
12373 | read: () => {},
|
12374 | destroy: this._reader.destroy.bind(this._reader)
|
12375 | });
|
12376 | }
|
12377 |
|
12378 | read() {
|
12379 | this._reader.onError(error => {
|
12380 | this._stream.emit('error', error);
|
12381 | });
|
12382 |
|
12383 | this._reader.onEntry(entry => {
|
12384 | this._stream.push(entry);
|
12385 | });
|
12386 |
|
12387 | this._reader.onEnd(() => {
|
12388 | this._stream.push(null);
|
12389 | });
|
12390 |
|
12391 | this._reader.read();
|
12392 |
|
12393 | return this._stream;
|
12394 | }
|
12395 |
|
12396 | }
|
12397 |
|
12398 | exports.default = StreamProvider;
|
12399 | });
|
12400 |
|
12401 | var sync$2 = createCommonjsModule(function (module, exports) {
|
12402 |
|
12403 | Object.defineProperty(exports, "__esModule", {
|
12404 | value: true
|
12405 | });
|
12406 |
|
12407 | class SyncReader extends reader.default {
|
12408 | constructor() {
|
12409 | super(...arguments);
|
12410 | this._scandir = out$1.scandirSync;
|
12411 | this._storage = new Set();
|
12412 | this._queue = new Set();
|
12413 | }
|
12414 |
|
12415 | read() {
|
12416 | this._pushToQueue(this._root, this._settings.basePath);
|
12417 |
|
12418 | this._handleQueue();
|
12419 |
|
12420 | return [...this._storage];
|
12421 | }
|
12422 |
|
12423 | _pushToQueue(directory, base) {
|
12424 | this._queue.add({
|
12425 | directory,
|
12426 | base
|
12427 | });
|
12428 | }
|
12429 |
|
12430 | _handleQueue() {
|
12431 | for (const item of this._queue.values()) {
|
12432 | this._handleDirectory(item.directory, item.base);
|
12433 | }
|
12434 | }
|
12435 |
|
12436 | _handleDirectory(directory, base) {
|
12437 | try {
|
12438 | const entries = this._scandir(directory, this._settings.fsScandirSettings);
|
12439 |
|
12440 | for (const entry of entries) {
|
12441 | this._handleEntry(entry, base);
|
12442 | }
|
12443 | } catch (error) {
|
12444 | this._handleError(error);
|
12445 | }
|
12446 | }
|
12447 |
|
12448 | _handleError(error) {
|
12449 | if (!common.isFatalError(this._settings, error)) {
|
12450 | return;
|
12451 | }
|
12452 |
|
12453 | throw error;
|
12454 | }
|
12455 |
|
12456 | _handleEntry(entry, base) {
|
12457 | const fullpath = entry.path;
|
12458 |
|
12459 | if (base !== undefined) {
|
12460 | entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
|
12461 | }
|
12462 |
|
12463 | if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
|
12464 | this._pushToStorage(entry);
|
12465 | }
|
12466 |
|
12467 | if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
|
12468 | this._pushToQueue(fullpath, entry.path);
|
12469 | }
|
12470 | }
|
12471 |
|
12472 | _pushToStorage(entry) {
|
12473 | this._storage.add(entry);
|
12474 | }
|
12475 |
|
12476 | }
|
12477 |
|
12478 | exports.default = SyncReader;
|
12479 | });
|
12480 |
|
12481 | var sync$3 = createCommonjsModule(function (module, exports) {
|
12482 |
|
12483 | Object.defineProperty(exports, "__esModule", {
|
12484 | value: true
|
12485 | });
|
12486 |
|
12487 | class SyncProvider {
|
12488 | constructor(_root, _settings) {
|
12489 | this._root = _root;
|
12490 | this._settings = _settings;
|
12491 | this._reader = new sync$2.default(this._root, this._settings);
|
12492 | }
|
12493 |
|
12494 | read() {
|
12495 | return this._reader.read();
|
12496 | }
|
12497 |
|
12498 | }
|
12499 |
|
12500 | exports.default = SyncProvider;
|
12501 | });
|
12502 |
|
12503 | var settings$2 = createCommonjsModule(function (module, exports) {
|
12504 |
|
12505 | Object.defineProperty(exports, "__esModule", {
|
12506 | value: true
|
12507 | });
|
12508 |
|
12509 | class Settings {
|
12510 | constructor(_options = {}) {
|
12511 | this._options = _options;
|
12512 | this.basePath = this._getValue(this._options.basePath, undefined);
|
12513 | this.concurrency = this._getValue(this._options.concurrency, Infinity);
|
12514 | this.deepFilter = this._getValue(this._options.deepFilter, null);
|
12515 | this.entryFilter = this._getValue(this._options.entryFilter, null);
|
12516 | this.errorFilter = this._getValue(this._options.errorFilter, null);
|
12517 | this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path__default['default'].sep);
|
12518 | this.fsScandirSettings = new out$1.Settings({
|
12519 | followSymbolicLinks: this._options.followSymbolicLinks,
|
12520 | fs: this._options.fs,
|
12521 | pathSegmentSeparator: this._options.pathSegmentSeparator,
|
12522 | stats: this._options.stats,
|
12523 | throwErrorOnBrokenSymbolicLink: this._options.throwErrorOnBrokenSymbolicLink
|
12524 | });
|
12525 | }
|
12526 |
|
12527 | _getValue(option, value) {
|
12528 | return option === undefined ? value : option;
|
12529 | }
|
12530 |
|
12531 | }
|
12532 |
|
12533 | exports.default = Settings;
|
12534 | });
|
12535 |
|
12536 | var out$2 = createCommonjsModule(function (module, exports) {
|
12537 |
|
12538 | Object.defineProperty(exports, "__esModule", {
|
12539 | value: true
|
12540 | });
|
12541 | exports.Settings = settings$2.default;
|
12542 |
|
12543 | function walk(directory, optionsOrSettingsOrCallback, callback) {
|
12544 | if (typeof optionsOrSettingsOrCallback === 'function') {
|
12545 | return new async$3.default(directory, getSettings()).read(optionsOrSettingsOrCallback);
|
12546 | }
|
12547 |
|
12548 | new async$3.default(directory, getSettings(optionsOrSettingsOrCallback)).read(callback);
|
12549 | }
|
12550 |
|
12551 | exports.walk = walk;
|
12552 |
|
12553 | function walkSync(directory, optionsOrSettings) {
|
12554 | const settings = getSettings(optionsOrSettings);
|
12555 | const provider = new sync$3.default(directory, settings);
|
12556 | return provider.read();
|
12557 | }
|
12558 |
|
12559 | exports.walkSync = walkSync;
|
12560 |
|
12561 | function walkStream(directory, optionsOrSettings) {
|
12562 | const settings = getSettings(optionsOrSettings);
|
12563 | const provider = new stream$1.default(directory, settings);
|
12564 | return provider.read();
|
12565 | }
|
12566 |
|
12567 | exports.walkStream = walkStream;
|
12568 |
|
12569 | function getSettings(settingsOrOptions = {}) {
|
12570 | if (settingsOrOptions instanceof settings$2.default) {
|
12571 | return settingsOrOptions;
|
12572 | }
|
12573 |
|
12574 | return new settings$2.default(settingsOrOptions);
|
12575 | }
|
12576 | });
|
12577 |
|
12578 | var reader$1 = createCommonjsModule(function (module, exports) {
|
12579 |
|
12580 | Object.defineProperty(exports, "__esModule", {
|
12581 | value: true
|
12582 | });
|
12583 |
|
12584 | class Reader {
|
12585 | constructor(_settings) {
|
12586 | this._settings = _settings;
|
12587 | this._fsStatSettings = new out.Settings({
|
12588 | followSymbolicLink: this._settings.followSymbolicLinks,
|
12589 | fs: this._settings.fs,
|
12590 | throwErrorOnBrokenSymbolicLink: this._settings.followSymbolicLinks
|
12591 | });
|
12592 | }
|
12593 |
|
12594 | _getFullEntryPath(filepath) {
|
12595 | return path__default['default'].resolve(this._settings.cwd, filepath);
|
12596 | }
|
12597 |
|
12598 | _makeEntry(stats, pattern) {
|
12599 | const entry = {
|
12600 | name: pattern,
|
12601 | path: pattern,
|
12602 | dirent: utils$2.fs.createDirentFromStats(pattern, stats)
|
12603 | };
|
12604 |
|
12605 | if (this._settings.stats) {
|
12606 | entry.stats = stats;
|
12607 | }
|
12608 |
|
12609 | return entry;
|
12610 | }
|
12611 |
|
12612 | _isFatalError(error) {
|
12613 | return !utils$2.errno.isEnoentCodeError(error) && !this._settings.suppressErrors;
|
12614 | }
|
12615 |
|
12616 | }
|
12617 |
|
12618 | exports.default = Reader;
|
12619 | });
|
12620 |
|
12621 | var stream$2 = createCommonjsModule(function (module, exports) {
|
12622 |
|
12623 | Object.defineProperty(exports, "__esModule", {
|
12624 | value: true
|
12625 | });
|
12626 |
|
12627 | class ReaderStream extends reader$1.default {
|
12628 | constructor() {
|
12629 | super(...arguments);
|
12630 | this._walkStream = out$2.walkStream;
|
12631 | this._stat = out.stat;
|
12632 | }
|
12633 |
|
12634 | dynamic(root, options) {
|
12635 | return this._walkStream(root, options);
|
12636 | }
|
12637 |
|
12638 | static(patterns, options) {
|
12639 | const filepaths = patterns.map(this._getFullEntryPath, this);
|
12640 | const stream = new stream_1__default['default'].PassThrough({
|
12641 | objectMode: true
|
12642 | });
|
12643 |
|
12644 | stream._write = (index, _enc, done) => {
|
12645 | return this._getEntry(filepaths[index], patterns[index], options).then(entry => {
|
12646 | if (entry !== null && options.entryFilter(entry)) {
|
12647 | stream.push(entry);
|
12648 | }
|
12649 |
|
12650 | if (index === filepaths.length - 1) {
|
12651 | stream.end();
|
12652 | }
|
12653 |
|
12654 | done();
|
12655 | }).catch(done);
|
12656 | };
|
12657 |
|
12658 | for (let i = 0; i < filepaths.length; i++) {
|
12659 | stream.write(i);
|
12660 | }
|
12661 |
|
12662 | return stream;
|
12663 | }
|
12664 |
|
12665 | _getEntry(filepath, pattern, options) {
|
12666 | return this._getStat(filepath).then(stats => this._makeEntry(stats, pattern)).catch(error => {
|
12667 | if (options.errorFilter(error)) {
|
12668 | return null;
|
12669 | }
|
12670 |
|
12671 | throw error;
|
12672 | });
|
12673 | }
|
12674 |
|
12675 | _getStat(filepath) {
|
12676 | return new Promise((resolve, reject) => {
|
12677 | this._stat(filepath, this._fsStatSettings, (error, stats) => {
|
12678 | return error === null ? resolve(stats) : reject(error);
|
12679 | });
|
12680 | });
|
12681 | }
|
12682 |
|
12683 | }
|
12684 |
|
12685 | exports.default = ReaderStream;
|
12686 | });
|
12687 |
|
12688 | var matcher = createCommonjsModule(function (module, exports) {
|
12689 |
|
12690 | Object.defineProperty(exports, "__esModule", {
|
12691 | value: true
|
12692 | });
|
12693 |
|
12694 | class Matcher {
|
12695 | constructor(_patterns, _settings, _micromatchOptions) {
|
12696 | this._patterns = _patterns;
|
12697 | this._settings = _settings;
|
12698 | this._micromatchOptions = _micromatchOptions;
|
12699 | this._storage = [];
|
12700 |
|
12701 | this._fillStorage();
|
12702 | }
|
12703 |
|
12704 | _fillStorage() {
|
12705 | |
12706 |
|
12707 |
|
12708 |
|
12709 | const patterns = utils$2.pattern.expandPatternsWithBraceExpansion(this._patterns);
|
12710 |
|
12711 | for (const pattern of patterns) {
|
12712 | const segments = this._getPatternSegments(pattern);
|
12713 |
|
12714 | const sections = this._splitSegmentsIntoSections(segments);
|
12715 |
|
12716 | this._storage.push({
|
12717 | complete: sections.length <= 1,
|
12718 | pattern,
|
12719 | segments,
|
12720 | sections
|
12721 | });
|
12722 | }
|
12723 | }
|
12724 |
|
12725 | _getPatternSegments(pattern) {
|
12726 | const parts = utils$2.pattern.getPatternParts(pattern, this._micromatchOptions);
|
12727 | return parts.map(part => {
|
12728 | const dynamic = utils$2.pattern.isDynamicPattern(part, this._settings);
|
12729 |
|
12730 | if (!dynamic) {
|
12731 | return {
|
12732 | dynamic: false,
|
12733 | pattern: part
|
12734 | };
|
12735 | }
|
12736 |
|
12737 | return {
|
12738 | dynamic: true,
|
12739 | pattern: part,
|
12740 | patternRe: utils$2.pattern.makeRe(part, this._micromatchOptions)
|
12741 | };
|
12742 | });
|
12743 | }
|
12744 |
|
12745 | _splitSegmentsIntoSections(segments) {
|
12746 | return utils$2.array.splitWhen(segments, segment => segment.dynamic && utils$2.pattern.hasGlobStar(segment.pattern));
|
12747 | }
|
12748 |
|
12749 | }
|
12750 |
|
12751 | exports.default = Matcher;
|
12752 | });
|
12753 |
|
12754 | var partial = createCommonjsModule(function (module, exports) {
|
12755 |
|
12756 | Object.defineProperty(exports, "__esModule", {
|
12757 | value: true
|
12758 | });
|
12759 |
|
12760 | class PartialMatcher extends matcher.default {
|
12761 | match(filepath) {
|
12762 | const parts = filepath.split('/');
|
12763 | const levels = parts.length;
|
12764 |
|
12765 | const patterns = this._storage.filter(info => !info.complete || info.segments.length > levels);
|
12766 |
|
12767 | for (const pattern of patterns) {
|
12768 | const section = pattern.sections[0];
|
12769 | |
12770 |
|
12771 |
|
12772 |
|
12773 |
|
12774 |
|
12775 |
|
12776 |
|
12777 | if (!pattern.complete && levels > section.length) {
|
12778 | return true;
|
12779 | }
|
12780 |
|
12781 | const match = parts.every((part, index) => {
|
12782 | const segment = pattern.segments[index];
|
12783 |
|
12784 | if (segment.dynamic && segment.patternRe.test(part)) {
|
12785 | return true;
|
12786 | }
|
12787 |
|
12788 | if (!segment.dynamic && segment.pattern === part) {
|
12789 | return true;
|
12790 | }
|
12791 |
|
12792 | return false;
|
12793 | });
|
12794 |
|
12795 | if (match) {
|
12796 | return true;
|
12797 | }
|
12798 | }
|
12799 |
|
12800 | return false;
|
12801 | }
|
12802 |
|
12803 | }
|
12804 |
|
12805 | exports.default = PartialMatcher;
|
12806 | });
|
12807 |
|
12808 | var deep = createCommonjsModule(function (module, exports) {
|
12809 |
|
12810 | Object.defineProperty(exports, "__esModule", {
|
12811 | value: true
|
12812 | });
|
12813 |
|
12814 | class DeepFilter {
|
12815 | constructor(_settings, _micromatchOptions) {
|
12816 | this._settings = _settings;
|
12817 | this._micromatchOptions = _micromatchOptions;
|
12818 | }
|
12819 |
|
12820 | getFilter(basePath, positive, negative) {
|
12821 | const matcher = this._getMatcher(positive);
|
12822 |
|
12823 | const negativeRe = this._getNegativePatternsRe(negative);
|
12824 |
|
12825 | return entry => this._filter(basePath, entry, matcher, negativeRe);
|
12826 | }
|
12827 |
|
12828 | _getMatcher(patterns) {
|
12829 | return new partial.default(patterns, this._settings, this._micromatchOptions);
|
12830 | }
|
12831 |
|
12832 | _getNegativePatternsRe(patterns) {
|
12833 | const affectDepthOfReadingPatterns = patterns.filter(utils$2.pattern.isAffectDepthOfReadingPattern);
|
12834 | return utils$2.pattern.convertPatternsToRe(affectDepthOfReadingPatterns, this._micromatchOptions);
|
12835 | }
|
12836 |
|
12837 | _filter(basePath, entry, matcher, negativeRe) {
|
12838 | if (this._isSkippedByDeep(basePath, entry.path)) {
|
12839 | return false;
|
12840 | }
|
12841 |
|
12842 | if (this._isSkippedSymbolicLink(entry)) {
|
12843 | return false;
|
12844 | }
|
12845 |
|
12846 | const filepath = utils$2.path.removeLeadingDotSegment(entry.path);
|
12847 |
|
12848 | if (this._isSkippedByPositivePatterns(filepath, matcher)) {
|
12849 | return false;
|
12850 | }
|
12851 |
|
12852 | return this._isSkippedByNegativePatterns(filepath, negativeRe);
|
12853 | }
|
12854 |
|
12855 | _isSkippedByDeep(basePath, entryPath) {
|
12856 | |
12857 |
|
12858 |
|
12859 | if (this._settings.deep === Infinity) {
|
12860 | return false;
|
12861 | }
|
12862 |
|
12863 | return this._getEntryLevel(basePath, entryPath) >= this._settings.deep;
|
12864 | }
|
12865 |
|
12866 | _getEntryLevel(basePath, entryPath) {
|
12867 | const entryPathDepth = entryPath.split('/').length;
|
12868 |
|
12869 | if (basePath === '') {
|
12870 | return entryPathDepth;
|
12871 | }
|
12872 |
|
12873 | const basePathDepth = basePath.split('/').length;
|
12874 | return entryPathDepth - basePathDepth;
|
12875 | }
|
12876 |
|
12877 | _isSkippedSymbolicLink(entry) {
|
12878 | return !this._settings.followSymbolicLinks && entry.dirent.isSymbolicLink();
|
12879 | }
|
12880 |
|
12881 | _isSkippedByPositivePatterns(entryPath, matcher) {
|
12882 | return !this._settings.baseNameMatch && !matcher.match(entryPath);
|
12883 | }
|
12884 |
|
12885 | _isSkippedByNegativePatterns(entryPath, patternsRe) {
|
12886 | return !utils$2.pattern.matchAny(entryPath, patternsRe);
|
12887 | }
|
12888 |
|
12889 | }
|
12890 |
|
12891 | exports.default = DeepFilter;
|
12892 | });
|
12893 |
|
12894 | var entry = createCommonjsModule(function (module, exports) {
|
12895 |
|
12896 | Object.defineProperty(exports, "__esModule", {
|
12897 | value: true
|
12898 | });
|
12899 |
|
12900 | class EntryFilter {
|
12901 | constructor(_settings, _micromatchOptions) {
|
12902 | this._settings = _settings;
|
12903 | this._micromatchOptions = _micromatchOptions;
|
12904 | this.index = new Map();
|
12905 | }
|
12906 |
|
12907 | getFilter(positive, negative) {
|
12908 | const positiveRe = utils$2.pattern.convertPatternsToRe(positive, this._micromatchOptions);
|
12909 | const negativeRe = utils$2.pattern.convertPatternsToRe(negative, this._micromatchOptions);
|
12910 | return entry => this._filter(entry, positiveRe, negativeRe);
|
12911 | }
|
12912 |
|
12913 | _filter(entry, positiveRe, negativeRe) {
|
12914 | if (this._settings.unique && this._isDuplicateEntry(entry)) {
|
12915 | return false;
|
12916 | }
|
12917 |
|
12918 | if (this._onlyFileFilter(entry) || this._onlyDirectoryFilter(entry)) {
|
12919 | return false;
|
12920 | }
|
12921 |
|
12922 | if (this._isSkippedByAbsoluteNegativePatterns(entry.path, negativeRe)) {
|
12923 | return false;
|
12924 | }
|
12925 |
|
12926 | const filepath = this._settings.baseNameMatch ? entry.name : entry.path;
|
12927 | const isMatched = this._isMatchToPatterns(filepath, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
|
12928 |
|
12929 | if (this._settings.unique && isMatched) {
|
12930 | this._createIndexRecord(entry);
|
12931 | }
|
12932 |
|
12933 | return isMatched;
|
12934 | }
|
12935 |
|
12936 | _isDuplicateEntry(entry) {
|
12937 | return this.index.has(entry.path);
|
12938 | }
|
12939 |
|
12940 | _createIndexRecord(entry) {
|
12941 | this.index.set(entry.path, undefined);
|
12942 | }
|
12943 |
|
12944 | _onlyFileFilter(entry) {
|
12945 | return this._settings.onlyFiles && !entry.dirent.isFile();
|
12946 | }
|
12947 |
|
12948 | _onlyDirectoryFilter(entry) {
|
12949 | return this._settings.onlyDirectories && !entry.dirent.isDirectory();
|
12950 | }
|
12951 |
|
12952 | _isSkippedByAbsoluteNegativePatterns(entryPath, patternsRe) {
|
12953 | if (!this._settings.absolute) {
|
12954 | return false;
|
12955 | }
|
12956 |
|
12957 | const fullpath = utils$2.path.makeAbsolute(this._settings.cwd, entryPath);
|
12958 | return utils$2.pattern.matchAny(fullpath, patternsRe);
|
12959 | }
|
12960 |
|
12961 | _isMatchToPatterns(entryPath, patternsRe) {
|
12962 | const filepath = utils$2.path.removeLeadingDotSegment(entryPath);
|
12963 | return utils$2.pattern.matchAny(filepath, patternsRe);
|
12964 | }
|
12965 |
|
12966 | }
|
12967 |
|
12968 | exports.default = EntryFilter;
|
12969 | });
|
12970 |
|
12971 | var error = createCommonjsModule(function (module, exports) {
|
12972 |
|
12973 | Object.defineProperty(exports, "__esModule", {
|
12974 | value: true
|
12975 | });
|
12976 |
|
12977 | class ErrorFilter {
|
12978 | constructor(_settings) {
|
12979 | this._settings = _settings;
|
12980 | }
|
12981 |
|
12982 | getFilter() {
|
12983 | return error => this._isNonFatalError(error);
|
12984 | }
|
12985 |
|
12986 | _isNonFatalError(error) {
|
12987 | return utils$2.errno.isEnoentCodeError(error) || this._settings.suppressErrors;
|
12988 | }
|
12989 |
|
12990 | }
|
12991 |
|
12992 | exports.default = ErrorFilter;
|
12993 | });
|
12994 |
|
12995 | var entry$1 = createCommonjsModule(function (module, exports) {
|
12996 |
|
12997 | Object.defineProperty(exports, "__esModule", {
|
12998 | value: true
|
12999 | });
|
13000 |
|
13001 | class EntryTransformer {
|
13002 | constructor(_settings) {
|
13003 | this._settings = _settings;
|
13004 | }
|
13005 |
|
13006 | getTransformer() {
|
13007 | return entry => this._transform(entry);
|
13008 | }
|
13009 |
|
13010 | _transform(entry) {
|
13011 | let filepath = entry.path;
|
13012 |
|
13013 | if (this._settings.absolute) {
|
13014 | filepath = utils$2.path.makeAbsolute(this._settings.cwd, filepath);
|
13015 | filepath = utils$2.path.unixify(filepath);
|
13016 | }
|
13017 |
|
13018 | if (this._settings.markDirectories && entry.dirent.isDirectory()) {
|
13019 | filepath += '/';
|
13020 | }
|
13021 |
|
13022 | if (!this._settings.objectMode) {
|
13023 | return filepath;
|
13024 | }
|
13025 |
|
13026 | return Object.assign(Object.assign({}, entry), {
|
13027 | path: filepath
|
13028 | });
|
13029 | }
|
13030 |
|
13031 | }
|
13032 |
|
13033 | exports.default = EntryTransformer;
|
13034 | });
|
13035 |
|
13036 | var provider = createCommonjsModule(function (module, exports) {
|
13037 |
|
13038 | Object.defineProperty(exports, "__esModule", {
|
13039 | value: true
|
13040 | });
|
13041 |
|
13042 | class Provider {
|
13043 | constructor(_settings) {
|
13044 | this._settings = _settings;
|
13045 | this.errorFilter = new error.default(this._settings);
|
13046 | this.entryFilter = new entry.default(this._settings, this._getMicromatchOptions());
|
13047 | this.deepFilter = new deep.default(this._settings, this._getMicromatchOptions());
|
13048 | this.entryTransformer = new entry$1.default(this._settings);
|
13049 | }
|
13050 |
|
13051 | _getRootDirectory(task) {
|
13052 | return path__default['default'].resolve(this._settings.cwd, task.base);
|
13053 | }
|
13054 |
|
13055 | _getReaderOptions(task) {
|
13056 | const basePath = task.base === '.' ? '' : task.base;
|
13057 | return {
|
13058 | basePath,
|
13059 | pathSegmentSeparator: '/',
|
13060 | concurrency: this._settings.concurrency,
|
13061 | deepFilter: this.deepFilter.getFilter(basePath, task.positive, task.negative),
|
13062 | entryFilter: this.entryFilter.getFilter(task.positive, task.negative),
|
13063 | errorFilter: this.errorFilter.getFilter(),
|
13064 | followSymbolicLinks: this._settings.followSymbolicLinks,
|
13065 | fs: this._settings.fs,
|
13066 | stats: this._settings.stats,
|
13067 | throwErrorOnBrokenSymbolicLink: this._settings.throwErrorOnBrokenSymbolicLink,
|
13068 | transform: this.entryTransformer.getTransformer()
|
13069 | };
|
13070 | }
|
13071 |
|
13072 | _getMicromatchOptions() {
|
13073 | return {
|
13074 | dot: this._settings.dot,
|
13075 | matchBase: this._settings.baseNameMatch,
|
13076 | nobrace: !this._settings.braceExpansion,
|
13077 | nocase: !this._settings.caseSensitiveMatch,
|
13078 | noext: !this._settings.extglob,
|
13079 | noglobstar: !this._settings.globstar,
|
13080 | posix: true,
|
13081 | strictSlashes: false
|
13082 | };
|
13083 | }
|
13084 |
|
13085 | }
|
13086 |
|
13087 | exports.default = Provider;
|
13088 | });
|
13089 |
|
13090 | var async$4 = createCommonjsModule(function (module, exports) {
|
13091 |
|
13092 | Object.defineProperty(exports, "__esModule", {
|
13093 | value: true
|
13094 | });
|
13095 |
|
13096 | class ProviderAsync extends provider.default {
|
13097 | constructor() {
|
13098 | super(...arguments);
|
13099 | this._reader = new stream$2.default(this._settings);
|
13100 | }
|
13101 |
|
13102 | read(task) {
|
13103 | const root = this._getRootDirectory(task);
|
13104 |
|
13105 | const options = this._getReaderOptions(task);
|
13106 |
|
13107 | const entries = [];
|
13108 | return new Promise((resolve, reject) => {
|
13109 | const stream = this.api(root, task, options);
|
13110 | stream.once('error', reject);
|
13111 | stream.on('data', entry => entries.push(options.transform(entry)));
|
13112 | stream.once('end', () => resolve(entries));
|
13113 | });
|
13114 | }
|
13115 |
|
13116 | api(root, task, options) {
|
13117 | if (task.dynamic) {
|
13118 | return this._reader.dynamic(root, options);
|
13119 | }
|
13120 |
|
13121 | return this._reader.static(task.patterns, options);
|
13122 | }
|
13123 |
|
13124 | }
|
13125 |
|
13126 | exports.default = ProviderAsync;
|
13127 | });
|
13128 |
|
13129 | var stream$3 = createCommonjsModule(function (module, exports) {
|
13130 |
|
13131 | Object.defineProperty(exports, "__esModule", {
|
13132 | value: true
|
13133 | });
|
13134 |
|
13135 | class ProviderStream extends provider.default {
|
13136 | constructor() {
|
13137 | super(...arguments);
|
13138 | this._reader = new stream$2.default(this._settings);
|
13139 | }
|
13140 |
|
13141 | read(task) {
|
13142 | const root = this._getRootDirectory(task);
|
13143 |
|
13144 | const options = this._getReaderOptions(task);
|
13145 |
|
13146 | const source = this.api(root, task, options);
|
13147 | const destination = new stream_1__default['default'].Readable({
|
13148 | objectMode: true,
|
13149 | read: () => {}
|
13150 | });
|
13151 | source.once('error', error => destination.emit('error', error)).on('data', entry => destination.emit('data', options.transform(entry))).once('end', () => destination.emit('end'));
|
13152 | destination.once('close', () => source.destroy());
|
13153 | return destination;
|
13154 | }
|
13155 |
|
13156 | api(root, task, options) {
|
13157 | if (task.dynamic) {
|
13158 | return this._reader.dynamic(root, options);
|
13159 | }
|
13160 |
|
13161 | return this._reader.static(task.patterns, options);
|
13162 | }
|
13163 |
|
13164 | }
|
13165 |
|
13166 | exports.default = ProviderStream;
|
13167 | });
|
13168 |
|
13169 | var sync$4 = createCommonjsModule(function (module, exports) {
|
13170 |
|
13171 | Object.defineProperty(exports, "__esModule", {
|
13172 | value: true
|
13173 | });
|
13174 |
|
13175 | class ReaderSync extends reader$1.default {
|
13176 | constructor() {
|
13177 | super(...arguments);
|
13178 | this._walkSync = out$2.walkSync;
|
13179 | this._statSync = out.statSync;
|
13180 | }
|
13181 |
|
13182 | dynamic(root, options) {
|
13183 | return this._walkSync(root, options);
|
13184 | }
|
13185 |
|
13186 | static(patterns, options) {
|
13187 | const entries = [];
|
13188 |
|
13189 | for (const pattern of patterns) {
|
13190 | const filepath = this._getFullEntryPath(pattern);
|
13191 |
|
13192 | const entry = this._getEntry(filepath, pattern, options);
|
13193 |
|
13194 | if (entry === null || !options.entryFilter(entry)) {
|
13195 | continue;
|
13196 | }
|
13197 |
|
13198 | entries.push(entry);
|
13199 | }
|
13200 |
|
13201 | return entries;
|
13202 | }
|
13203 |
|
13204 | _getEntry(filepath, pattern, options) {
|
13205 | try {
|
13206 | const stats = this._getStat(filepath);
|
13207 |
|
13208 | return this._makeEntry(stats, pattern);
|
13209 | } catch (error) {
|
13210 | if (options.errorFilter(error)) {
|
13211 | return null;
|
13212 | }
|
13213 |
|
13214 | throw error;
|
13215 | }
|
13216 | }
|
13217 |
|
13218 | _getStat(filepath) {
|
13219 | return this._statSync(filepath, this._fsStatSettings);
|
13220 | }
|
13221 |
|
13222 | }
|
13223 |
|
13224 | exports.default = ReaderSync;
|
13225 | });
|
13226 |
|
13227 | var sync$5 = createCommonjsModule(function (module, exports) {
|
13228 |
|
13229 | Object.defineProperty(exports, "__esModule", {
|
13230 | value: true
|
13231 | });
|
13232 |
|
13233 | class ProviderSync extends provider.default {
|
13234 | constructor() {
|
13235 | super(...arguments);
|
13236 | this._reader = new sync$4.default(this._settings);
|
13237 | }
|
13238 |
|
13239 | read(task) {
|
13240 | const root = this._getRootDirectory(task);
|
13241 |
|
13242 | const options = this._getReaderOptions(task);
|
13243 |
|
13244 | const entries = this.api(root, task, options);
|
13245 | return entries.map(options.transform);
|
13246 | }
|
13247 |
|
13248 | api(root, task, options) {
|
13249 | if (task.dynamic) {
|
13250 | return this._reader.dynamic(root, options);
|
13251 | }
|
13252 |
|
13253 | return this._reader.static(task.patterns, options);
|
13254 | }
|
13255 |
|
13256 | }
|
13257 |
|
13258 | exports.default = ProviderSync;
|
13259 | });
|
13260 |
|
13261 | var settings$3 = createCommonjsModule(function (module, exports) {
|
13262 |
|
13263 | Object.defineProperty(exports, "__esModule", {
|
13264 | value: true
|
13265 | });
|
13266 | exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
13267 | const CPU_COUNT = os__default['default'].cpus().length;
|
13268 | exports.DEFAULT_FILE_SYSTEM_ADAPTER = {
|
13269 | lstat: fs__default['default'].lstat,
|
13270 | lstatSync: fs__default['default'].lstatSync,
|
13271 | stat: fs__default['default'].stat,
|
13272 | statSync: fs__default['default'].statSync,
|
13273 | readdir: fs__default['default'].readdir,
|
13274 | readdirSync: fs__default['default'].readdirSync
|
13275 | };
|
13276 |
|
13277 | class Settings {
|
13278 | constructor(_options = {}) {
|
13279 | this._options = _options;
|
13280 | this.absolute = this._getValue(this._options.absolute, false);
|
13281 | this.baseNameMatch = this._getValue(this._options.baseNameMatch, false);
|
13282 | this.braceExpansion = this._getValue(this._options.braceExpansion, true);
|
13283 | this.caseSensitiveMatch = this._getValue(this._options.caseSensitiveMatch, true);
|
13284 | this.concurrency = this._getValue(this._options.concurrency, CPU_COUNT);
|
13285 | this.cwd = this._getValue(this._options.cwd, process.cwd());
|
13286 | this.deep = this._getValue(this._options.deep, Infinity);
|
13287 | this.dot = this._getValue(this._options.dot, false);
|
13288 | this.extglob = this._getValue(this._options.extglob, true);
|
13289 | this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, true);
|
13290 | this.fs = this._getFileSystemMethods(this._options.fs);
|
13291 | this.globstar = this._getValue(this._options.globstar, true);
|
13292 | this.ignore = this._getValue(this._options.ignore, []);
|
13293 | this.markDirectories = this._getValue(this._options.markDirectories, false);
|
13294 | this.objectMode = this._getValue(this._options.objectMode, false);
|
13295 | this.onlyDirectories = this._getValue(this._options.onlyDirectories, false);
|
13296 | this.onlyFiles = this._getValue(this._options.onlyFiles, true);
|
13297 | this.stats = this._getValue(this._options.stats, false);
|
13298 | this.suppressErrors = this._getValue(this._options.suppressErrors, false);
|
13299 | this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, false);
|
13300 | this.unique = this._getValue(this._options.unique, true);
|
13301 |
|
13302 | if (this.onlyDirectories) {
|
13303 | this.onlyFiles = false;
|
13304 | }
|
13305 |
|
13306 | if (this.stats) {
|
13307 | this.objectMode = true;
|
13308 | }
|
13309 | }
|
13310 |
|
13311 | _getValue(option, value) {
|
13312 | return option === undefined ? value : option;
|
13313 | }
|
13314 |
|
13315 | _getFileSystemMethods(methods = {}) {
|
13316 | return Object.assign(Object.assign({}, exports.DEFAULT_FILE_SYSTEM_ADAPTER), methods);
|
13317 | }
|
13318 |
|
13319 | }
|
13320 |
|
13321 | exports.default = Settings;
|
13322 | });
|
13323 |
|
13324 | async function FastGlob(source, options) {
|
13325 | assertPatternsInput(source);
|
13326 | const works = getWorks(source, async$4.default, options);
|
13327 | const result = await Promise.all(works);
|
13328 | return utils$2.array.flatten(result);
|
13329 | }
|
13330 |
|
13331 |
|
13332 |
|
13333 | (function (FastGlob) {
|
13334 | function sync(source, options) {
|
13335 | assertPatternsInput(source);
|
13336 | const works = getWorks(source, sync$5.default, options);
|
13337 | return utils$2.array.flatten(works);
|
13338 | }
|
13339 |
|
13340 | FastGlob.sync = sync;
|
13341 |
|
13342 | function stream(source, options) {
|
13343 | assertPatternsInput(source);
|
13344 | const works = getWorks(source, stream$3.default, options);
|
13345 | |
13346 |
|
13347 |
|
13348 |
|
13349 |
|
13350 |
|
13351 | return utils$2.stream.merge(works);
|
13352 | }
|
13353 |
|
13354 | FastGlob.stream = stream;
|
13355 |
|
13356 | function generateTasks(source, options) {
|
13357 | assertPatternsInput(source);
|
13358 | const patterns = [].concat(source);
|
13359 | const settings = new settings$3.default(options);
|
13360 | return tasks.generate(patterns, settings);
|
13361 | }
|
13362 |
|
13363 | FastGlob.generateTasks = generateTasks;
|
13364 |
|
13365 | function isDynamicPattern(source, options) {
|
13366 | assertPatternsInput(source);
|
13367 | const settings = new settings$3.default(options);
|
13368 | return utils$2.pattern.isDynamicPattern(source, settings);
|
13369 | }
|
13370 |
|
13371 | FastGlob.isDynamicPattern = isDynamicPattern;
|
13372 |
|
13373 | function escapePath(source) {
|
13374 | assertPatternsInput(source);
|
13375 | return utils$2.path.escape(source);
|
13376 | }
|
13377 |
|
13378 | FastGlob.escapePath = escapePath;
|
13379 | })(FastGlob || (FastGlob = {}));
|
13380 |
|
13381 | function getWorks(source, _Provider, options) {
|
13382 | const patterns = [].concat(source);
|
13383 | const settings = new settings$3.default(options);
|
13384 | const tasks$1 = tasks.generate(patterns, settings);
|
13385 | const provider = new _Provider(settings);
|
13386 | return tasks$1.map(provider.read, provider);
|
13387 | }
|
13388 |
|
13389 | function assertPatternsInput(input) {
|
13390 | const source = [].concat(input);
|
13391 | const isValidSource = source.every(item => utils$2.string.isString(item) && !utils$2.string.isEmpty(item));
|
13392 |
|
13393 | if (!isValidSource) {
|
13394 | throw new TypeError('Patterns must be a string (non empty) or an array of strings');
|
13395 | }
|
13396 | }
|
13397 |
|
13398 | var out$3 = FastGlob;
|
13399 |
|
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 |
|
13405 |
|
13406 |
|
13407 | function* expandPatterns(context) {
|
13408 | const cwd = process.cwd();
|
13409 | const seen = new Set();
|
13410 | let noResults = true;
|
13411 |
|
13412 | for (const pathOrError of expandPatternsInternal(context)) {
|
13413 | noResults = false;
|
13414 |
|
13415 | if (typeof pathOrError !== "string") {
|
13416 | yield pathOrError;
|
13417 | continue;
|
13418 | }
|
13419 |
|
13420 | const relativePath = path__default['default'].relative(cwd, pathOrError);
|
13421 |
|
13422 | if (seen.has(relativePath)) {
|
13423 | continue;
|
13424 | }
|
13425 |
|
13426 | seen.add(relativePath);
|
13427 | yield relativePath;
|
13428 | }
|
13429 |
|
13430 | if (noResults) {
|
13431 |
|
13432 | yield {
|
13433 | error: `No matching files. Patterns: ${context.filePatterns.join(" ")}`
|
13434 | };
|
13435 | }
|
13436 | }
|
13437 |
|
13438 |
|
13439 |
|
13440 |
|
13441 |
|
13442 | function* expandPatternsInternal(context) {
|
13443 |
|
13444 | const silentlyIgnoredDirs = {
|
13445 | ".git": true,
|
13446 | ".svn": true,
|
13447 | ".hg": true,
|
13448 | node_modules: context.argv["with-node-modules"] !== true
|
13449 | };
|
13450 | const globOptions = {
|
13451 | dot: true,
|
13452 | ignore: Object.keys(silentlyIgnoredDirs).filter(dir => silentlyIgnoredDirs[dir]).map(dir => "**/" + dir)
|
13453 | };
|
13454 | let supportedFilesGlob;
|
13455 | const cwd = process.cwd();
|
13456 |
|
13457 |
|
13458 | const entries = [];
|
13459 |
|
13460 | for (const pattern of context.filePatterns) {
|
13461 | const absolutePath = path__default['default'].resolve(cwd, pattern);
|
13462 |
|
13463 | if (containsIgnoredPathSegment(absolutePath, cwd, silentlyIgnoredDirs)) {
|
13464 | continue;
|
13465 | }
|
13466 |
|
13467 | const stat = statSafeSync(absolutePath);
|
13468 |
|
13469 | if (stat) {
|
13470 | if (stat.isFile()) {
|
13471 | entries.push({
|
13472 | type: "file",
|
13473 | glob: escapePathForGlob(fixWindowsSlashes(pattern)),
|
13474 | input: pattern
|
13475 | });
|
13476 | } else if (stat.isDirectory()) {
|
13477 | entries.push({
|
13478 | type: "dir",
|
13479 | glob: escapePathForGlob(fixWindowsSlashes(pattern)) + "/" + getSupportedFilesGlob(),
|
13480 | input: pattern
|
13481 | });
|
13482 | }
|
13483 | } else if (pattern[0] === "!") {
|
13484 |
|
13485 | globOptions.ignore.push(fixWindowsSlashes(pattern.slice(1)));
|
13486 | } else {
|
13487 | entries.push({
|
13488 | type: "glob",
|
13489 | glob: fixWindowsSlashes(pattern),
|
13490 | input: pattern
|
13491 | });
|
13492 | }
|
13493 | }
|
13494 |
|
13495 | for (const {
|
13496 | type,
|
13497 | glob,
|
13498 | input
|
13499 | } of entries) {
|
13500 | let result;
|
13501 |
|
13502 | try {
|
13503 | result = out$3.sync(glob, globOptions);
|
13504 | } catch ({
|
13505 | message
|
13506 | }) {
|
13507 |
|
13508 | yield {
|
13509 | error: `${errorMessages.globError[type]}: ${input}\n${message}`
|
13510 | };
|
13511 |
|
13512 |
|
13513 | continue;
|
13514 | }
|
13515 |
|
13516 | if (result.length === 0) {
|
13517 | yield {
|
13518 | error: `${errorMessages.emptyResults[type]}: "${input}".`
|
13519 | };
|
13520 | } else {
|
13521 | yield* sortPaths(result);
|
13522 | }
|
13523 | }
|
13524 |
|
13525 | function getSupportedFilesGlob() {
|
13526 | if (!supportedFilesGlob) {
|
13527 | const extensions = flatten_1(context.languages.map(lang => lang.extensions || []));
|
13528 | const filenames = flatten_1(context.languages.map(lang => lang.filenames || []));
|
13529 | supportedFilesGlob = `**/{${extensions.map(ext => "*" + (ext[0] === "." ? ext : "." + ext)).concat(filenames)}}`;
|
13530 | }
|
13531 |
|
13532 | return supportedFilesGlob;
|
13533 | }
|
13534 | }
|
13535 |
|
13536 | const errorMessages = {
|
13537 | globError: {
|
13538 | file: "Unable to resolve file",
|
13539 | dir: "Unable to expand directory",
|
13540 | glob: "Unable to expand glob pattern"
|
13541 | },
|
13542 | emptyResults: {
|
13543 | file: "Explicitly specified file was ignored due to negative glob patterns",
|
13544 | dir: "No supported files were found in the directory",
|
13545 | glob: "No files matching the pattern were found"
|
13546 | }
|
13547 | };
|
13548 |
|
13549 |
|
13550 |
|
13551 |
|
13552 |
|
13553 |
|
13554 | function containsIgnoredPathSegment(absolutePath, cwd, ignoredDirectories) {
|
13555 | return path__default['default'].relative(cwd, absolutePath).split(path__default['default'].sep).some(dir => ignoredDirectories[dir]);
|
13556 | }
|
13557 |
|
13558 |
|
13559 |
|
13560 |
|
13561 |
|
13562 | function sortPaths(paths) {
|
13563 | return paths.sort((a, b) => a.localeCompare(b));
|
13564 | }
|
13565 |
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 |
|
13571 |
|
13572 | function statSafeSync(filePath) {
|
13573 | try {
|
13574 | return fs__default['default'].statSync(filePath);
|
13575 | } catch (error) {
|
13576 |
|
13577 | if (error.code !== "ENOENT") {
|
13578 | throw error;
|
13579 | }
|
13580 | }
|
13581 | }
|
13582 |
|
13583 |
|
13584 |
|
13585 |
|
13586 |
|
13587 |
|
13588 |
|
13589 |
|
13590 | function escapePathForGlob(path) {
|
13591 | return out$3.escapePath(path.replace(/\\/g, "\0")
|
13592 | ).replace(/\\!/g, "@(!)")
|
13593 | .replace(/\0/g, "@(\\\\)");
|
13594 | }
|
13595 |
|
13596 | const isWindows = path__default['default'].sep === "\\";
|
13597 |
|
13598 |
|
13599 |
|
13600 |
|
13601 |
|
13602 |
|
13603 |
|
13604 |
|
13605 | function fixWindowsSlashes(pattern) {
|
13606 | return isWindows ? pattern.replace(/\\/g, "/") : pattern;
|
13607 | }
|
13608 |
|
13609 | var expandPatterns_1 = {
|
13610 | expandPatterns,
|
13611 | fixWindowsSlashes
|
13612 | };
|
13613 |
|
13614 | var lib = createCommonjsModule(function (module, exports) {
|
13615 |
|
13616 | Object.defineProperty(exports, "__esModule", {
|
13617 | value: true
|
13618 | });
|
13619 |
|
13620 | function noop() {
|
13621 | var args = [];
|
13622 |
|
13623 | for (var _i = 0; _i < arguments.length; _i++) {
|
13624 | args[_i] = arguments[_i];
|
13625 | }
|
13626 | }
|
13627 |
|
13628 | function createWeakMap() {
|
13629 | if (typeof WeakMap !== 'undefined') {
|
13630 | return new WeakMap();
|
13631 | } else {
|
13632 | return fakeSetOrMap();
|
13633 | }
|
13634 | }
|
13635 | |
13636 |
|
13637 |
|
13638 |
|
13639 |
|
13640 | function fakeSetOrMap() {
|
13641 | return {
|
13642 | add: noop,
|
13643 | delete: noop,
|
13644 | get: noop,
|
13645 | set: noop,
|
13646 | has: function (k) {
|
13647 | return false;
|
13648 | }
|
13649 | };
|
13650 | }
|
13651 |
|
13652 |
|
13653 | var hop = Object.prototype.hasOwnProperty;
|
13654 |
|
13655 | var has = function (obj, prop) {
|
13656 | return hop.call(obj, prop);
|
13657 | };
|
13658 |
|
13659 |
|
13660 | function extend(target, source) {
|
13661 | for (var prop in source) {
|
13662 | if (has(source, prop)) {
|
13663 | target[prop] = source[prop];
|
13664 | }
|
13665 | }
|
13666 |
|
13667 | return target;
|
13668 | }
|
13669 |
|
13670 | var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
|
13671 | var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
|
13672 | var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
|
13673 | var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
|
13674 | var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
|
13675 |
|
13676 | function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
|
13677 |
|
13678 |
|
13679 | var indentationLevel = 0;
|
13680 | var match = strings[0].match(reDetectIndentation);
|
13681 |
|
13682 | if (match) {
|
13683 | indentationLevel = match[1].length;
|
13684 | }
|
13685 |
|
13686 | var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
|
13687 | var reMatchIndent = new RegExp(reSource, 'g');
|
13688 |
|
13689 | if (firstInterpolatedValueSetsIndentationLevel) {
|
13690 | strings = strings.slice(1);
|
13691 | }
|
13692 |
|
13693 | var newline = options.newline,
|
13694 | trimLeadingNewline = options.trimLeadingNewline,
|
13695 | trimTrailingNewline = options.trimTrailingNewline;
|
13696 | var normalizeNewlines = typeof newline === 'string';
|
13697 | var l = strings.length;
|
13698 | var outdentedStrings = strings.map(function (v, i) {
|
13699 |
|
13700 | v = v.replace(reMatchIndent, '$1');
|
13701 |
|
13702 | if (i === 0 && trimLeadingNewline) {
|
13703 | v = v.replace(reLeadingNewline, '');
|
13704 | }
|
13705 |
|
13706 |
|
13707 | if (i === l - 1 && trimTrailingNewline) {
|
13708 | v = v.replace(reTrailingNewline, '');
|
13709 | }
|
13710 |
|
13711 |
|
13712 | if (normalizeNewlines) {
|
13713 | v = v.replace(/\r\n|\n|\r/g, function (_) {
|
13714 | return newline;
|
13715 | });
|
13716 | }
|
13717 |
|
13718 | return v;
|
13719 | });
|
13720 | return outdentedStrings;
|
13721 | }
|
13722 |
|
13723 | function concatStringsAndValues(strings, values) {
|
13724 | var ret = '';
|
13725 |
|
13726 | for (var i = 0, l = strings.length; i < l; i++) {
|
13727 | ret += strings[i];
|
13728 |
|
13729 | if (i < l - 1) {
|
13730 | ret += values[i];
|
13731 | }
|
13732 | }
|
13733 |
|
13734 | return ret;
|
13735 | }
|
13736 |
|
13737 | function isTemplateStringsArray(v) {
|
13738 | return has(v, 'raw') && has(v, 'length');
|
13739 | }
|
13740 | |
13741 |
|
13742 |
|
13743 |
|
13744 |
|
13745 |
|
13746 |
|
13747 |
|
13748 | function createInstance(options) {
|
13749 |
|
13750 | var arrayAutoIndentCache = createWeakMap();
|
13751 | |
13752 |
|
13753 |
|
13754 |
|
13755 |
|
13756 | var arrayFirstInterpSetsIndentCache = createWeakMap();
|
13757 |
|
13758 | function outdent(stringsOrOptions) {
|
13759 | var values = [];
|
13760 |
|
13761 | for (var _i = 1; _i < arguments.length; _i++) {
|
13762 | values[_i - 1] = arguments[_i];
|
13763 | }
|
13764 |
|
13765 |
|
13766 |
|
13767 | if (isTemplateStringsArray(stringsOrOptions)) {
|
13768 | var strings = stringsOrOptions;
|
13769 |
|
13770 | var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]);
|
13771 |
|
13772 | var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
|
13773 | var renderedArray = cache.get(strings);
|
13774 |
|
13775 | if (!renderedArray) {
|
13776 | renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
|
13777 | cache.set(strings, renderedArray);
|
13778 | }
|
13779 |
|
13780 |
|
13781 |
|
13782 | if (values.length === 0) {
|
13783 | return renderedArray[0];
|
13784 | }
|
13785 |
|
13786 |
|
13787 |
|
13788 | var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
|
13789 | return rendered;
|
13790 | } else {
|
13791 |
|
13792 | return createInstance(extend(extend({}, options), stringsOrOptions || {}));
|
13793 | }
|
13794 | }
|
13795 |
|
13796 | var fullOutdent = extend(outdent, {
|
13797 | string: function (str) {
|
13798 | return _outdentArray([str], false, options)[0];
|
13799 | }
|
13800 | });
|
13801 | return fullOutdent;
|
13802 | }
|
13803 |
|
13804 | var defaultOutdent = createInstance({
|
13805 | trimLeadingNewline: true,
|
13806 | trimTrailingNewline: true
|
13807 | });
|
13808 | exports.outdent = defaultOutdent;
|
13809 |
|
13810 |
|
13811 | exports.default = defaultOutdent;
|
13812 |
|
13813 | {
|
13814 |
|
13815 |
|
13816 | try {
|
13817 | module.exports = defaultOutdent;
|
13818 | Object.defineProperty(defaultOutdent, '__esModule', {
|
13819 | value: true
|
13820 | });
|
13821 | defaultOutdent.default = defaultOutdent;
|
13822 | defaultOutdent.outdent = defaultOutdent;
|
13823 | } catch (e) {}
|
13824 | }
|
13825 | });
|
13826 |
|
13827 | const {
|
13828 | outdent
|
13829 | } = lib;
|
13830 | const {
|
13831 | coreOptions
|
13832 | } = prettierInternal;
|
13833 | const categoryOrder = [coreOptions.CATEGORY_OUTPUT, coreOptions.CATEGORY_FORMAT, coreOptions.CATEGORY_CONFIG, coreOptions.CATEGORY_EDITOR, coreOptions.CATEGORY_OTHER];
|
13834 |
|
13835 |
|
13836 |
|
13837 |
|
13838 |
|
13839 |
|
13840 |
|
13841 |
|
13842 |
|
13843 |
|
13844 |
|
13845 |
|
13846 |
|
13847 |
|
13848 |
|
13849 |
|
13850 |
|
13851 |
|
13852 |
|
13853 |
|
13854 |
|
13855 |
|
13856 |
|
13857 |
|
13858 |
|
13859 |
|
13860 |
|
13861 |
|
13862 |
|
13863 |
|
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 |
|
13871 |
|
13872 |
|
13873 |
|
13874 |
|
13875 |
|
13876 |
|
13877 |
|
13878 |
|
13879 |
|
13880 |
|
13881 |
|
13882 |
|
13883 |
|
13884 |
|
13885 |
|
13886 |
|
13887 |
|
13888 |
|
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 | const options = {
|
13894 | check: {
|
13895 | type: "boolean",
|
13896 | category: coreOptions.CATEGORY_OUTPUT,
|
13897 | alias: "c",
|
13898 | description: outdent`
|
13899 | Check if the given files are formatted, print a human-friendly summary
|
13900 | message and paths to unformatted files (see also --list-different).
|
13901 | `
|
13902 | },
|
13903 | color: {
|
13904 |
|
13905 |
|
13906 |
|
13907 |
|
13908 | type: "boolean",
|
13909 | default: true,
|
13910 | description: "Colorize error messages.",
|
13911 | oppositeDescription: "Do not colorize error messages."
|
13912 | },
|
13913 | config: {
|
13914 | type: "path",
|
13915 | category: coreOptions.CATEGORY_CONFIG,
|
13916 | description: "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
|
13917 | oppositeDescription: "Do not look for a configuration file.",
|
13918 | exception: value => value === false
|
13919 | },
|
13920 | "config-precedence": {
|
13921 | type: "choice",
|
13922 | category: coreOptions.CATEGORY_CONFIG,
|
13923 | default: "cli-override",
|
13924 | choices: [{
|
13925 | value: "cli-override",
|
13926 | description: "CLI options take precedence over config file"
|
13927 | }, {
|
13928 | value: "file-override",
|
13929 | description: "Config file take precedence over CLI options"
|
13930 | }, {
|
13931 | value: "prefer-file",
|
13932 | description: outdent`
|
13933 | If a config file is found will evaluate it and ignore other CLI options.
|
13934 | If no config file is found CLI options will evaluate as normal.
|
13935 | `
|
13936 | }],
|
13937 | description: "Define in which order config files and CLI options should be evaluated."
|
13938 | },
|
13939 | "debug-benchmark": {
|
13940 |
|
13941 | type: "boolean"
|
13942 | },
|
13943 | "debug-check": {
|
13944 |
|
13945 | type: "boolean"
|
13946 | },
|
13947 | "debug-print-doc": {
|
13948 | type: "boolean"
|
13949 | },
|
13950 | "debug-repeat": {
|
13951 |
|
13952 | type: "int",
|
13953 | default: 0
|
13954 | },
|
13955 | editorconfig: {
|
13956 | type: "boolean",
|
13957 | category: coreOptions.CATEGORY_CONFIG,
|
13958 | description: "Take .editorconfig into account when parsing configuration.",
|
13959 | oppositeDescription: "Don't take .editorconfig into account when parsing configuration.",
|
13960 | default: true
|
13961 | },
|
13962 | "find-config-path": {
|
13963 | type: "path",
|
13964 | category: coreOptions.CATEGORY_CONFIG,
|
13965 | description: "Find and print the path to a configuration file for the given input file."
|
13966 | },
|
13967 | "file-info": {
|
13968 | type: "path",
|
13969 | description: outdent`
|
13970 | Extract the following info (as JSON) for a given file path. Reported fields:
|
13971 | * ignored (boolean) - true if file path is filtered by --ignore-path
|
13972 | * inferredParser (string | null) - name of parser inferred from file path
|
13973 | `
|
13974 | },
|
13975 | help: {
|
13976 | type: "flag",
|
13977 | alias: "h",
|
13978 | description: outdent`
|
13979 | Show CLI usage, or details about the given flag.
|
13980 | Example: --help write
|
13981 | `,
|
13982 | exception: value => value === ""
|
13983 | },
|
13984 | "ignore-path": {
|
13985 | type: "path",
|
13986 | category: coreOptions.CATEGORY_CONFIG,
|
13987 | default: ".prettierignore",
|
13988 | description: "Path to a file with patterns describing files to ignore."
|
13989 | },
|
13990 | "ignore-unknown": {
|
13991 | type: "boolean",
|
13992 | alias: "u",
|
13993 | description: "Ignore unknown files."
|
13994 | },
|
13995 | "list-different": {
|
13996 | type: "boolean",
|
13997 | category: coreOptions.CATEGORY_OUTPUT,
|
13998 | alias: "l",
|
13999 | description: "Print the names of files that are different from Prettier's formatting (see also --check)."
|
14000 | },
|
14001 | loglevel: {
|
14002 | type: "choice",
|
14003 | description: "What level of logs to report.",
|
14004 | default: "log",
|
14005 | choices: ["silent", "error", "warn", "log", "debug"]
|
14006 | },
|
14007 | "support-info": {
|
14008 | type: "boolean",
|
14009 | description: "Print support information as JSON."
|
14010 | },
|
14011 | version: {
|
14012 | type: "boolean",
|
14013 | alias: "v",
|
14014 | description: "Print Prettier version."
|
14015 | },
|
14016 | "with-node-modules": {
|
14017 | type: "boolean",
|
14018 | category: coreOptions.CATEGORY_CONFIG,
|
14019 | description: "Process files inside 'node_modules' directory."
|
14020 | },
|
14021 | write: {
|
14022 | type: "boolean",
|
14023 | alias: "w",
|
14024 | category: coreOptions.CATEGORY_OUTPUT,
|
14025 | description: "Edit files in-place. (Beware!)"
|
14026 | }
|
14027 | };
|
14028 | const usageSummary = outdent`
|
14029 | Usage: prettier [options] [file/dir/glob ...]
|
14030 |
|
14031 | By default, output is written to stdout.
|
14032 | Stdin is read if it is piped to Prettier and no files are given.
|
14033 | `;
|
14034 | var constant$1 = {
|
14035 | categoryOrder,
|
14036 | options,
|
14037 | usageSummary
|
14038 | };
|
14039 |
|
14040 | const {
|
14041 | isCI
|
14042 | } = thirdParty;
|
14043 |
|
14044 |
|
14045 |
|
14046 | var isTty = function isTTY() {
|
14047 | return process.stdout.isTTY && !isCI();
|
14048 | };
|
14049 |
|
14050 | function Diff() {}
|
14051 |
|
14052 | Diff.prototype = {
|
14053 | diff: function diff(oldString, newString) {
|
14054 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
14055 | var callback = options.callback;
|
14056 |
|
14057 | if (typeof options === 'function') {
|
14058 | callback = options;
|
14059 | options = {};
|
14060 | }
|
14061 |
|
14062 | this.options = options;
|
14063 | var self = this;
|
14064 |
|
14065 | function done(value) {
|
14066 | if (callback) {
|
14067 | setTimeout(function () {
|
14068 | callback(undefined, value);
|
14069 | }, 0);
|
14070 | return true;
|
14071 | } else {
|
14072 | return value;
|
14073 | }
|
14074 | }
|
14075 |
|
14076 |
|
14077 | oldString = this.castInput(oldString);
|
14078 | newString = this.castInput(newString);
|
14079 | oldString = this.removeEmpty(this.tokenize(oldString));
|
14080 | newString = this.removeEmpty(this.tokenize(newString));
|
14081 | var newLen = newString.length,
|
14082 | oldLen = oldString.length;
|
14083 | var editLength = 1;
|
14084 | var maxEditLength = newLen + oldLen;
|
14085 | var bestPath = [{
|
14086 | newPos: -1,
|
14087 | components: []
|
14088 | }];
|
14089 |
|
14090 | var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
|
14091 |
|
14092 | if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
|
14093 |
|
14094 | return done([{
|
14095 | value: this.join(newString),
|
14096 | count: newString.length
|
14097 | }]);
|
14098 | }
|
14099 |
|
14100 |
|
14101 | function execEditLength() {
|
14102 | for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
|
14103 | var basePath = void 0;
|
14104 |
|
14105 | var addPath = bestPath[diagonalPath - 1],
|
14106 | removePath = bestPath[diagonalPath + 1],
|
14107 | _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
|
14108 |
|
14109 | if (addPath) {
|
14110 |
|
14111 | bestPath[diagonalPath - 1] = undefined;
|
14112 | }
|
14113 |
|
14114 | var canAdd = addPath && addPath.newPos + 1 < newLen,
|
14115 | canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
|
14116 |
|
14117 | if (!canAdd && !canRemove) {
|
14118 |
|
14119 | bestPath[diagonalPath] = undefined;
|
14120 | continue;
|
14121 | }
|
14122 |
|
14123 |
|
14124 |
|
14125 |
|
14126 | if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
|
14127 | basePath = clonePath(removePath);
|
14128 | self.pushComponent(basePath.components, undefined, true);
|
14129 | } else {
|
14130 | basePath = addPath;
|
14131 |
|
14132 | basePath.newPos++;
|
14133 | self.pushComponent(basePath.components, true, undefined);
|
14134 | }
|
14135 |
|
14136 | _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath);
|
14137 |
|
14138 | if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
|
14139 | return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
|
14140 | } else {
|
14141 |
|
14142 | bestPath[diagonalPath] = basePath;
|
14143 | }
|
14144 | }
|
14145 |
|
14146 | editLength++;
|
14147 | }
|
14148 |
|
14149 |
|
14150 |
|
14151 |
|
14152 | if (callback) {
|
14153 | (function exec() {
|
14154 | setTimeout(function () {
|
14155 |
|
14156 |
|
14157 |
|
14158 | if (editLength > maxEditLength) {
|
14159 | return callback();
|
14160 | }
|
14161 |
|
14162 | if (!execEditLength()) {
|
14163 | exec();
|
14164 | }
|
14165 | }, 0);
|
14166 | })();
|
14167 | } else {
|
14168 | while (editLength <= maxEditLength) {
|
14169 | var ret = execEditLength();
|
14170 |
|
14171 | if (ret) {
|
14172 | return ret;
|
14173 | }
|
14174 | }
|
14175 | }
|
14176 | },
|
14177 | pushComponent: function pushComponent(components, added, removed) {
|
14178 | var last = components[components.length - 1];
|
14179 |
|
14180 | if (last && last.added === added && last.removed === removed) {
|
14181 |
|
14182 |
|
14183 | components[components.length - 1] = {
|
14184 | count: last.count + 1,
|
14185 | added: added,
|
14186 | removed: removed
|
14187 | };
|
14188 | } else {
|
14189 | components.push({
|
14190 | count: 1,
|
14191 | added: added,
|
14192 | removed: removed
|
14193 | });
|
14194 | }
|
14195 | },
|
14196 | extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
|
14197 | var newLen = newString.length,
|
14198 | oldLen = oldString.length,
|
14199 | newPos = basePath.newPos,
|
14200 | oldPos = newPos - diagonalPath,
|
14201 | commonCount = 0;
|
14202 |
|
14203 | while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
|
14204 | newPos++;
|
14205 | oldPos++;
|
14206 | commonCount++;
|
14207 | }
|
14208 |
|
14209 | if (commonCount) {
|
14210 | basePath.components.push({
|
14211 | count: commonCount
|
14212 | });
|
14213 | }
|
14214 |
|
14215 | basePath.newPos = newPos;
|
14216 | return oldPos;
|
14217 | },
|
14218 | equals: function equals(left, right) {
|
14219 | if (this.options.comparator) {
|
14220 | return this.options.comparator(left, right);
|
14221 | } else {
|
14222 | return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
|
14223 | }
|
14224 | },
|
14225 | removeEmpty: function removeEmpty(array) {
|
14226 | var ret = [];
|
14227 |
|
14228 | for (var i = 0; i < array.length; i++) {
|
14229 | if (array[i]) {
|
14230 | ret.push(array[i]);
|
14231 | }
|
14232 | }
|
14233 |
|
14234 | return ret;
|
14235 | },
|
14236 | castInput: function castInput(value) {
|
14237 | return value;
|
14238 | },
|
14239 | tokenize: function tokenize(value) {
|
14240 | return value.split('');
|
14241 | },
|
14242 | join: function join(chars) {
|
14243 | return chars.join('');
|
14244 | }
|
14245 | };
|
14246 |
|
14247 | function buildValues(diff, components, newString, oldString, useLongestToken) {
|
14248 | var componentPos = 0,
|
14249 | componentLen = components.length,
|
14250 | newPos = 0,
|
14251 | oldPos = 0;
|
14252 |
|
14253 | for (; componentPos < componentLen; componentPos++) {
|
14254 | var component = components[componentPos];
|
14255 |
|
14256 | if (!component.removed) {
|
14257 | if (!component.added && useLongestToken) {
|
14258 | var value = newString.slice(newPos, newPos + component.count);
|
14259 | value = value.map(function (value, i) {
|
14260 | var oldValue = oldString[oldPos + i];
|
14261 | return oldValue.length > value.length ? oldValue : value;
|
14262 | });
|
14263 | component.value = diff.join(value);
|
14264 | } else {
|
14265 | component.value = diff.join(newString.slice(newPos, newPos + component.count));
|
14266 | }
|
14267 |
|
14268 | newPos += component.count;
|
14269 |
|
14270 | if (!component.added) {
|
14271 | oldPos += component.count;
|
14272 | }
|
14273 | } else {
|
14274 | component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
|
14275 | oldPos += component.count;
|
14276 |
|
14277 |
|
14278 |
|
14279 | if (componentPos && components[componentPos - 1].added) {
|
14280 | var tmp = components[componentPos - 1];
|
14281 | components[componentPos - 1] = components[componentPos];
|
14282 | components[componentPos] = tmp;
|
14283 | }
|
14284 | }
|
14285 | }
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 | var lastComponent = components[componentLen - 1];
|
14291 |
|
14292 | if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
|
14293 | components[componentLen - 2].value += lastComponent.value;
|
14294 | components.pop();
|
14295 | }
|
14296 |
|
14297 | return components;
|
14298 | }
|
14299 |
|
14300 | function clonePath(path) {
|
14301 | return {
|
14302 | newPos: path.newPos,
|
14303 | components: path.components.slice(0)
|
14304 | };
|
14305 | }
|
14306 |
|
14307 | var characterDiff = new Diff();
|
14308 |
|
14309 | function diffChars(oldStr, newStr, options) {
|
14310 | return characterDiff.diff(oldStr, newStr, options);
|
14311 | }
|
14312 |
|
14313 | function generateOptions(options, defaults) {
|
14314 | if (typeof options === 'function') {
|
14315 | defaults.callback = options;
|
14316 | } else if (options) {
|
14317 | for (var name in options) {
|
14318 |
|
14319 | if (options.hasOwnProperty(name)) {
|
14320 | defaults[name] = options[name];
|
14321 | }
|
14322 | }
|
14323 | }
|
14324 |
|
14325 | return defaults;
|
14326 | }
|
14327 |
|
14328 |
|
14329 |
|
14330 |
|
14331 |
|
14332 |
|
14333 |
|
14334 |
|
14335 |
|
14336 |
|
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 | var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
|
14346 | var reWhitespace = /\S/;
|
14347 | var wordDiff = new Diff();
|
14348 |
|
14349 | wordDiff.equals = function (left, right) {
|
14350 | if (this.options.ignoreCase) {
|
14351 | left = left.toLowerCase();
|
14352 | right = right.toLowerCase();
|
14353 | }
|
14354 |
|
14355 | return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
|
14356 | };
|
14357 |
|
14358 | wordDiff.tokenize = function (value) {
|
14359 |
|
14360 | var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/);
|
14361 |
|
14362 | for (var i = 0; i < tokens.length - 1; i++) {
|
14363 |
|
14364 | if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
|
14365 | tokens[i] += tokens[i + 2];
|
14366 | tokens.splice(i + 1, 2);
|
14367 | i--;
|
14368 | }
|
14369 | }
|
14370 |
|
14371 | return tokens;
|
14372 | };
|
14373 |
|
14374 | function diffWords(oldStr, newStr, options) {
|
14375 | options = generateOptions(options, {
|
14376 | ignoreWhitespace: true
|
14377 | });
|
14378 | return wordDiff.diff(oldStr, newStr, options);
|
14379 | }
|
14380 |
|
14381 | function diffWordsWithSpace(oldStr, newStr, options) {
|
14382 | return wordDiff.diff(oldStr, newStr, options);
|
14383 | }
|
14384 |
|
14385 | var lineDiff = new Diff();
|
14386 |
|
14387 | lineDiff.tokenize = function (value) {
|
14388 | var retLines = [],
|
14389 | linesAndNewlines = value.split(/(\n|\r\n)/);
|
14390 |
|
14391 | if (!linesAndNewlines[linesAndNewlines.length - 1]) {
|
14392 | linesAndNewlines.pop();
|
14393 | }
|
14394 |
|
14395 |
|
14396 | for (var i = 0; i < linesAndNewlines.length; i++) {
|
14397 | var line = linesAndNewlines[i];
|
14398 |
|
14399 | if (i % 2 && !this.options.newlineIsToken) {
|
14400 | retLines[retLines.length - 1] += line;
|
14401 | } else {
|
14402 | if (this.options.ignoreWhitespace) {
|
14403 | line = line.trim();
|
14404 | }
|
14405 |
|
14406 | retLines.push(line);
|
14407 | }
|
14408 | }
|
14409 |
|
14410 | return retLines;
|
14411 | };
|
14412 |
|
14413 | function diffLines(oldStr, newStr, callback) {
|
14414 | return lineDiff.diff(oldStr, newStr, callback);
|
14415 | }
|
14416 |
|
14417 | function diffTrimmedLines(oldStr, newStr, callback) {
|
14418 | var options = generateOptions(callback, {
|
14419 | ignoreWhitespace: true
|
14420 | });
|
14421 | return lineDiff.diff(oldStr, newStr, options);
|
14422 | }
|
14423 |
|
14424 | var sentenceDiff = new Diff();
|
14425 |
|
14426 | sentenceDiff.tokenize = function (value) {
|
14427 | return value.split(/(\S.+?[.!?])(?=\s+|$)/);
|
14428 | };
|
14429 |
|
14430 | function diffSentences(oldStr, newStr, callback) {
|
14431 | return sentenceDiff.diff(oldStr, newStr, callback);
|
14432 | }
|
14433 |
|
14434 | var cssDiff = new Diff();
|
14435 |
|
14436 | cssDiff.tokenize = function (value) {
|
14437 | return value.split(/([{}:;,]|\s+)/);
|
14438 | };
|
14439 |
|
14440 | function diffCss(oldStr, newStr, callback) {
|
14441 | return cssDiff.diff(oldStr, newStr, callback);
|
14442 | }
|
14443 |
|
14444 | function _typeof(obj) {
|
14445 | "@babel/helpers - typeof";
|
14446 |
|
14447 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
14448 | _typeof = function (obj) {
|
14449 | return typeof obj;
|
14450 | };
|
14451 | } else {
|
14452 | _typeof = function (obj) {
|
14453 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
14454 | };
|
14455 | }
|
14456 |
|
14457 | return _typeof(obj);
|
14458 | }
|
14459 |
|
14460 | function _toConsumableArray(arr) {
|
14461 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
14462 | }
|
14463 |
|
14464 | function _arrayWithoutHoles(arr) {
|
14465 | if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
14466 | }
|
14467 |
|
14468 | function _iterableToArray(iter) {
|
14469 | if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
14470 | }
|
14471 |
|
14472 | function _unsupportedIterableToArray(o, minLen) {
|
14473 | if (!o) return;
|
14474 | if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
14475 | var n = Object.prototype.toString.call(o).slice(8, -1);
|
14476 | if (n === "Object" && o.constructor) n = o.constructor.name;
|
14477 | if (n === "Map" || n === "Set") return Array.from(o);
|
14478 | if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
14479 | }
|
14480 |
|
14481 | function _arrayLikeToArray(arr, len) {
|
14482 | if (len == null || len > arr.length) len = arr.length;
|
14483 |
|
14484 | for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
14485 |
|
14486 | return arr2;
|
14487 | }
|
14488 |
|
14489 | function _nonIterableSpread() {
|
14490 | throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
14491 | }
|
14492 |
|
14493 | var objectPrototypeToString = Object.prototype.toString;
|
14494 | var jsonDiff = new Diff();
|
14495 |
|
14496 |
|
14497 | jsonDiff.useLongestToken = true;
|
14498 | jsonDiff.tokenize = lineDiff.tokenize;
|
14499 |
|
14500 | jsonDiff.castInput = function (value) {
|
14501 | var _this$options = this.options,
|
14502 | undefinedReplacement = _this$options.undefinedReplacement,
|
14503 | _this$options$stringi = _this$options.stringifyReplacer,
|
14504 | stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
|
14505 | return typeof v === 'undefined' ? undefinedReplacement : v;
|
14506 | } : _this$options$stringi;
|
14507 | return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
|
14508 | };
|
14509 |
|
14510 | jsonDiff.equals = function (left, right) {
|
14511 | return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
|
14512 | };
|
14513 |
|
14514 | function diffJson(oldObj, newObj, options) {
|
14515 | return jsonDiff.diff(oldObj, newObj, options);
|
14516 | }
|
14517 |
|
14518 |
|
14519 |
|
14520 | function canonicalize(obj, stack, replacementStack, replacer, key) {
|
14521 | stack = stack || [];
|
14522 | replacementStack = replacementStack || [];
|
14523 |
|
14524 | if (replacer) {
|
14525 | obj = replacer(key, obj);
|
14526 | }
|
14527 |
|
14528 | var i;
|
14529 |
|
14530 | for (i = 0; i < stack.length; i += 1) {
|
14531 | if (stack[i] === obj) {
|
14532 | return replacementStack[i];
|
14533 | }
|
14534 | }
|
14535 |
|
14536 | var canonicalizedObj;
|
14537 |
|
14538 | if ('[object Array]' === objectPrototypeToString.call(obj)) {
|
14539 | stack.push(obj);
|
14540 | canonicalizedObj = new Array(obj.length);
|
14541 | replacementStack.push(canonicalizedObj);
|
14542 |
|
14543 | for (i = 0; i < obj.length; i += 1) {
|
14544 | canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
|
14545 | }
|
14546 |
|
14547 | stack.pop();
|
14548 | replacementStack.pop();
|
14549 | return canonicalizedObj;
|
14550 | }
|
14551 |
|
14552 | if (obj && obj.toJSON) {
|
14553 | obj = obj.toJSON();
|
14554 | }
|
14555 |
|
14556 | if (_typeof(obj) === 'object' && obj !== null) {
|
14557 | stack.push(obj);
|
14558 | canonicalizedObj = {};
|
14559 | replacementStack.push(canonicalizedObj);
|
14560 |
|
14561 | var sortedKeys = [],
|
14562 | _key;
|
14563 |
|
14564 | for (_key in obj) {
|
14565 |
|
14566 | if (obj.hasOwnProperty(_key)) {
|
14567 | sortedKeys.push(_key);
|
14568 | }
|
14569 | }
|
14570 |
|
14571 | sortedKeys.sort();
|
14572 |
|
14573 | for (i = 0; i < sortedKeys.length; i += 1) {
|
14574 | _key = sortedKeys[i];
|
14575 | canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
|
14576 | }
|
14577 |
|
14578 | stack.pop();
|
14579 | replacementStack.pop();
|
14580 | } else {
|
14581 | canonicalizedObj = obj;
|
14582 | }
|
14583 |
|
14584 | return canonicalizedObj;
|
14585 | }
|
14586 |
|
14587 | var arrayDiff = new Diff();
|
14588 |
|
14589 | arrayDiff.tokenize = function (value) {
|
14590 | return value.slice();
|
14591 | };
|
14592 |
|
14593 | arrayDiff.join = arrayDiff.removeEmpty = function (value) {
|
14594 | return value;
|
14595 | };
|
14596 |
|
14597 | function diffArrays(oldArr, newArr, callback) {
|
14598 | return arrayDiff.diff(oldArr, newArr, callback);
|
14599 | }
|
14600 |
|
14601 | function parsePatch(uniDiff) {
|
14602 | var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
14603 | var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
|
14604 | delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
|
14605 | list = [],
|
14606 | i = 0;
|
14607 |
|
14608 | function parseIndex() {
|
14609 | var index = {};
|
14610 | list.push(index);
|
14611 |
|
14612 | while (i < diffstr.length) {
|
14613 | var line = diffstr[i];
|
14614 |
|
14615 | if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
|
14616 | break;
|
14617 | }
|
14618 |
|
14619 |
|
14620 | var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
|
14621 |
|
14622 | if (header) {
|
14623 | index.index = header[1];
|
14624 | }
|
14625 |
|
14626 | i++;
|
14627 | }
|
14628 |
|
14629 |
|
14630 |
|
14631 | parseFileHeader(index);
|
14632 | parseFileHeader(index);
|
14633 |
|
14634 | index.hunks = [];
|
14635 |
|
14636 | while (i < diffstr.length) {
|
14637 | var _line = diffstr[i];
|
14638 |
|
14639 | if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
|
14640 | break;
|
14641 | } else if (/^@@/.test(_line)) {
|
14642 | index.hunks.push(parseHunk());
|
14643 | } else if (_line && options.strict) {
|
14644 |
|
14645 | throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
|
14646 | } else {
|
14647 | i++;
|
14648 | }
|
14649 | }
|
14650 | }
|
14651 |
|
14652 |
|
14653 |
|
14654 | function parseFileHeader(index) {
|
14655 | var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
|
14656 |
|
14657 | if (fileHeader) {
|
14658 | var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
|
14659 | var data = fileHeader[2].split('\t', 2);
|
14660 | var fileName = data[0].replace(/\\\\/g, '\\');
|
14661 |
|
14662 | if (/^".*"$/.test(fileName)) {
|
14663 | fileName = fileName.substr(1, fileName.length - 2);
|
14664 | }
|
14665 |
|
14666 | index[keyPrefix + 'FileName'] = fileName;
|
14667 | index[keyPrefix + 'Header'] = (data[1] || '').trim();
|
14668 | i++;
|
14669 | }
|
14670 | }
|
14671 |
|
14672 |
|
14673 |
|
14674 | function parseHunk() {
|
14675 | var chunkHeaderIndex = i,
|
14676 | chunkHeaderLine = diffstr[i++],
|
14677 | chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
|
14678 | var hunk = {
|
14679 | oldStart: +chunkHeader[1],
|
14680 | oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
|
14681 | newStart: +chunkHeader[3],
|
14682 | newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
|
14683 | lines: [],
|
14684 | linedelimiters: []
|
14685 | };
|
14686 |
|
14687 |
|
14688 |
|
14689 | if (hunk.oldLines === 0) {
|
14690 | hunk.oldStart += 1;
|
14691 | }
|
14692 |
|
14693 | if (hunk.newLines === 0) {
|
14694 | hunk.newStart += 1;
|
14695 | }
|
14696 |
|
14697 | var addCount = 0,
|
14698 | removeCount = 0;
|
14699 |
|
14700 | for (; i < diffstr.length; i++) {
|
14701 |
|
14702 |
|
14703 | if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
|
14704 | break;
|
14705 | }
|
14706 |
|
14707 | var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
|
14708 |
|
14709 | if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
|
14710 | hunk.lines.push(diffstr[i]);
|
14711 | hunk.linedelimiters.push(delimiters[i] || '\n');
|
14712 |
|
14713 | if (operation === '+') {
|
14714 | addCount++;
|
14715 | } else if (operation === '-') {
|
14716 | removeCount++;
|
14717 | } else if (operation === ' ') {
|
14718 | addCount++;
|
14719 | removeCount++;
|
14720 | }
|
14721 | } else {
|
14722 | break;
|
14723 | }
|
14724 | }
|
14725 |
|
14726 |
|
14727 | if (!addCount && hunk.newLines === 1) {
|
14728 | hunk.newLines = 0;
|
14729 | }
|
14730 |
|
14731 | if (!removeCount && hunk.oldLines === 1) {
|
14732 | hunk.oldLines = 0;
|
14733 | }
|
14734 |
|
14735 |
|
14736 | if (options.strict) {
|
14737 | if (addCount !== hunk.newLines) {
|
14738 | throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
|
14739 | }
|
14740 |
|
14741 | if (removeCount !== hunk.oldLines) {
|
14742 | throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
|
14743 | }
|
14744 | }
|
14745 |
|
14746 | return hunk;
|
14747 | }
|
14748 |
|
14749 | while (i < diffstr.length) {
|
14750 | parseIndex();
|
14751 | }
|
14752 |
|
14753 | return list;
|
14754 | }
|
14755 |
|
14756 |
|
14757 |
|
14758 |
|
14759 | function distanceIterator(start, minLine, maxLine) {
|
14760 | var wantForward = true,
|
14761 | backwardExhausted = false,
|
14762 | forwardExhausted = false,
|
14763 | localOffset = 1;
|
14764 | return function iterator() {
|
14765 | if (wantForward && !forwardExhausted) {
|
14766 | if (backwardExhausted) {
|
14767 | localOffset++;
|
14768 | } else {
|
14769 | wantForward = false;
|
14770 | }
|
14771 |
|
14772 |
|
14773 |
|
14774 | if (start + localOffset <= maxLine) {
|
14775 | return localOffset;
|
14776 | }
|
14777 |
|
14778 | forwardExhausted = true;
|
14779 | }
|
14780 |
|
14781 | if (!backwardExhausted) {
|
14782 | if (!forwardExhausted) {
|
14783 | wantForward = true;
|
14784 | }
|
14785 |
|
14786 |
|
14787 |
|
14788 | if (minLine <= start - localOffset) {
|
14789 | return -localOffset++;
|
14790 | }
|
14791 |
|
14792 | backwardExhausted = true;
|
14793 | return iterator();
|
14794 | }
|
14795 |
|
14796 |
|
14797 | };
|
14798 | }
|
14799 |
|
14800 | function applyPatch(source, uniDiff) {
|
14801 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
14802 |
|
14803 | if (typeof uniDiff === 'string') {
|
14804 | uniDiff = parsePatch(uniDiff);
|
14805 | }
|
14806 |
|
14807 | if (Array.isArray(uniDiff)) {
|
14808 | if (uniDiff.length > 1) {
|
14809 | throw new Error('applyPatch only works with a single input.');
|
14810 | }
|
14811 |
|
14812 | uniDiff = uniDiff[0];
|
14813 | }
|
14814 |
|
14815 |
|
14816 | var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
|
14817 | delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
|
14818 | hunks = uniDiff.hunks,
|
14819 | compareLine = options.compareLine || function (lineNumber, line, operation, patchContent) {
|
14820 | return line === patchContent;
|
14821 | },
|
14822 | errorCount = 0,
|
14823 | fuzzFactor = options.fuzzFactor || 0,
|
14824 | minLine = 0,
|
14825 | offset = 0,
|
14826 | removeEOFNL,
|
14827 | addEOFNL;
|
14828 | |
14829 |
|
14830 |
|
14831 |
|
14832 |
|
14833 | function hunkFits(hunk, toPos) {
|
14834 | for (var j = 0; j < hunk.lines.length; j++) {
|
14835 | var line = hunk.lines[j],
|
14836 | operation = line.length > 0 ? line[0] : ' ',
|
14837 | content = line.length > 0 ? line.substr(1) : line;
|
14838 |
|
14839 | if (operation === ' ' || operation === '-') {
|
14840 |
|
14841 | if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
|
14842 | errorCount++;
|
14843 |
|
14844 | if (errorCount > fuzzFactor) {
|
14845 | return false;
|
14846 | }
|
14847 | }
|
14848 |
|
14849 | toPos++;
|
14850 | }
|
14851 | }
|
14852 |
|
14853 | return true;
|
14854 | }
|
14855 |
|
14856 |
|
14857 | for (var i = 0; i < hunks.length; i++) {
|
14858 | var hunk = hunks[i],
|
14859 | maxLine = lines.length - hunk.oldLines,
|
14860 | localOffset = 0,
|
14861 | toPos = offset + hunk.oldStart - 1;
|
14862 | var iterator = distanceIterator(toPos, minLine, maxLine);
|
14863 |
|
14864 | for (; localOffset !== undefined; localOffset = iterator()) {
|
14865 | if (hunkFits(hunk, toPos + localOffset)) {
|
14866 | hunk.offset = offset += localOffset;
|
14867 | break;
|
14868 | }
|
14869 | }
|
14870 |
|
14871 | if (localOffset === undefined) {
|
14872 | return false;
|
14873 | }
|
14874 |
|
14875 |
|
14876 |
|
14877 | minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
|
14878 | }
|
14879 |
|
14880 |
|
14881 | var diffOffset = 0;
|
14882 |
|
14883 | for (var _i = 0; _i < hunks.length; _i++) {
|
14884 | var _hunk = hunks[_i],
|
14885 | _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
|
14886 |
|
14887 | diffOffset += _hunk.newLines - _hunk.oldLines;
|
14888 |
|
14889 | for (var j = 0; j < _hunk.lines.length; j++) {
|
14890 | var line = _hunk.lines[j],
|
14891 | operation = line.length > 0 ? line[0] : ' ',
|
14892 | content = line.length > 0 ? line.substr(1) : line,
|
14893 | delimiter = _hunk.linedelimiters[j];
|
14894 |
|
14895 | if (operation === ' ') {
|
14896 | _toPos++;
|
14897 | } else if (operation === '-') {
|
14898 | lines.splice(_toPos, 1);
|
14899 | delimiters.splice(_toPos, 1);
|
14900 |
|
14901 | } else if (operation === '+') {
|
14902 | lines.splice(_toPos, 0, content);
|
14903 | delimiters.splice(_toPos, 0, delimiter);
|
14904 | _toPos++;
|
14905 | } else if (operation === '\\') {
|
14906 | var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
|
14907 |
|
14908 | if (previousOperation === '+') {
|
14909 | removeEOFNL = true;
|
14910 | } else if (previousOperation === '-') {
|
14911 | addEOFNL = true;
|
14912 | }
|
14913 | }
|
14914 | }
|
14915 | }
|
14916 |
|
14917 |
|
14918 | if (removeEOFNL) {
|
14919 | while (!lines[lines.length - 1]) {
|
14920 | lines.pop();
|
14921 | delimiters.pop();
|
14922 | }
|
14923 | } else if (addEOFNL) {
|
14924 | lines.push('');
|
14925 | delimiters.push('\n');
|
14926 | }
|
14927 |
|
14928 | for (var _k = 0; _k < lines.length - 1; _k++) {
|
14929 | lines[_k] = lines[_k] + delimiters[_k];
|
14930 | }
|
14931 |
|
14932 | return lines.join('');
|
14933 | }
|
14934 |
|
14935 |
|
14936 | function applyPatches(uniDiff, options) {
|
14937 | if (typeof uniDiff === 'string') {
|
14938 | uniDiff = parsePatch(uniDiff);
|
14939 | }
|
14940 |
|
14941 | var currentIndex = 0;
|
14942 |
|
14943 | function processIndex() {
|
14944 | var index = uniDiff[currentIndex++];
|
14945 |
|
14946 | if (!index) {
|
14947 | return options.complete();
|
14948 | }
|
14949 |
|
14950 | options.loadFile(index, function (err, data) {
|
14951 | if (err) {
|
14952 | return options.complete(err);
|
14953 | }
|
14954 |
|
14955 | var updatedContent = applyPatch(data, index, options);
|
14956 | options.patched(index, updatedContent, function (err) {
|
14957 | if (err) {
|
14958 | return options.complete(err);
|
14959 | }
|
14960 |
|
14961 | processIndex();
|
14962 | });
|
14963 | });
|
14964 | }
|
14965 |
|
14966 | processIndex();
|
14967 | }
|
14968 |
|
14969 | function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
14970 | if (!options) {
|
14971 | options = {};
|
14972 | }
|
14973 |
|
14974 | if (typeof options.context === 'undefined') {
|
14975 | options.context = 4;
|
14976 | }
|
14977 |
|
14978 | var diff = diffLines(oldStr, newStr, options);
|
14979 | diff.push({
|
14980 | value: '',
|
14981 | lines: []
|
14982 | });
|
14983 |
|
14984 | function contextLines(lines) {
|
14985 | return lines.map(function (entry) {
|
14986 | return ' ' + entry;
|
14987 | });
|
14988 | }
|
14989 |
|
14990 | var hunks = [];
|
14991 | var oldRangeStart = 0,
|
14992 | newRangeStart = 0,
|
14993 | curRange = [],
|
14994 | oldLine = 1,
|
14995 | newLine = 1;
|
14996 |
|
14997 | var _loop = function _loop(i) {
|
14998 | var current = diff[i],
|
14999 | lines = current.lines || current.value.replace(/\n$/, '').split('\n');
|
15000 | current.lines = lines;
|
15001 |
|
15002 | if (current.added || current.removed) {
|
15003 | var _curRange;
|
15004 |
|
15005 |
|
15006 | if (!oldRangeStart) {
|
15007 | var prev = diff[i - 1];
|
15008 | oldRangeStart = oldLine;
|
15009 | newRangeStart = newLine;
|
15010 |
|
15011 | if (prev) {
|
15012 | curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
|
15013 | oldRangeStart -= curRange.length;
|
15014 | newRangeStart -= curRange.length;
|
15015 | }
|
15016 | }
|
15017 |
|
15018 |
|
15019 | (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
|
15020 | return (current.added ? '+' : '-') + entry;
|
15021 | })));
|
15022 |
|
15023 |
|
15024 | if (current.added) {
|
15025 | newLine += lines.length;
|
15026 | } else {
|
15027 | oldLine += lines.length;
|
15028 | }
|
15029 | } else {
|
15030 |
|
15031 | if (oldRangeStart) {
|
15032 |
|
15033 | if (lines.length <= options.context * 2 && i < diff.length - 2) {
|
15034 | var _curRange2;
|
15035 |
|
15036 |
|
15037 | (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
|
15038 | } else {
|
15039 | var _curRange3;
|
15040 |
|
15041 |
|
15042 | var contextSize = Math.min(lines.length, options.context);
|
15043 |
|
15044 | (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
|
15045 |
|
15046 | var hunk = {
|
15047 | oldStart: oldRangeStart,
|
15048 | oldLines: oldLine - oldRangeStart + contextSize,
|
15049 | newStart: newRangeStart,
|
15050 | newLines: newLine - newRangeStart + contextSize,
|
15051 | lines: curRange
|
15052 | };
|
15053 |
|
15054 | if (i >= diff.length - 2 && lines.length <= options.context) {
|
15055 |
|
15056 | var oldEOFNewline = /\n$/.test(oldStr);
|
15057 | var newEOFNewline = /\n$/.test(newStr);
|
15058 | var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
|
15059 |
|
15060 | if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
|
15061 |
|
15062 |
|
15063 | curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
|
15064 | }
|
15065 |
|
15066 | if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
|
15067 | curRange.push('\\ No newline at end of file');
|
15068 | }
|
15069 | }
|
15070 |
|
15071 | hunks.push(hunk);
|
15072 | oldRangeStart = 0;
|
15073 | newRangeStart = 0;
|
15074 | curRange = [];
|
15075 | }
|
15076 | }
|
15077 |
|
15078 | oldLine += lines.length;
|
15079 | newLine += lines.length;
|
15080 | }
|
15081 | };
|
15082 |
|
15083 | for (var i = 0; i < diff.length; i++) {
|
15084 | _loop(i);
|
15085 | }
|
15086 |
|
15087 | return {
|
15088 | oldFileName: oldFileName,
|
15089 | newFileName: newFileName,
|
15090 | oldHeader: oldHeader,
|
15091 | newHeader: newHeader,
|
15092 | hunks: hunks
|
15093 | };
|
15094 | }
|
15095 |
|
15096 | function formatPatch(diff) {
|
15097 | var ret = [];
|
15098 |
|
15099 | if (diff.oldFileName == diff.newFileName) {
|
15100 | ret.push('Index: ' + diff.oldFileName);
|
15101 | }
|
15102 |
|
15103 | ret.push('===================================================================');
|
15104 | ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
|
15105 | ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
|
15106 |
|
15107 | for (var i = 0; i < diff.hunks.length; i++) {
|
15108 | var hunk = diff.hunks[i];
|
15109 |
|
15110 |
|
15111 |
|
15112 | if (hunk.oldLines === 0) {
|
15113 | hunk.oldStart -= 1;
|
15114 | }
|
15115 |
|
15116 | if (hunk.newLines === 0) {
|
15117 | hunk.newStart -= 1;
|
15118 | }
|
15119 |
|
15120 | ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
|
15121 | ret.push.apply(ret, hunk.lines);
|
15122 | }
|
15123 |
|
15124 | return ret.join('\n') + '\n';
|
15125 | }
|
15126 |
|
15127 | function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
|
15128 | return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
|
15129 | }
|
15130 |
|
15131 | function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
|
15132 | return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
|
15133 | }
|
15134 |
|
15135 | function arrayEqual(a, b) {
|
15136 | if (a.length !== b.length) {
|
15137 | return false;
|
15138 | }
|
15139 |
|
15140 | return arrayStartsWith(a, b);
|
15141 | }
|
15142 |
|
15143 | function arrayStartsWith(array, start) {
|
15144 | if (start.length > array.length) {
|
15145 | return false;
|
15146 | }
|
15147 |
|
15148 | for (var i = 0; i < start.length; i++) {
|
15149 | if (start[i] !== array[i]) {
|
15150 | return false;
|
15151 | }
|
15152 | }
|
15153 |
|
15154 | return true;
|
15155 | }
|
15156 |
|
15157 | function calcLineCount(hunk) {
|
15158 | var _calcOldNewLineCount = calcOldNewLineCount(hunk.lines),
|
15159 | oldLines = _calcOldNewLineCount.oldLines,
|
15160 | newLines = _calcOldNewLineCount.newLines;
|
15161 |
|
15162 | if (oldLines !== undefined) {
|
15163 | hunk.oldLines = oldLines;
|
15164 | } else {
|
15165 | delete hunk.oldLines;
|
15166 | }
|
15167 |
|
15168 | if (newLines !== undefined) {
|
15169 | hunk.newLines = newLines;
|
15170 | } else {
|
15171 | delete hunk.newLines;
|
15172 | }
|
15173 | }
|
15174 |
|
15175 | function merge(mine, theirs, base) {
|
15176 | mine = loadPatch(mine, base);
|
15177 | theirs = loadPatch(theirs, base);
|
15178 | var ret = {};
|
15179 |
|
15180 |
|
15181 |
|
15182 | if (mine.index || theirs.index) {
|
15183 | ret.index = mine.index || theirs.index;
|
15184 | }
|
15185 |
|
15186 | if (mine.newFileName || theirs.newFileName) {
|
15187 | if (!fileNameChanged(mine)) {
|
15188 |
|
15189 | ret.oldFileName = theirs.oldFileName || mine.oldFileName;
|
15190 | ret.newFileName = theirs.newFileName || mine.newFileName;
|
15191 | ret.oldHeader = theirs.oldHeader || mine.oldHeader;
|
15192 | ret.newHeader = theirs.newHeader || mine.newHeader;
|
15193 | } else if (!fileNameChanged(theirs)) {
|
15194 |
|
15195 | ret.oldFileName = mine.oldFileName;
|
15196 | ret.newFileName = mine.newFileName;
|
15197 | ret.oldHeader = mine.oldHeader;
|
15198 | ret.newHeader = mine.newHeader;
|
15199 | } else {
|
15200 |
|
15201 | ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
|
15202 | ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
|
15203 | ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
|
15204 | ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
|
15205 | }
|
15206 | }
|
15207 |
|
15208 | ret.hunks = [];
|
15209 | var mineIndex = 0,
|
15210 | theirsIndex = 0,
|
15211 | mineOffset = 0,
|
15212 | theirsOffset = 0;
|
15213 |
|
15214 | while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
|
15215 | var mineCurrent = mine.hunks[mineIndex] || {
|
15216 | oldStart: Infinity
|
15217 | },
|
15218 | theirsCurrent = theirs.hunks[theirsIndex] || {
|
15219 | oldStart: Infinity
|
15220 | };
|
15221 |
|
15222 | if (hunkBefore(mineCurrent, theirsCurrent)) {
|
15223 |
|
15224 | ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
|
15225 | mineIndex++;
|
15226 | theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
|
15227 | } else if (hunkBefore(theirsCurrent, mineCurrent)) {
|
15228 |
|
15229 | ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
|
15230 | theirsIndex++;
|
15231 | mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
|
15232 | } else {
|
15233 |
|
15234 | var mergedHunk = {
|
15235 | oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
|
15236 | oldLines: 0,
|
15237 | newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
|
15238 | newLines: 0,
|
15239 | lines: []
|
15240 | };
|
15241 | mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
|
15242 | theirsIndex++;
|
15243 | mineIndex++;
|
15244 | ret.hunks.push(mergedHunk);
|
15245 | }
|
15246 | }
|
15247 |
|
15248 | return ret;
|
15249 | }
|
15250 |
|
15251 | function loadPatch(param, base) {
|
15252 | if (typeof param === 'string') {
|
15253 | if (/^@@/m.test(param) || /^Index:/m.test(param)) {
|
15254 | return parsePatch(param)[0];
|
15255 | }
|
15256 |
|
15257 | if (!base) {
|
15258 | throw new Error('Must provide a base reference or pass in a patch');
|
15259 | }
|
15260 |
|
15261 | return structuredPatch(undefined, undefined, base, param);
|
15262 | }
|
15263 |
|
15264 | return param;
|
15265 | }
|
15266 |
|
15267 | function fileNameChanged(patch) {
|
15268 | return patch.newFileName && patch.newFileName !== patch.oldFileName;
|
15269 | }
|
15270 |
|
15271 | function selectField(index, mine, theirs) {
|
15272 | if (mine === theirs) {
|
15273 | return mine;
|
15274 | } else {
|
15275 | index.conflict = true;
|
15276 | return {
|
15277 | mine: mine,
|
15278 | theirs: theirs
|
15279 | };
|
15280 | }
|
15281 | }
|
15282 |
|
15283 | function hunkBefore(test, check) {
|
15284 | return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
|
15285 | }
|
15286 |
|
15287 | function cloneHunk(hunk, offset) {
|
15288 | return {
|
15289 | oldStart: hunk.oldStart,
|
15290 | oldLines: hunk.oldLines,
|
15291 | newStart: hunk.newStart + offset,
|
15292 | newLines: hunk.newLines,
|
15293 | lines: hunk.lines
|
15294 | };
|
15295 | }
|
15296 |
|
15297 | function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
|
15298 |
|
15299 |
|
15300 | var mine = {
|
15301 | offset: mineOffset,
|
15302 | lines: mineLines,
|
15303 | index: 0
|
15304 | },
|
15305 | their = {
|
15306 | offset: theirOffset,
|
15307 | lines: theirLines,
|
15308 | index: 0
|
15309 | };
|
15310 |
|
15311 | insertLeading(hunk, mine, their);
|
15312 | insertLeading(hunk, their, mine);
|
15313 |
|
15314 | while (mine.index < mine.lines.length && their.index < their.lines.length) {
|
15315 | var mineCurrent = mine.lines[mine.index],
|
15316 | theirCurrent = their.lines[their.index];
|
15317 |
|
15318 | if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
|
15319 |
|
15320 | mutualChange(hunk, mine, their);
|
15321 | } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
|
15322 | var _hunk$lines;
|
15323 |
|
15324 |
|
15325 | (_hunk$lines = hunk.lines).push.apply(_hunk$lines, _toConsumableArray(collectChange(mine)));
|
15326 | } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
|
15327 | var _hunk$lines2;
|
15328 |
|
15329 |
|
15330 | (_hunk$lines2 = hunk.lines).push.apply(_hunk$lines2, _toConsumableArray(collectChange(their)));
|
15331 | } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
|
15332 |
|
15333 | removal(hunk, mine, their);
|
15334 | } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
|
15335 |
|
15336 | removal(hunk, their, mine, true);
|
15337 | } else if (mineCurrent === theirCurrent) {
|
15338 |
|
15339 | hunk.lines.push(mineCurrent);
|
15340 | mine.index++;
|
15341 | their.index++;
|
15342 | } else {
|
15343 |
|
15344 | conflict(hunk, collectChange(mine), collectChange(their));
|
15345 | }
|
15346 | }
|
15347 |
|
15348 |
|
15349 | insertTrailing(hunk, mine);
|
15350 | insertTrailing(hunk, their);
|
15351 | calcLineCount(hunk);
|
15352 | }
|
15353 |
|
15354 | function mutualChange(hunk, mine, their) {
|
15355 | var myChanges = collectChange(mine),
|
15356 | theirChanges = collectChange(their);
|
15357 |
|
15358 | if (allRemoves(myChanges) && allRemoves(theirChanges)) {
|
15359 |
|
15360 | if (arrayStartsWith(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
|
15361 | var _hunk$lines3;
|
15362 |
|
15363 | (_hunk$lines3 = hunk.lines).push.apply(_hunk$lines3, _toConsumableArray(myChanges));
|
15364 |
|
15365 | return;
|
15366 | } else if (arrayStartsWith(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
|
15367 | var _hunk$lines4;
|
15368 |
|
15369 | (_hunk$lines4 = hunk.lines).push.apply(_hunk$lines4, _toConsumableArray(theirChanges));
|
15370 |
|
15371 | return;
|
15372 | }
|
15373 | } else if (arrayEqual(myChanges, theirChanges)) {
|
15374 | var _hunk$lines5;
|
15375 |
|
15376 | (_hunk$lines5 = hunk.lines).push.apply(_hunk$lines5, _toConsumableArray(myChanges));
|
15377 |
|
15378 | return;
|
15379 | }
|
15380 |
|
15381 | conflict(hunk, myChanges, theirChanges);
|
15382 | }
|
15383 |
|
15384 | function removal(hunk, mine, their, swap) {
|
15385 | var myChanges = collectChange(mine),
|
15386 | theirChanges = collectContext(their, myChanges);
|
15387 |
|
15388 | if (theirChanges.merged) {
|
15389 | var _hunk$lines6;
|
15390 |
|
15391 | (_hunk$lines6 = hunk.lines).push.apply(_hunk$lines6, _toConsumableArray(theirChanges.merged));
|
15392 | } else {
|
15393 | conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
|
15394 | }
|
15395 | }
|
15396 |
|
15397 | function conflict(hunk, mine, their) {
|
15398 | hunk.conflict = true;
|
15399 | hunk.lines.push({
|
15400 | conflict: true,
|
15401 | mine: mine,
|
15402 | theirs: their
|
15403 | });
|
15404 | }
|
15405 |
|
15406 | function insertLeading(hunk, insert, their) {
|
15407 | while (insert.offset < their.offset && insert.index < insert.lines.length) {
|
15408 | var line = insert.lines[insert.index++];
|
15409 | hunk.lines.push(line);
|
15410 | insert.offset++;
|
15411 | }
|
15412 | }
|
15413 |
|
15414 | function insertTrailing(hunk, insert) {
|
15415 | while (insert.index < insert.lines.length) {
|
15416 | var line = insert.lines[insert.index++];
|
15417 | hunk.lines.push(line);
|
15418 | }
|
15419 | }
|
15420 |
|
15421 | function collectChange(state) {
|
15422 | var ret = [],
|
15423 | operation = state.lines[state.index][0];
|
15424 |
|
15425 | while (state.index < state.lines.length) {
|
15426 | var line = state.lines[state.index];
|
15427 |
|
15428 | if (operation === '-' && line[0] === '+') {
|
15429 | operation = '+';
|
15430 | }
|
15431 |
|
15432 | if (operation === line[0]) {
|
15433 | ret.push(line);
|
15434 | state.index++;
|
15435 | } else {
|
15436 | break;
|
15437 | }
|
15438 | }
|
15439 |
|
15440 | return ret;
|
15441 | }
|
15442 |
|
15443 | function collectContext(state, matchChanges) {
|
15444 | var changes = [],
|
15445 | merged = [],
|
15446 | matchIndex = 0,
|
15447 | contextChanges = false,
|
15448 | conflicted = false;
|
15449 |
|
15450 | while (matchIndex < matchChanges.length && state.index < state.lines.length) {
|
15451 | var change = state.lines[state.index],
|
15452 | match = matchChanges[matchIndex];
|
15453 |
|
15454 | if (match[0] === '+') {
|
15455 | break;
|
15456 | }
|
15457 |
|
15458 | contextChanges = contextChanges || change[0] !== ' ';
|
15459 | merged.push(match);
|
15460 | matchIndex++;
|
15461 |
|
15462 |
|
15463 | if (change[0] === '+') {
|
15464 | conflicted = true;
|
15465 |
|
15466 | while (change[0] === '+') {
|
15467 | changes.push(change);
|
15468 | change = state.lines[++state.index];
|
15469 | }
|
15470 | }
|
15471 |
|
15472 | if (match.substr(1) === change.substr(1)) {
|
15473 | changes.push(change);
|
15474 | state.index++;
|
15475 | } else {
|
15476 | conflicted = true;
|
15477 | }
|
15478 | }
|
15479 |
|
15480 | if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
|
15481 | conflicted = true;
|
15482 | }
|
15483 |
|
15484 | if (conflicted) {
|
15485 | return changes;
|
15486 | }
|
15487 |
|
15488 | while (matchIndex < matchChanges.length) {
|
15489 | merged.push(matchChanges[matchIndex++]);
|
15490 | }
|
15491 |
|
15492 | return {
|
15493 | merged: merged,
|
15494 | changes: changes
|
15495 | };
|
15496 | }
|
15497 |
|
15498 | function allRemoves(changes) {
|
15499 | return changes.reduce(function (prev, change) {
|
15500 | return prev && change[0] === '-';
|
15501 | }, true);
|
15502 | }
|
15503 |
|
15504 | function skipRemoveSuperset(state, removeChanges, delta) {
|
15505 | for (var i = 0; i < delta; i++) {
|
15506 | var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
|
15507 |
|
15508 | if (state.lines[state.index + i] !== ' ' + changeContent) {
|
15509 | return false;
|
15510 | }
|
15511 | }
|
15512 |
|
15513 | state.index += delta;
|
15514 | return true;
|
15515 | }
|
15516 |
|
15517 | function calcOldNewLineCount(lines) {
|
15518 | var oldLines = 0;
|
15519 | var newLines = 0;
|
15520 | lines.forEach(function (line) {
|
15521 | if (typeof line !== 'string') {
|
15522 | var myCount = calcOldNewLineCount(line.mine);
|
15523 | var theirCount = calcOldNewLineCount(line.theirs);
|
15524 |
|
15525 | if (oldLines !== undefined) {
|
15526 | if (myCount.oldLines === theirCount.oldLines) {
|
15527 | oldLines += myCount.oldLines;
|
15528 | } else {
|
15529 | oldLines = undefined;
|
15530 | }
|
15531 | }
|
15532 |
|
15533 | if (newLines !== undefined) {
|
15534 | if (myCount.newLines === theirCount.newLines) {
|
15535 | newLines += myCount.newLines;
|
15536 | } else {
|
15537 | newLines = undefined;
|
15538 | }
|
15539 | }
|
15540 | } else {
|
15541 | if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
|
15542 | newLines++;
|
15543 | }
|
15544 |
|
15545 | if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
|
15546 | oldLines++;
|
15547 | }
|
15548 | }
|
15549 | });
|
15550 | return {
|
15551 | oldLines: oldLines,
|
15552 | newLines: newLines
|
15553 | };
|
15554 | }
|
15555 |
|
15556 |
|
15557 | function convertChangesToDMP(changes) {
|
15558 | var ret = [],
|
15559 | change,
|
15560 | operation;
|
15561 |
|
15562 | for (var i = 0; i < changes.length; i++) {
|
15563 | change = changes[i];
|
15564 |
|
15565 | if (change.added) {
|
15566 | operation = 1;
|
15567 | } else if (change.removed) {
|
15568 | operation = -1;
|
15569 | } else {
|
15570 | operation = 0;
|
15571 | }
|
15572 |
|
15573 | ret.push([operation, change.value]);
|
15574 | }
|
15575 |
|
15576 | return ret;
|
15577 | }
|
15578 |
|
15579 | function convertChangesToXML(changes) {
|
15580 | var ret = [];
|
15581 |
|
15582 | for (var i = 0; i < changes.length; i++) {
|
15583 | var change = changes[i];
|
15584 |
|
15585 | if (change.added) {
|
15586 | ret.push('<ins>');
|
15587 | } else if (change.removed) {
|
15588 | ret.push('<del>');
|
15589 | }
|
15590 |
|
15591 | ret.push(escapeHTML(change.value));
|
15592 |
|
15593 | if (change.added) {
|
15594 | ret.push('</ins>');
|
15595 | } else if (change.removed) {
|
15596 | ret.push('</del>');
|
15597 | }
|
15598 | }
|
15599 |
|
15600 | return ret.join('');
|
15601 | }
|
15602 |
|
15603 | function escapeHTML(s) {
|
15604 | var n = s;
|
15605 | n = n.replace(/&/g, '&');
|
15606 | n = n.replace(/</g, '<');
|
15607 | n = n.replace(/>/g, '>');
|
15608 | n = n.replace(/"/g, '"');
|
15609 | return n;
|
15610 | }
|
15611 |
|
15612 | var index_es6 = Object.freeze({
|
15613 | __proto__: null,
|
15614 | Diff: Diff,
|
15615 | applyPatch: applyPatch,
|
15616 | applyPatches: applyPatches,
|
15617 | canonicalize: canonicalize,
|
15618 | convertChangesToDMP: convertChangesToDMP,
|
15619 | convertChangesToXML: convertChangesToXML,
|
15620 | createPatch: createPatch,
|
15621 | createTwoFilesPatch: createTwoFilesPatch,
|
15622 | diffArrays: diffArrays,
|
15623 | diffChars: diffChars,
|
15624 | diffCss: diffCss,
|
15625 | diffJson: diffJson,
|
15626 | diffLines: diffLines,
|
15627 | diffSentences: diffSentences,
|
15628 | diffTrimmedLines: diffTrimmedLines,
|
15629 | diffWords: diffWords,
|
15630 | diffWordsWithSpace: diffWordsWithSpace,
|
15631 | merge: merge,
|
15632 | parsePatch: parsePatch,
|
15633 | structuredPatch: structuredPatch
|
15634 | });
|
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 | const {
|
15640 | getStdin
|
15641 | } = thirdParty;
|
15642 | const {
|
15643 | createIgnorer,
|
15644 | errors,
|
15645 | coreOptions: coreOptions$1,
|
15646 | optionsModule,
|
15647 | optionsNormalizer,
|
15648 | utils: {
|
15649 | arrayify
|
15650 | }
|
15651 | } = prettierInternal;
|
15652 | const {
|
15653 | expandPatterns: expandPatterns$1,
|
15654 | fixWindowsSlashes: fixWindowsSlashes$1
|
15655 | } = expandPatterns_1;
|
15656 | const OPTION_USAGE_THRESHOLD = 25;
|
15657 | const CHOICE_USAGE_MARGIN = 3;
|
15658 | const CHOICE_USAGE_INDENTATION = 2;
|
15659 |
|
15660 | function getOptions(argv, detailedOptions) {
|
15661 | return fromPairs_1(detailedOptions.filter(({
|
15662 | forwardToApi
|
15663 | }) => forwardToApi).map(({
|
15664 | forwardToApi,
|
15665 | name
|
15666 | }) => [forwardToApi, argv[name]]));
|
15667 | }
|
15668 |
|
15669 | function cliifyOptions(object, apiDetailedOptionMap) {
|
15670 | return Object.keys(object || {}).reduce((output, key) => {
|
15671 | const apiOption = apiDetailedOptionMap[key];
|
15672 | const cliKey = apiOption ? apiOption.name : key;
|
15673 | output[dashify(cliKey)] = object[key];
|
15674 | return output;
|
15675 | }, {});
|
15676 | }
|
15677 |
|
15678 | function diff(a, b) {
|
15679 | return index_es6.createTwoFilesPatch("", "", a, b, "", "", {
|
15680 | context: 2
|
15681 | });
|
15682 | }
|
15683 |
|
15684 | function handleError(context, filename, error) {
|
15685 | if (error instanceof errors.UndefinedParserError) {
|
15686 |
|
15687 |
|
15688 |
|
15689 | if ((context.argv.write || context.argv["ignore-unknown"]) && isTty()) {
|
15690 | readline__default['default'].clearLine(process.stdout, 0);
|
15691 | readline__default['default'].cursorTo(process.stdout, 0, null);
|
15692 | }
|
15693 |
|
15694 | if (context.argv["ignore-unknown"]) {
|
15695 | return;
|
15696 | }
|
15697 |
|
15698 | if (!context.argv.check && !context.argv["list-different"]) {
|
15699 | process.exitCode = 2;
|
15700 | }
|
15701 |
|
15702 | context.logger.error(error.message);
|
15703 | return;
|
15704 | }
|
15705 |
|
15706 | if (context.argv.write) {
|
15707 |
|
15708 | process.stdout.write("\n");
|
15709 | }
|
15710 |
|
15711 | const isParseError = Boolean(error && error.loc);
|
15712 | const isValidationError = /^Invalid \S+ value\./.test(error && error.message);
|
15713 |
|
15714 | if (isParseError) {
|
15715 |
|
15716 | context.logger.error(`${filename}: ${String(error)}`);
|
15717 | } else if (isValidationError || error instanceof errors.ConfigError) {
|
15718 |
|
15719 | context.logger.error(error.message);
|
15720 |
|
15721 | process.exit(1);
|
15722 | } else if (error instanceof errors.DebugError) {
|
15723 |
|
15724 | context.logger.error(`${filename}: ${error.message}`);
|
15725 | } else {
|
15726 |
|
15727 |
|
15728 |
|
15729 | context.logger.error(filename + ": " + (error.stack || error));
|
15730 | }
|
15731 |
|
15732 |
|
15733 | process.exitCode = 2;
|
15734 | }
|
15735 |
|
15736 | function logResolvedConfigPathOrDie(context) {
|
15737 | const configFile = src.resolveConfigFile.sync(context.argv["find-config-path"]);
|
15738 |
|
15739 | if (configFile) {
|
15740 | context.logger.log(path__default['default'].relative(process.cwd(), configFile));
|
15741 | } else {
|
15742 | process.exit(1);
|
15743 | }
|
15744 | }
|
15745 |
|
15746 | function logFileInfoOrDie(context) {
|
15747 | const options = {
|
15748 | ignorePath: context.argv["ignore-path"],
|
15749 | withNodeModules: context.argv["with-node-modules"],
|
15750 | plugins: context.argv.plugin,
|
15751 | pluginSearchDirs: context.argv["plugin-search-dir"],
|
15752 | resolveConfig: context.argv.config !== false
|
15753 | };
|
15754 | context.logger.log(src.format(fastJsonStableStringify(src.getFileInfo.sync(context.argv["file-info"], options)), {
|
15755 | parser: "json"
|
15756 | }));
|
15757 | }
|
15758 |
|
15759 | function writeOutput(context, result, options) {
|
15760 |
|
15761 | process.stdout.write(context.argv["debug-check"] ? result.filepath : result.formatted);
|
15762 |
|
15763 | if (options && options.cursorOffset >= 0) {
|
15764 | process.stderr.write(result.cursorOffset + "\n");
|
15765 | }
|
15766 | }
|
15767 |
|
15768 | function listDifferent(context, input, options, filename) {
|
15769 | if (!context.argv.check && !context.argv["list-different"]) {
|
15770 | return;
|
15771 | }
|
15772 |
|
15773 | try {
|
15774 | if (!options.filepath && !options.parser) {
|
15775 | throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
|
15776 | }
|
15777 |
|
15778 | if (!src.check(input, options)) {
|
15779 | if (!context.argv.write) {
|
15780 | context.logger.log(filename);
|
15781 | process.exitCode = 1;
|
15782 | }
|
15783 | }
|
15784 | } catch (error) {
|
15785 | context.logger.error(error.message);
|
15786 | }
|
15787 |
|
15788 | return true;
|
15789 | }
|
15790 |
|
15791 | function format(context, input, opt) {
|
15792 | if (!opt.parser && !opt.filepath) {
|
15793 | throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
|
15794 | }
|
15795 |
|
15796 | if (context.argv["debug-print-doc"]) {
|
15797 | const doc = src.__debug.printToDoc(input, opt);
|
15798 |
|
15799 | return {
|
15800 | formatted: src.__debug.formatDoc(doc)
|
15801 | };
|
15802 | }
|
15803 |
|
15804 | if (context.argv["debug-check"]) {
|
15805 | const pp = src.format(input, opt);
|
15806 | const pppp = src.format(pp, opt);
|
15807 |
|
15808 | if (pp !== pppp) {
|
15809 | throw new errors.DebugError("prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp));
|
15810 | } else {
|
15811 | const stringify = obj => JSON.stringify(obj, null, 2);
|
15812 |
|
15813 | const ast = stringify(src.__debug.parse(input, opt,
|
15814 |
|
15815 | true).ast);
|
15816 | const past = stringify(src.__debug.parse(pp, opt,
|
15817 |
|
15818 | true).ast);
|
15819 |
|
15820 |
|
15821 | if (ast !== past) {
|
15822 | const MAX_AST_SIZE = 2097152;
|
15823 |
|
15824 | const astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
|
15825 | throw new errors.DebugError("ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp));
|
15826 | }
|
15827 | }
|
15828 |
|
15829 | return {
|
15830 | formatted: pp,
|
15831 | filepath: opt.filepath || "(stdin)\n"
|
15832 | };
|
15833 | }
|
15834 |
|
15835 |
|
15836 |
|
15837 | if (context.argv["debug-benchmark"]) {
|
15838 | let benchmark;
|
15839 |
|
15840 | try {
|
15841 | benchmark = require("benchmark");
|
15842 | } catch (err) {
|
15843 | context.logger.debug("'--debug-benchmark' requires the 'benchmark' package to be installed.");
|
15844 | process.exit(2);
|
15845 | }
|
15846 |
|
15847 | context.logger.debug("'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module.");
|
15848 | const suite = new benchmark.Suite();
|
15849 | suite.add("format", () => {
|
15850 | src.formatWithCursor(input, opt);
|
15851 | }).on("cycle", event => {
|
15852 | const results = {
|
15853 | benchmark: String(event.target),
|
15854 | hz: event.target.hz,
|
15855 | ms: event.target.times.cycle * 1000
|
15856 | };
|
15857 | context.logger.debug("'--debug-benchmark' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
|
15858 | }).run({
|
15859 | async: false
|
15860 | });
|
15861 | } else if (context.argv["debug-repeat"] > 0) {
|
15862 | const repeat = context.argv["debug-repeat"];
|
15863 | context.logger.debug("'--debug-repeat' option found, running formatWithCursor " + repeat + " times.");
|
15864 |
|
15865 | const now = Date.now ? () => Date.now() : () => +new Date();
|
15866 | let totalMs = 0;
|
15867 |
|
15868 | for (let i = 0; i < repeat; ++i) {
|
15869 | const startMs = now();
|
15870 | src.formatWithCursor(input, opt);
|
15871 | totalMs += now() - startMs;
|
15872 | }
|
15873 |
|
15874 | const averageMs = totalMs / repeat;
|
15875 | const results = {
|
15876 | repeat,
|
15877 | hz: 1000 / averageMs,
|
15878 | ms: averageMs
|
15879 | };
|
15880 | context.logger.debug("'--debug-repeat' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
|
15881 | }
|
15882 |
|
15883 | return src.formatWithCursor(input, opt);
|
15884 | }
|
15885 |
|
15886 | function getOptionsOrDie(context, filePath) {
|
15887 | try {
|
15888 | if (context.argv.config === false) {
|
15889 | context.logger.debug("'--no-config' option found, skip loading config file.");
|
15890 | return null;
|
15891 | }
|
15892 |
|
15893 | context.logger.debug(context.argv.config ? `load config file from '${context.argv.config}'` : `resolve config from '${filePath}'`);
|
15894 | const options = src.resolveConfig.sync(filePath, {
|
15895 | editorconfig: context.argv.editorconfig,
|
15896 | config: context.argv.config
|
15897 | });
|
15898 | context.logger.debug("loaded options `" + JSON.stringify(options) + "`");
|
15899 | return options;
|
15900 | } catch (error) {
|
15901 | context.logger.error(`Invalid configuration file \`${filePath}\`: ` + error.message);
|
15902 | process.exit(2);
|
15903 | }
|
15904 | }
|
15905 |
|
15906 | function getOptionsForFile(context, filepath) {
|
15907 | const options = getOptionsOrDie(context, filepath);
|
15908 | const hasPlugins = options && options.plugins;
|
15909 |
|
15910 | if (hasPlugins) {
|
15911 | pushContextPlugins(context, options.plugins);
|
15912 | }
|
15913 |
|
15914 | const appliedOptions = Object.assign({
|
15915 | filepath
|
15916 | }, applyConfigPrecedence(context, options && optionsNormalizer.normalizeApiOptions(options, context.supportOptions, {
|
15917 | logger: context.logger
|
15918 | })));
|
15919 | context.logger.debug(`applied config-precedence (${context.argv["config-precedence"]}): ` + `${JSON.stringify(appliedOptions)}`);
|
15920 |
|
15921 | if (hasPlugins) {
|
15922 | popContextPlugins(context);
|
15923 | }
|
15924 |
|
15925 | return appliedOptions;
|
15926 | }
|
15927 |
|
15928 | function parseArgsToOptions(context, overrideDefaults) {
|
15929 | const minimistOptions = createMinimistOptions(context.detailedOptions);
|
15930 | const apiDetailedOptionMap = createApiDetailedOptionMap(context.detailedOptions);
|
15931 | return getOptions(optionsNormalizer.normalizeCliOptions(minimist_1(context.args, {
|
15932 | string: minimistOptions.string,
|
15933 | boolean: minimistOptions.boolean,
|
15934 | default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
|
15935 | }), context.detailedOptions, {
|
15936 | logger: false
|
15937 | }), context.detailedOptions);
|
15938 | }
|
15939 |
|
15940 | function applyConfigPrecedence(context, options) {
|
15941 | try {
|
15942 | switch (context.argv["config-precedence"]) {
|
15943 | case "cli-override":
|
15944 | return parseArgsToOptions(context, options);
|
15945 |
|
15946 | case "file-override":
|
15947 | return Object.assign({}, parseArgsToOptions(context), options);
|
15948 |
|
15949 | case "prefer-file":
|
15950 | return options || parseArgsToOptions(context);
|
15951 | }
|
15952 | } catch (error) {
|
15953 |
|
15954 | context.logger.error(error.toString());
|
15955 |
|
15956 |
|
15957 | process.exit(2);
|
15958 | }
|
15959 | }
|
15960 |
|
15961 | function formatStdin(context) {
|
15962 | const filepath = context.argv["stdin-filepath"] ? path__default['default'].resolve(process.cwd(), context.argv["stdin-filepath"]) : process.cwd();
|
15963 | const ignorer = createIgnorerFromContextOrDie(context);
|
15964 |
|
15965 |
|
15966 | const relativeFilepath = context.argv["ignore-path"] ? path__default['default'].relative(path__default['default'].dirname(context.argv["ignore-path"]), filepath) : path__default['default'].relative(process.cwd(), filepath);
|
15967 | getStdin().then(input => {
|
15968 | if (relativeFilepath && ignorer.ignores(fixWindowsSlashes$1(relativeFilepath))) {
|
15969 | writeOutput(context, {
|
15970 | formatted: input
|
15971 | });
|
15972 | return;
|
15973 | }
|
15974 |
|
15975 | const options = getOptionsForFile(context, filepath);
|
15976 |
|
15977 | if (listDifferent(context, input, options, "(stdin)")) {
|
15978 | return;
|
15979 | }
|
15980 |
|
15981 | writeOutput(context, format(context, input, options), options);
|
15982 | }).catch(error => {
|
15983 | handleError(context, relativeFilepath || "stdin", error);
|
15984 | });
|
15985 | }
|
15986 |
|
15987 | function createIgnorerFromContextOrDie(context) {
|
15988 | try {
|
15989 | return createIgnorer.sync(context.argv["ignore-path"], context.argv["with-node-modules"]);
|
15990 | } catch (e) {
|
15991 | context.logger.error(e.message);
|
15992 | process.exit(2);
|
15993 | }
|
15994 | }
|
15995 |
|
15996 | function formatFiles(context) {
|
15997 |
|
15998 |
|
15999 | const ignorer = createIgnorerFromContextOrDie(context);
|
16000 | let numberOfUnformattedFilesFound = 0;
|
16001 |
|
16002 | if (context.argv.check) {
|
16003 | context.logger.log("Checking formatting...");
|
16004 | }
|
16005 |
|
16006 | for (const pathOrError of expandPatterns$1(context)) {
|
16007 | if (typeof pathOrError === "object") {
|
16008 | context.logger.error(pathOrError.error);
|
16009 |
|
16010 | process.exitCode = 2;
|
16011 | continue;
|
16012 | }
|
16013 |
|
16014 | const filename = pathOrError;
|
16015 |
|
16016 |
|
16017 | const ignoreFilename = context.argv["ignore-path"] ? path__default['default'].relative(path__default['default'].dirname(context.argv["ignore-path"]), filename) : filename;
|
16018 | const fileIgnored = ignorer.ignores(fixWindowsSlashes$1(ignoreFilename));
|
16019 |
|
16020 | if (fileIgnored && (context.argv["debug-check"] || context.argv.write || context.argv.check || context.argv["list-different"])) {
|
16021 | continue;
|
16022 | }
|
16023 |
|
16024 | const options = Object.assign({}, getOptionsForFile(context, filename), {
|
16025 | filepath: filename
|
16026 | });
|
16027 |
|
16028 | if (isTty()) {
|
16029 | context.logger.log(filename, {
|
16030 | newline: false
|
16031 | });
|
16032 | }
|
16033 |
|
16034 | let input;
|
16035 |
|
16036 | try {
|
16037 | input = fs__default['default'].readFileSync(filename, "utf8");
|
16038 | } catch (error) {
|
16039 |
|
16040 |
|
16041 |
|
16042 | context.logger.log("");
|
16043 |
|
16044 |
|
16045 | context.logger.error(`Unable to read file: ${filename}\n${error.message}`);
|
16046 |
|
16047 |
|
16048 |
|
16049 | process.exitCode = 2;
|
16050 |
|
16051 |
|
16052 | continue;
|
16053 | }
|
16054 |
|
16055 | if (fileIgnored) {
|
16056 | writeOutput(context, {
|
16057 | formatted: input
|
16058 | }, options);
|
16059 | continue;
|
16060 | }
|
16061 |
|
16062 | const start = Date.now();
|
16063 | let result;
|
16064 | let output;
|
16065 |
|
16066 | try {
|
16067 | result = format(context, input, options);
|
16068 | output = result.formatted;
|
16069 | } catch (error) {
|
16070 | handleError(context, filename, error);
|
16071 | continue;
|
16072 | }
|
16073 |
|
16074 | const isDifferent = output !== input;
|
16075 |
|
16076 | if (isTty()) {
|
16077 |
|
16078 | readline__default['default'].clearLine(process.stdout, 0);
|
16079 | readline__default['default'].cursorTo(process.stdout, 0, null);
|
16080 | }
|
16081 |
|
16082 | if (context.argv.write) {
|
16083 |
|
16084 |
|
16085 | if (isDifferent) {
|
16086 | if (!context.argv.check && !context.argv["list-different"]) {
|
16087 | context.logger.log(`${filename} ${Date.now() - start}ms`);
|
16088 | }
|
16089 |
|
16090 | try {
|
16091 | fs__default['default'].writeFileSync(filename, output, "utf8");
|
16092 | } catch (error) {
|
16093 |
|
16094 | context.logger.error(`Unable to write file: ${filename}\n${error.message}`);
|
16095 |
|
16096 |
|
16097 |
|
16098 | process.exitCode = 2;
|
16099 | }
|
16100 | } else if (!context.argv.check && !context.argv["list-different"]) {
|
16101 | context.logger.log(`${source.grey(filename)} ${Date.now() - start}ms`);
|
16102 | }
|
16103 | } else if (context.argv["debug-check"]) {
|
16104 |
|
16105 | if (result.filepath) {
|
16106 | context.logger.log(result.filepath);
|
16107 | } else {
|
16108 | process.exitCode = 2;
|
16109 | }
|
16110 | } else if (!context.argv.check && !context.argv["list-different"]) {
|
16111 | writeOutput(context, result, options);
|
16112 | }
|
16113 |
|
16114 | if (isDifferent) {
|
16115 | if (context.argv.check) {
|
16116 | context.logger.warn(filename);
|
16117 | } else if (context.argv["list-different"]) {
|
16118 | context.logger.log(filename);
|
16119 | }
|
16120 |
|
16121 | numberOfUnformattedFilesFound += 1;
|
16122 | }
|
16123 | }
|
16124 |
|
16125 |
|
16126 | if (context.argv.check) {
|
16127 | if (numberOfUnformattedFilesFound === 0) {
|
16128 | context.logger.log("All matched files use Prettier code style!");
|
16129 | } else {
|
16130 | context.logger.warn(context.argv.write ? "Code style issues fixed in the above file(s)." : "Code style issues found in the above file(s). Forgot to run Prettier?");
|
16131 | }
|
16132 | }
|
16133 |
|
16134 |
|
16135 | if ((context.argv.check || context.argv["list-different"]) && numberOfUnformattedFilesFound > 0 && !process.exitCode && !context.argv.write) {
|
16136 | process.exitCode = 1;
|
16137 | }
|
16138 | }
|
16139 |
|
16140 | function getOptionsWithOpposites(options) {
|
16141 |
|
16142 | const optionsWithOpposites = options.map(option => [option.description ? option : null, option.oppositeDescription ? Object.assign({}, option, {
|
16143 | name: `no-${option.name}`,
|
16144 | type: "boolean",
|
16145 | description: option.oppositeDescription
|
16146 | }) : null]);
|
16147 | return flatten_1(optionsWithOpposites).filter(Boolean);
|
16148 | }
|
16149 |
|
16150 | function createUsage(context) {
|
16151 | const options = getOptionsWithOpposites(context.detailedOptions).filter(
|
16152 | option => !(option.type === "boolean" && option.oppositeDescription && !option.name.startsWith("no-")));
|
16153 | const groupedOptions = groupBy_1(options, option => option.category);
|
16154 | const firstCategories = constant$1.categoryOrder.slice(0, -1);
|
16155 | const lastCategories = constant$1.categoryOrder.slice(-1);
|
16156 | const restCategories = Object.keys(groupedOptions).filter(category => !constant$1.categoryOrder.includes(category));
|
16157 | const allCategories = [...firstCategories, ...restCategories, ...lastCategories];
|
16158 | const optionsUsage = allCategories.map(category => {
|
16159 | const categoryOptions = groupedOptions[category].map(option => createOptionUsage(context, option, OPTION_USAGE_THRESHOLD)).join("\n");
|
16160 | return `${category} options:\n\n${indent(categoryOptions, 2)}`;
|
16161 | });
|
16162 | return [constant$1.usageSummary].concat(optionsUsage, [""]).join("\n\n");
|
16163 | }
|
16164 |
|
16165 | function createOptionUsage(context, option, threshold) {
|
16166 | const header = createOptionUsageHeader(option);
|
16167 | const optionDefaultValue = getOptionDefaultValue(context, option.name);
|
16168 | return createOptionUsageRow(header, `${option.description}${optionDefaultValue === undefined ? "" : `\nDefaults to ${createDefaultValueDisplay(optionDefaultValue)}.`}`, threshold);
|
16169 | }
|
16170 |
|
16171 | function createDefaultValueDisplay(value) {
|
16172 | return Array.isArray(value) ? `[${value.map(createDefaultValueDisplay).join(", ")}]` : value;
|
16173 | }
|
16174 |
|
16175 | function createOptionUsageHeader(option) {
|
16176 | const name = `--${option.name}`;
|
16177 | const alias = option.alias ? `-${option.alias},` : null;
|
16178 | const type = createOptionUsageType(option);
|
16179 | return [alias, name, type].filter(Boolean).join(" ");
|
16180 | }
|
16181 |
|
16182 | function createOptionUsageRow(header, content, threshold) {
|
16183 | const separator = header.length >= threshold ? `\n${" ".repeat(threshold)}` : " ".repeat(threshold - header.length);
|
16184 | const description = content.replace(/\n/g, `\n${" ".repeat(threshold)}`);
|
16185 | return `${header}${separator}${description}`;
|
16186 | }
|
16187 |
|
16188 | function createOptionUsageType(option) {
|
16189 | switch (option.type) {
|
16190 | case "boolean":
|
16191 | return null;
|
16192 |
|
16193 | case "choice":
|
16194 | return `<${option.choices.filter(choice => !choice.deprecated && choice.since !== null).map(choice => choice.value).join("|")}>`;
|
16195 |
|
16196 | default:
|
16197 | return `<${option.type}>`;
|
16198 | }
|
16199 | }
|
16200 |
|
16201 | function createChoiceUsages(choices, margin, indentation) {
|
16202 | const activeChoices = choices.filter(choice => !choice.deprecated && choice.since !== null);
|
16203 | const threshold = activeChoices.map(choice => choice.value.length).reduce((current, length) => Math.max(current, length), 0) + margin;
|
16204 | return activeChoices.map(choice => indent(createOptionUsageRow(choice.value, choice.description, threshold), indentation));
|
16205 | }
|
16206 |
|
16207 | function createDetailedUsage(context, flag) {
|
16208 | const option = getOptionsWithOpposites(context.detailedOptions).find(option => option.name === flag || option.alias === flag);
|
16209 | const header = createOptionUsageHeader(option);
|
16210 | const description = `\n\n${indent(option.description, 2)}`;
|
16211 | const choices = option.type !== "choice" ? "" : `\n\nValid options:\n\n${createChoiceUsages(option.choices, CHOICE_USAGE_MARGIN, CHOICE_USAGE_INDENTATION).join("\n")}`;
|
16212 | const optionDefaultValue = getOptionDefaultValue(context, option.name);
|
16213 | const defaults = optionDefaultValue !== undefined ? `\n\nDefault: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
|
16214 | const pluginDefaults = option.pluginDefaults && Object.keys(option.pluginDefaults).length ? `\nPlugin defaults:${Object.keys(option.pluginDefaults).map(key => `\n* ${key}: ${createDefaultValueDisplay(option.pluginDefaults[key])}`)}` : "";
|
16215 | return `${header}${description}${choices}${defaults}${pluginDefaults}`;
|
16216 | }
|
16217 |
|
16218 | function getOptionDefaultValue(context, optionName) {
|
16219 |
|
16220 | if (!(optionName in context.detailedOptionMap)) {
|
16221 | return;
|
16222 | }
|
16223 |
|
16224 | const option = context.detailedOptionMap[optionName];
|
16225 |
|
16226 | if (option.default !== undefined) {
|
16227 | return option.default;
|
16228 | }
|
16229 |
|
16230 | const optionCamelName = camelcase(optionName);
|
16231 |
|
16232 | if (optionCamelName in context.apiDefaultOptions) {
|
16233 | return context.apiDefaultOptions[optionCamelName];
|
16234 | }
|
16235 | }
|
16236 |
|
16237 | function indent(str, spaces) {
|
16238 | return str.replace(/^/gm, " ".repeat(spaces));
|
16239 | }
|
16240 |
|
16241 | function createLogger(logLevel) {
|
16242 | return {
|
16243 | warn: createLogFunc("warn", "yellow"),
|
16244 | error: createLogFunc("error", "red"),
|
16245 | debug: createLogFunc("debug", "blue"),
|
16246 | log: createLogFunc("log")
|
16247 | };
|
16248 |
|
16249 | function createLogFunc(loggerName, color) {
|
16250 | if (!shouldLog(loggerName)) {
|
16251 | return () => {};
|
16252 | }
|
16253 |
|
16254 | const prefix = color ? `[${source[color](loggerName)}] ` : "";
|
16255 | return function (message, opts) {
|
16256 | opts = Object.assign({
|
16257 | newline: true
|
16258 | }, opts);
|
16259 | const stream = process[loggerName === "log" ? "stdout" : "stderr"];
|
16260 | stream.write(message.replace(/^/gm, prefix) + (opts.newline ? "\n" : ""));
|
16261 | };
|
16262 | }
|
16263 |
|
16264 | function shouldLog(loggerName) {
|
16265 | switch (logLevel) {
|
16266 | case "silent":
|
16267 | return false;
|
16268 |
|
16269 | case "debug":
|
16270 | if (loggerName === "debug") {
|
16271 | return true;
|
16272 | }
|
16273 |
|
16274 |
|
16275 |
|
16276 | case "log":
|
16277 | if (loggerName === "log") {
|
16278 | return true;
|
16279 | }
|
16280 |
|
16281 |
|
16282 |
|
16283 | case "warn":
|
16284 | if (loggerName === "warn") {
|
16285 | return true;
|
16286 | }
|
16287 |
|
16288 |
|
16289 |
|
16290 | case "error":
|
16291 | return loggerName === "error";
|
16292 | }
|
16293 | }
|
16294 | }
|
16295 |
|
16296 | function normalizeDetailedOption(name, option) {
|
16297 | return Object.assign({
|
16298 | category: coreOptions$1.CATEGORY_OTHER
|
16299 | }, option, {
|
16300 | choices: option.choices && option.choices.map(choice => {
|
16301 | const newChoice = Object.assign({
|
16302 | description: "",
|
16303 | deprecated: false
|
16304 | }, typeof choice === "object" ? choice : {
|
16305 | value: choice
|
16306 | });
|
16307 |
|
16308 |
|
16309 | if (newChoice.value === true) {
|
16310 | newChoice.value = "";
|
16311 | }
|
16312 |
|
16313 | return newChoice;
|
16314 | })
|
16315 | });
|
16316 | }
|
16317 |
|
16318 | function normalizeDetailedOptionMap(detailedOptionMap) {
|
16319 | return fromPairs_1(Object.entries(detailedOptionMap).sort(([leftName], [rightName]) => leftName.localeCompare(rightName)).map(([name, option]) => [name, normalizeDetailedOption(name, option)]));
|
16320 | }
|
16321 |
|
16322 | function createMinimistOptions(detailedOptions) {
|
16323 | const [boolean, string] = partition_1(detailedOptions, ({
|
16324 | type
|
16325 | }) => type === "boolean").map(detailedOptions => flatten_1(detailedOptions.map(({
|
16326 | name,
|
16327 | alias
|
16328 | }) => alias ? [name, alias] : [name])));
|
16329 | const defaults = fromPairs_1(detailedOptions.filter(option => !option.deprecated && (!option.forwardToApi || option.name === "plugin" || option.name === "plugin-search-dir") && option.default !== undefined).map(option => [option.name, option.default]));
|
16330 | return {
|
16331 |
|
16332 | alias: {},
|
16333 | boolean,
|
16334 | string,
|
16335 | default: defaults
|
16336 | };
|
16337 | }
|
16338 |
|
16339 | function createApiDetailedOptionMap(detailedOptions) {
|
16340 | return fromPairs_1(detailedOptions.filter(option => option.forwardToApi && option.forwardToApi !== option.name).map(option => [option.forwardToApi, option]));
|
16341 | }
|
16342 |
|
16343 | function createDetailedOptionMap(supportOptions) {
|
16344 | return fromPairs_1(supportOptions.map(option => {
|
16345 | const newOption = Object.assign({}, option, {
|
16346 | name: option.cliName || dashify(option.name),
|
16347 | description: option.cliDescription || option.description,
|
16348 | category: option.cliCategory || coreOptions$1.CATEGORY_FORMAT,
|
16349 | forwardToApi: option.name
|
16350 | });
|
16351 |
|
16352 |
|
16353 | if (option.deprecated) {
|
16354 | delete newOption.forwardToApi;
|
16355 | delete newOption.description;
|
16356 | delete newOption.oppositeDescription;
|
16357 | newOption.deprecated = true;
|
16358 | }
|
16359 |
|
16360 | return [newOption.name, newOption];
|
16361 | }));
|
16362 | }
|
16363 |
|
16364 |
|
16365 |
|
16366 |
|
16367 |
|
16368 |
|
16369 |
|
16370 |
|
16371 |
|
16372 |
|
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 |
|
16380 |
|
16381 | function createContext(args) {
|
16382 | const context = {
|
16383 | args,
|
16384 | stack: []
|
16385 | };
|
16386 | updateContextArgv(context);
|
16387 | normalizeContextArgv(context, ["loglevel", "plugin", "plugin-search-dir"]);
|
16388 | context.logger = createLogger(context.argv.loglevel);
|
16389 | updateContextArgv(context, context.argv.plugin, context.argv["plugin-search-dir"]);
|
16390 | return (
|
16391 |
|
16392 | context
|
16393 | );
|
16394 | }
|
16395 |
|
16396 | function initContext(context) {
|
16397 |
|
16398 | normalizeContextArgv(context);
|
16399 | }
|
16400 |
|
16401 |
|
16402 |
|
16403 |
|
16404 |
|
16405 |
|
16406 |
|
16407 | function updateContextOptions(context, plugins, pluginSearchDirs) {
|
16408 | const {
|
16409 | options: supportOptions,
|
16410 | languages
|
16411 | } = src.getSupportInfo({
|
16412 | showDeprecated: true,
|
16413 | showUnreleased: true,
|
16414 | showInternal: true,
|
16415 | plugins,
|
16416 | pluginSearchDirs
|
16417 | });
|
16418 | const detailedOptionMap = normalizeDetailedOptionMap(Object.assign({}, createDetailedOptionMap(supportOptions), constant$1.options));
|
16419 | const detailedOptions = arrayify(detailedOptionMap, "name");
|
16420 | const apiDefaultOptions = Object.assign({}, optionsModule.hiddenDefaults, fromPairs_1(supportOptions.filter(({
|
16421 | deprecated
|
16422 | }) => !deprecated).map(option => [option.name, option.default])));
|
16423 | Object.assign(context, {
|
16424 | supportOptions,
|
16425 | detailedOptions,
|
16426 | detailedOptionMap,
|
16427 | apiDefaultOptions,
|
16428 | languages
|
16429 | });
|
16430 | }
|
16431 |
|
16432 |
|
16433 |
|
16434 |
|
16435 |
|
16436 |
|
16437 |
|
16438 | function pushContextPlugins(context, plugins, pluginSearchDirs) {
|
16439 | context.stack.push(pick_1(context, ["supportOptions", "detailedOptions", "detailedOptionMap", "apiDefaultOptions", "languages"]));
|
16440 | updateContextOptions(context, plugins, pluginSearchDirs);
|
16441 | }
|
16442 |
|
16443 |
|
16444 |
|
16445 |
|
16446 |
|
16447 | function popContextPlugins(context) {
|
16448 | Object.assign(context, context.stack.pop());
|
16449 | }
|
16450 |
|
16451 | function updateContextArgv(context, plugins, pluginSearchDirs) {
|
16452 | pushContextPlugins(context, plugins, pluginSearchDirs);
|
16453 | const minimistOptions = createMinimistOptions(context.detailedOptions);
|
16454 | const argv = minimist_1(context.args, minimistOptions);
|
16455 | context.argv = argv;
|
16456 | context.filePatterns = argv._.map(file => String(file));
|
16457 | }
|
16458 |
|
16459 | function normalizeContextArgv(context, keys) {
|
16460 | const detailedOptions = !keys ? context.detailedOptions : context.detailedOptions.filter(option => keys.includes(option.name));
|
16461 | const argv = !keys ? context.argv : pick_1(context.argv, keys);
|
16462 | context.argv = optionsNormalizer.normalizeCliOptions(argv, detailedOptions, {
|
16463 | logger: context.logger
|
16464 | });
|
16465 | }
|
16466 |
|
16467 |
|
16468 | var util$1 = {
|
16469 | createContext,
|
16470 | createDetailedOptionMap,
|
16471 | createDetailedUsage,
|
16472 | createUsage,
|
16473 | format,
|
16474 | formatFiles,
|
16475 | formatStdin,
|
16476 | initContext,
|
16477 | logResolvedConfigPathOrDie,
|
16478 | logFileInfoOrDie,
|
16479 | normalizeDetailedOptionMap
|
16480 | };
|
16481 |
|
16482 | pleaseUpgradeNode(require$$1);
|
16483 |
|
16484 | function run(args) {
|
16485 | const context = util$1.createContext(args);
|
16486 |
|
16487 | try {
|
16488 | util$1.initContext(context);
|
16489 | context.logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
|
16490 |
|
16491 | if (context.argv.check && context.argv["list-different"]) {
|
16492 | context.logger.error("Cannot use --check and --list-different together.");
|
16493 | process.exit(1);
|
16494 | }
|
16495 |
|
16496 | if (context.argv.write && context.argv["debug-check"]) {
|
16497 | context.logger.error("Cannot use --write and --debug-check together.");
|
16498 | process.exit(1);
|
16499 | }
|
16500 |
|
16501 | if (context.argv["find-config-path"] && context.filePatterns.length) {
|
16502 | context.logger.error("Cannot use --find-config-path with multiple files");
|
16503 | process.exit(1);
|
16504 | }
|
16505 |
|
16506 | if (context.argv["file-info"] && context.filePatterns.length) {
|
16507 | context.logger.error("Cannot use --file-info with multiple files");
|
16508 | process.exit(1);
|
16509 | }
|
16510 |
|
16511 | if (context.argv.version) {
|
16512 | context.logger.log(src.version);
|
16513 | process.exit(0);
|
16514 | }
|
16515 |
|
16516 | if (context.argv.help !== undefined) {
|
16517 | context.logger.log(typeof context.argv.help === "string" && context.argv.help !== "" ? util$1.createDetailedUsage(context, context.argv.help) : util$1.createUsage(context));
|
16518 | process.exit(0);
|
16519 | }
|
16520 |
|
16521 | if (context.argv["support-info"]) {
|
16522 | context.logger.log(src.format(fastJsonStableStringify(src.getSupportInfo()), {
|
16523 | parser: "json"
|
16524 | }));
|
16525 | process.exit(0);
|
16526 | }
|
16527 |
|
16528 | const hasFilePatterns = context.filePatterns.length !== 0;
|
16529 | const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.args["stdin-filepath"]);
|
16530 |
|
16531 | if (context.argv["find-config-path"]) {
|
16532 | util$1.logResolvedConfigPathOrDie(context);
|
16533 | } else if (context.argv["file-info"]) {
|
16534 | util$1.logFileInfoOrDie(context);
|
16535 | } else if (useStdin) {
|
16536 | util$1.formatStdin(context);
|
16537 | } else if (hasFilePatterns) {
|
16538 | util$1.formatFiles(context);
|
16539 | } else {
|
16540 | context.logger.log(util$1.createUsage(context));
|
16541 | process.exit(1);
|
16542 | }
|
16543 | } catch (error) {
|
16544 | context.logger.error(error.message);
|
16545 | process.exit(1);
|
16546 | }
|
16547 | }
|
16548 |
|
16549 | var cli = {
|
16550 | run
|
16551 | };
|
16552 |
|
16553 | cli.run(process.argv.slice(2));
|
16554 | var prettier = {};
|
16555 |
|
16556 | module.exports = prettier;
|