UNPKG

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