1 |
|
2 |
|
3 | import * as braces from "braces";
|
4 | declare namespace micromatch {
|
5 | interface Item {
|
6 | glob: string;
|
7 | regex: RegExp;
|
8 | input: string;
|
9 | output: string;
|
10 | }
|
11 | interface Options {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | basename?: boolean | undefined;
|
27 | |
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | bash?: boolean | undefined;
|
44 | |
45 |
|
46 |
|
47 |
|
48 |
|
49 | capture?: boolean | undefined;
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 | contains?: boolean | undefined;
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 | cwd?: string | undefined;
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 | debug?: boolean | undefined;
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 | dot?: boolean | undefined;
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | expandRange?: ((left: string, right: string, options: Options) => string) | undefined;
|
82 | /**
|
83 | * Similar to the `--failglob` behavior in Bash, throws an error when no matches are found.
|
84 | *
|
85 | * @default false
|
86 | */
|
87 | failglob?: boolean | undefined;
|
88 | /**
|
89 | * To speed up processing, full parsing is skipped for a handful common glob patterns. Disable this behavior by setting this option to false.
|
90 | *
|
91 | * @default true
|
92 | */
|
93 | fastpaths?: boolean | undefined;
|
94 | /**
|
95 | * Regex flags to use in the generated regex. If defined, the `nocase` option will be overridden.
|
96 | *
|
97 | * @default undefined
|
98 | */
|
99 | flags?: boolean | undefined;
|
100 | /**
|
101 | * Custom function for formatting the returned string. This is useful for removing leading slashes, converting Windows paths to Posix paths, etc.
|
102 | *
|
103 | * @default undefined
|
104 | */
|
105 | format?: ((returnedString: string) => string) | undefined;
|
106 | /**
|
107 | * One or more glob patterns for excluding strings that should not be matched from the result.
|
108 | *
|
109 | * @default undefined
|
110 | */
|
111 | ignore?: string | readonly string[] | undefined;
|
112 | /**
|
113 | * Retain quotes in the generated regex, since quotes may also be used as an alternative to backslashes.
|
114 | *
|
115 | * @default false
|
116 | */
|
117 | keepQuotes?: boolean | undefined;
|
118 | /**
|
119 | * When `true`, brackets in the glob pattern will be escaped so that only literal brackets will be matched.
|
120 | *
|
121 | * @default undefined
|
122 | */
|
123 | literalBrackets?: boolean | undefined;
|
124 | /**
|
125 | * Support regex positive and negative lookbehinds. Note that you must be using Node 8.1.10 or higher to enable regex lookbehinds.
|
126 | *
|
127 | * @default true
|
128 | */
|
129 | lookbehinds?: boolean | undefined;
|
130 | /**
|
131 | * Alias for `basename`.
|
132 | *
|
133 | * @default false
|
134 | */
|
135 | matchBase?: boolean | undefined;
|
136 | /**
|
137 | * Limit the max length of the input string. An error is thrown if the input string is longer than this value.
|
138 | *
|
139 | * @default 65536
|
140 | */
|
141 | maxLength?: number | undefined;
|
142 | /**
|
143 | * Disable brace matching, so that `{a,b}` and `{1..3}` would be treated as literal characters.
|
144 | *
|
145 | * @default false
|
146 | */
|
147 | nobrace?: boolean | undefined;
|
148 | /**
|
149 | * Disable matching with regex brackets.
|
150 | *
|
151 | * @default undefined
|
152 | */
|
153 | nobracket?: boolean | undefined;
|
154 | /**
|
155 | * Perform case-insensitive matching. Equivalent to the regex `i` flag.
|
156 | * Note that this option is ignored when the `flags` option is defined.
|
157 | *
|
158 | * @default false
|
159 | */
|
160 | nocase?: boolean | undefined;
|
161 | /**
|
162 | * Alias for `noextglob`
|
163 | *
|
164 | * @default false
|
165 | */
|
166 | noext?: boolean | undefined;
|
167 | /**
|
168 | * Disable support for matching with extglobs (like `+(a|b)`)
|
169 | *
|
170 | * @default false
|
171 | */
|
172 | noextglob?: boolean | undefined;
|
173 | /**
|
174 | * Disable matching with globstars (`**`).
|
175 | *
|
176 | * @default undefined
|
177 | */
|
178 | noglobstar?: boolean | undefined;
|
179 | /**
|
180 | * Disallow negation (`!`) patterns, and treat leading `!` as a literal character to match.
|
181 | *
|
182 | * @default undefined
|
183 | */
|
184 | nonegate?: boolean | undefined;
|
185 | /**
|
186 | * Disable support for regex quantifiers (like `a{1,2}`) and treat them as brace patterns to be expanded.
|
187 | *
|
188 | * @default false
|
189 | */
|
190 | noquantifiers?: boolean | undefined;
|
191 | /**
|
192 | * Function to be called on ignored items.
|
193 | *
|
194 | * @default undefined
|
195 | */
|
196 | onIgnore?: ((item: Item) => void) | undefined;
|
197 | /**
|
198 | * Function to be called on matched items.
|
199 | *
|
200 | * @default undefined
|
201 | */
|
202 | onMatch?: ((item: Item) => void) | undefined;
|
203 | /**
|
204 | * Function to be called on all items, regardless of whether or not they are matched or ignored.
|
205 | *
|
206 | * @default undefined
|
207 | */
|
208 | onResult?: ((item: Item) => void) | undefined;
|
209 | /**
|
210 | * Support POSIX character classes ("posix brackets").
|
211 | *
|
212 | * @default false
|
213 | */
|
214 | posix?: boolean | undefined;
|
215 | /**
|
216 | * String to prepend to the generated regex used for matching.
|
217 | *
|
218 | * @default undefined
|
219 | */
|
220 | prepend?: boolean | undefined;
|
221 | /**
|
222 | * Use regular expression rules for `+` (instead of matching literal `+`), and for stars that follow closing parentheses or brackets (as in `)*` and `]*`).
|
223 | *
|
224 | * @default false
|
225 | */
|
226 | regex?: boolean | undefined;
|
227 | /**
|
228 | * Throw an error if brackets, braces, or parens are imbalanced.
|
229 | *
|
230 | * @default undefined
|
231 | */
|
232 | strictBrackets?: boolean | undefined;
|
233 | /**
|
234 | * When true, picomatch won't match trailing slashes with single stars.
|
235 | *
|
236 | * @default undefined
|
237 | */
|
238 | strictSlashes?: boolean | undefined;
|
239 | /**
|
240 | * Remove backslashes from returned matches.
|
241 | *
|
242 | * @default undefined
|
243 | *
|
244 | * @example
|
245 | * In this example we want to match a literal `*`:
|
246 | *
|
247 | * ```js
|
248 | * mm.match(['abc', 'a\\*c'], 'a\\*c');
|
249 | * //=> ['a\\*c']
|
250 | *
|
251 | * mm.match(['abc', 'a\\*c'], 'a\\*c', {unescape: true});
|
252 | *
|
253 | * ```
|
254 | */
|
255 | unescape?: boolean | undefined;
|
256 | /**
|
257 | * Convert all slashes in file paths to forward slashes. This does not convert slashes in the glob pattern itself
|
258 | *
|
259 | * @default undefined
|
260 | */
|
261 | windows?: boolean | undefined;
|
262 | }
|
263 |
|
264 | interface ScanOptions extends Options {
|
265 | /**
|
266 | * When `true`, the returned object will include an array of `tokens` (objects), representing each path "segment" in the scanned glob pattern.
|
267 | *
|
268 | * @default false
|
269 | */
|
270 | tokens?: boolean | undefined;
|
271 | /**
|
272 | * When `true`, the returned object will include an array of strings representing each path "segment" in the scanned glob pattern.
|
273 | * This is automatically enabled when `options.tokens` is `true`.
|
274 | *
|
275 | * @default false
|
276 | */
|
277 | parts?: boolean | undefined;
|
278 | }
|
279 |
|
280 | interface ScanInfo {
|
281 | prefix: string;
|
282 | input: string;
|
283 | start: number;
|
284 | base: string;
|
285 | glob: string;
|
286 | isBrace: boolean;
|
287 | isBracket: boolean;
|
288 | isGlob: boolean;
|
289 | isExtglob: boolean;
|
290 | isGlobstar: boolean;
|
291 | negated: boolean;
|
292 | negatedExtglob: boolean;
|
293 | }
|
294 |
|
295 | interface ScanInfoToken {
|
296 | value: string;
|
297 | depth: number;
|
298 | isGlob: boolean;
|
299 |
|
300 | backslashes?: boolean | undefined;
|
301 | isBrace?: boolean | undefined;
|
302 | isBracket?: boolean | undefined;
|
303 | isExtglob?: boolean | undefined;
|
304 | isGlobstar?: boolean | undefined;
|
305 | isPrefix?: boolean | undefined;
|
306 | negated?: boolean | undefined;
|
307 | }
|
308 |
|
309 | interface ScanInfoWithParts extends ScanInfo {
|
310 | slashes: number[];
|
311 | parts: string[];
|
312 | }
|
313 |
|
314 | interface ScanInfoWithTokens extends ScanInfoWithParts {
|
315 | maxDepth: number;
|
316 | tokens: ScanInfoToken[];
|
317 | }
|
318 | }
|
319 |
|
320 | interface Micromatch {
|
321 | /**
|
322 | * The main function takes a list of strings and one or more glob patterns to use for matching.
|
323 | *
|
324 | * @param list A list of strings to match
|
325 | * @param patterns One or more glob patterns to use for matching.
|
326 | * @param options See available options for changing how matches are performed
|
327 | * @returns Returns an array of matches
|
328 | *
|
329 | * @example
|
330 | * ```js
|
331 | * var mm = require('micromatch');
|
332 | * mm(list, patterns[, options]);
|
333 | *
|
334 | * console.log(mm(['a.js', 'a.txt'], ['*.js']));
|
335 | *
|
336 | * ```
|
337 | */
|
338 | (list: readonly string[], patterns: string | readonly string[], options?: micromatch.Options): string[];
|
339 |
|
340 | /**
|
341 | * Similar to the main function, but `pattern` must be a string.
|
342 | *
|
343 | * @param list Array of strings to match
|
344 | * @param pattern Glob pattern to use for matching.
|
345 | * @param options See available options for changing how matches are performed
|
346 | * @returns Returns an array of matches
|
347 | *
|
348 | * @example
|
349 | * ```js
|
350 | * var mm = require('micromatch');
|
351 | * mm.match(list, pattern[, options]);
|
352 | *
|
353 | * console.log(mm.match(['a.a', 'a.aa', 'a.b', 'a.c'], '*.a'));
|
354 | *
|
355 | * ```
|
356 | */
|
357 | match(list: readonly string[], pattern: string | readonly string[], options?: micromatch.Options): string[];
|
358 |
|
359 | /**
|
360 | * Returns true if the specified `string` matches the given glob `pattern`.
|
361 | *
|
362 | * @param string String to match
|
363 | * @param pattern Glob pattern to use for matching.
|
364 | * @param options See available options for changing how matches are performed
|
365 | * @returns Returns true if the string matches the glob pattern.
|
366 | *
|
367 | * @example
|
368 | * ```js
|
369 | * var mm = require('micromatch');
|
370 | * mm.isMatch(string, pattern[, options]);
|
371 | *
|
372 | * console.log(mm.isMatch('a.a', '*.a'));
|
373 | *
|
374 | * console.log(mm.isMatch('a.b', '*.a'));
|
375 | *
|
376 | * ```
|
377 | */
|
378 | isMatch(string: string, pattern: string | readonly string[], options?: micromatch.Options): boolean;
|
379 |
|
380 | /**
|
381 | * Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
|
382 | *
|
383 | * @param list The string or array of strings to test. Returns as soon as the first match is found.
|
384 | * @param patterns One or more glob patterns to use for matching.
|
385 | * @param options See available options for changing how matches are performed
|
386 | * @returns Returns true if any patterns match `str`
|
387 | *
|
388 | * @example
|
389 | * ```js
|
390 | * var mm = require('micromatch');
|
391 | * mm.some(list, patterns[, options]);
|
392 | *
|
393 | * console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
|
394 | *
|
395 | * console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
|
396 | *
|
397 | * ```
|
398 | */
|
399 | some(
|
400 | list: string | readonly string[],
|
401 | patterns: string | readonly string[],
|
402 | options?: micromatch.Options,
|
403 | ): boolean;
|
404 |
|
405 | /**
|
406 | * Returns true if every string in the given `list` matches any of the given glob `patterns`.
|
407 | *
|
408 | * @param list The string or array of strings to test.
|
409 | * @param patterns One or more glob patterns to use for matching.
|
410 | * @param options See available options for changing how matches are performed
|
411 | * @returns Returns true if any patterns match `str`
|
412 | *
|
413 | * @example
|
414 | * ```js
|
415 | * var mm = require('micromatch');
|
416 | * mm.every(list, patterns[, options]);
|
417 | *
|
418 | * console.log(mm.every('foo.js', ['foo.js']));
|
419 | *
|
420 | * console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
|
421 | *
|
422 | * console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
|
423 | *
|
424 | * console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
|
425 | *
|
426 | * ```
|
427 | */
|
428 | every(
|
429 | list: string | readonly string[],
|
430 | patterns: string | readonly string[],
|
431 | options?: micromatch.Options,
|
432 | ): boolean;
|
433 |
|
434 | /**
|
435 | * Returns true if **any** of the given glob `patterns` match the specified `string`.
|
436 | *
|
437 | * @param str The string to test.
|
438 | * @param patterns One or more glob patterns to use for matching.
|
439 | * @param options See available options for changing how matches are performed
|
440 | * @returns Returns true if any patterns match `str`
|
441 | *
|
442 | * @example
|
443 | * ```js
|
444 | * var mm = require('micromatch');
|
445 | * mm.any(string, patterns[, options]);
|
446 | *
|
447 | * console.log(mm.any('a.a', ['b.*', '*.a']));
|
448 | *
|
449 | * console.log(mm.any('a.a', 'b.*'));
|
450 | *
|
451 | * ```
|
452 | */
|
453 | any(
|
454 | str: string | readonly string[],
|
455 | patterns: string | readonly string[],
|
456 | options?: micromatch.Options,
|
457 | ): boolean;
|
458 |
|
459 | /**
|
460 | * Returns true if **all** of the given `patterns` match the specified string.
|
461 | *
|
462 | * @param str The string to test.
|
463 | * @param patterns One or more glob patterns to use for matching.
|
464 | * @param options See available options for changing how matches are performed
|
465 | * @returns Returns true if any patterns match `str`
|
466 | *
|
467 | * @example
|
468 | * ```js
|
469 | * var mm = require('micromatch');
|
470 | * mm.all(string, patterns[, options]);
|
471 | *
|
472 | * console.log(mm.all('foo.js', ['foo.js']));
|
473 | *
|
474 | *
|
475 | * console.log(mm.all('foo.js', ['*.js', '!foo.js']));
|
476 | *
|
477 | *
|
478 | * console.log(mm.all('foo.js', ['*.js', 'foo.js']));
|
479 | *
|
480 | *
|
481 | * console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
|
482 | *
|
483 | * ```
|
484 | */
|
485 | all(
|
486 | str: string | readonly string[],
|
487 | patterns: string | readonly string[],
|
488 | options?: micromatch.Options,
|
489 | ): boolean;
|
490 |
|
491 | /**
|
492 | * Returns a list of strings that _**do not match any**_ of the given `patterns`.
|
493 | *
|
494 | * @param list Array of strings to match.
|
495 | * @param patterns One or more glob pattern to use for matching.
|
496 | * @param options See available options for changing how matches are performed
|
497 | * @returns Returns an array of strings that **do not match** the given patterns.
|
498 | *
|
499 | * @example
|
500 | * ```js
|
501 | * var mm = require('micromatch');
|
502 | * mm.not(list, patterns[, options]);
|
503 | *
|
504 | * console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
|
505 | *
|
506 | * ```
|
507 | */
|
508 | not(list: readonly string[], patterns: string | readonly string[], options?: micromatch.Options): string[];
|
509 |
|
510 | /**
|
511 | * Returns true if the given `string` contains the given pattern. Similar to [.isMatch](#isMatch) but the pattern can match any part of the string.
|
512 | *
|
513 | * @param str The string to match.
|
514 | * @param patterns Glob pattern to use for matching.
|
515 | * @param options See available options for changing how matches are performed
|
516 | * @returns Returns true if the patter matches any part of `str`.
|
517 | *
|
518 | * @example
|
519 | * ```js
|
520 | * var mm = require('micromatch');
|
521 | * mm.contains(string, pattern[, options]);
|
522 | *
|
523 | * console.log(mm.contains('aa/bb/cc', '*b'));
|
524 | *
|
525 | * console.log(mm.contains('aa/bb/cc', '*d'));
|
526 | *
|
527 | * ```
|
528 | */
|
529 | contains(str: string, patterns: string | readonly string[], options?: micromatch.Options): boolean;
|
530 |
|
531 | /**
|
532 | * Filter the keys of the given object with the given `glob` pattern and `options`. Does not attempt to match nested keys.
|
533 | * If you need this feature, use [glob-object](https://github.com/jonschlinkert/glob-object) instead.
|
534 | *
|
535 | * @param object The object with keys to filter.
|
536 | * @param patterns One or more glob patterns to use for matching.
|
537 | * @param options See available options for changing how matches are performed
|
538 | * @returns Returns an object with only keys that match the given patterns.
|
539 | *
|
540 | * @example
|
541 | * ```js
|
542 | * var mm = require('micromatch');
|
543 | * mm.matchKeys(object, patterns[, options]);
|
544 | *
|
545 | * var obj = { aa: 'a', ab: 'b', ac: 'c' };
|
546 | * console.log(mm.matchKeys(obj, '*b'));
|
547 | *
|
548 | * ```
|
549 | */
|
550 | matchKeys<T>(object: T, patterns: string | readonly string[], options?: micromatch.Options): Partial<T>;
|
551 |
|
552 | /**
|
553 | * Returns a memoized matcher function from the given glob `pattern` and `options`. The returned function takes a string to match as its only argument and returns true if the string is a match.
|
554 | *
|
555 | * @param pattern Glob pattern
|
556 | * @param options See available options for changing how matches are performed.
|
557 | * @returns Returns a matcher function.
|
558 | *
|
559 | * @example
|
560 | * ```js
|
561 | * var mm = require('micromatch');
|
562 | * mm.matcher(pattern[, options]);
|
563 | *
|
564 | * var isMatch = mm.matcher('*.!(*a)');
|
565 | * console.log(isMatch('a.a'));
|
566 | *
|
567 | * console.log(isMatch('a.b'));
|
568 | *
|
569 | * ```
|
570 | */
|
571 | matcher(pattern: string, options?: micromatch.Options): (str: string) => boolean;
|
572 |
|
573 | /**
|
574 | * Returns an array of matches captured by `pattern` in `string, or`null` if the pattern did not match.
|
575 | *
|
576 | * @param pattern Glob pattern to use for matching.
|
577 | * @param string String to match
|
578 | * @param options See available options for changing how matches are performed
|
579 | * @returns Returns an array of captures if the string matches the glob pattern, otherwise `null`.
|
580 | *
|
581 | * @example
|
582 | * ```js
|
583 | * var mm = require('micromatch');
|
584 | * mm.capture(pattern, string[, options]);
|
585 | *
|
586 | * console.log(mm.capture('test/*.js', 'test/foo.js'));
|
587 | * //=> ['foo']
|
588 | * console.log(mm.capture('test/*.js', 'foo/bar.css'));
|
589 | * //=> null
|
590 | * ```
|
591 | */
|
592 | capture(pattern: string, string: string, options?: micromatch.Options): string[] | null;
|
593 |
|
594 | |
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 | makeRe(pattern: string, options?: micromatch.Options): RegExp;
|
611 |
|
612 | |
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 | braces(pattern: string, options?: braces.Options): string[];
|
629 |
|
630 | |
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 | parse(glob: string, options?: micromatch.Options): object;
|
658 |
|
659 | |
660 |
|
661 |
|
662 | scan(pattern: string, options: { parts: true } & micromatch.ScanOptions): micromatch.ScanInfoWithParts;
|
663 | scan(pattern: string, options: { tokens: true } & micromatch.ScanOptions): micromatch.ScanInfoWithTokens;
|
664 | scan(pattern: string, options?: micromatch.ScanOptions): micromatch.ScanInfo;
|
665 | }
|
666 |
|
667 | export as namespace micromatch;
|
668 |
|
669 | declare const micromatch: Micromatch;
|
670 | export = micromatch;
|