1 | // Type definitions for braces 3.0
|
2 | // Project: https://github.com/micromatch/braces
|
3 | // Definitions by: vemoo <https://github.com/vemoo>
|
4 | // mrmlnc <https://github.com/mrmlnc>
|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 |
|
7 | declare namespace braces {
|
8 | type Transform = (str: string) => string;
|
9 |
|
10 | interface Options {
|
11 | /**
|
12 | * Limit the length of the input string. Useful when the input string is generated or your application allows
|
13 | * users to pass a string, et cetera.
|
14 | *
|
15 | * @default 65536
|
16 | * @example
|
17 | * console.log(braces('a/{b,c}/d', { maxLength: 3 }));
|
18 | * //=> throws an error
|
19 | */
|
20 | maxLength?: number;
|
21 | /**
|
22 | * Generate an "expanded" brace pattern (alternatively you can use the `braces.expand()` method).
|
23 | *
|
24 | * @default undefined
|
25 | * @example
|
26 | * console.log(braces('a/{b,c}/d', { expand: true }));
|
27 | * //=> [ 'a/b/d', 'a/c/d' ]
|
28 | */
|
29 | expand?: boolean;
|
30 | /**
|
31 | * Remove duplicates from the returned array.
|
32 | *
|
33 | * @default undefined
|
34 | */
|
35 | nodupes?: boolean;
|
36 | /**
|
37 | * To prevent malicious patterns from being passed by users, an error is thrown when `braces.expand()`
|
38 | * is used or `options.expand` is true and the generated range will exceed the `rangeLimit`.
|
39 | *
|
40 | * You can customize `options.rangeLimit` or set it to `Infinity` to disable this altogether.
|
41 | *
|
42 | * @default 1000
|
43 | * @example
|
44 | * // pattern exceeds the "rangeLimit", so it's optimized automatically
|
45 | * console.log(braces.expand('{1..1000}'));
|
46 | * //=> ['([1-9]|[1-9][0-9]{1,2}|1000)']
|
47 | *
|
48 | * // pattern does not exceed "rangeLimit", so it's NOT optimized
|
49 | * console.log(braces.expand('{1..100}'));
|
50 | * //=> ['1', '2', '3', '4', '5', …, '100']
|
51 | */
|
52 | rangeLimit?: number;
|
53 | /**
|
54 | * Customize range expansion.
|
55 | *
|
56 | * @default undefined
|
57 | * @example
|
58 | * const range = braces.expand('x{a..e}y', {
|
59 | * transform: (str) => `foo/${str}`
|
60 | * });
|
61 | *
|
62 | * console.log(range);
|
63 | * //=> [ 'xfooay', 'xfooby', 'xfoocy', 'xfoody', 'xfooey' ]
|
64 | */
|
65 | transform?: Transform;
|
66 | /**
|
67 | * In regular expressions, quanitifiers can be used to specify how many times a token can be repeated.
|
68 | * For example, `a{1,3}` will match the letter `a` one to three times.
|
69 | *
|
70 | * Unfortunately, regex quantifiers happen to share the same syntax as [Bash lists](#lists)
|
71 | *
|
72 | * The `quantifiers` option tells braces to detect when [regex quantifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#quantifiers)
|
73 | * are defined in the given pattern, and not to try to expand them as lists.
|
74 | *
|
75 | * @default undefined
|
76 | * @example
|
77 | * const braces = require('braces');
|
78 | * console.log(braces('a/b{1,3}/{x,y,z}'));
|
79 | * //=> [ 'a/b(1|3)/(x|y|z)' ]
|
80 | * console.log(braces('a/b{1,3}/{x,y,z}', {quantifiers: true}));
|
81 | * //=> [ 'a/b{1,3}/(x|y|z)' ]
|
82 | * console.log(braces('a/b{1,3}/{x,y,z}', {quantifiers: true, expand: true}));
|
83 | * //=> [ 'a/b{1,3}/x', 'a/b{1,3}/y', 'a/b{1,3}/z' ]
|
84 | */
|
85 | quantifiers?: boolean;
|
86 | /**
|
87 | * Strip backslashes that were used for escaping from the result.
|
88 | *
|
89 | * @default undefined
|
90 | */
|
91 | unescape?: boolean;
|
92 | }
|
93 | }
|
94 | interface Braces {
|
95 | (pattern: string, options?: braces.Options): string[];
|
96 | expand(pattern: string): string[];
|
97 | }
|
98 | declare const braces: Braces;
|
99 | export as namespace braces;
|
100 | export = braces;
|