You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brace patterns are great for matching ranges. Users (and implementors) shouldn't have to think about whether or not they will break their application (or yours) from accidentally defining an aggressive brace pattern. _Braces is the only library that offers a [solution to this problem](#performance)_.
8
+
Brace patterns make globs more powerful by adding the ability to match specific ranges and sequences of characters.
9
+
10
+
-**Accurate** - complete support for the [Bash 4.3 Brace Expansion][bash] specification (passes all of the Bash braces tests)
11
+
-**[fast and performant](#benchmarks)** - Starts fast, runs fast and [scales well](#performance) as patterns increase in complexity.
12
+
-**Organized code base** - The parser and compiler are easy to maintain and update when edge cases crop up.
13
+
-**Well-tested** - Thousands of test assertions, and passes all of the Bash, minimatch, and [brace-expansion][] unit tests (as of the date this was written).
14
+
-**Safer** - You shouldn't have to worry about users defining aggressive or malicious brace patterns that can break your application. Braces takes measures to prevent malicious regex that can be used for DDoS attacks (see [catastrophic backtracking](https://www.regular-expressions.info/catastrophic.html)).
-[Supports escaping](#escaping) - To prevent evaluation of special characters.
4
19
5
-
-**Safe(r)**: Braces isn't vulnerable to DoS attacks like [brace-expansion][], [minimatch][] and [multimatch][] (a different bug than the [other regex DoS bug][bug]).
6
-
-**Accurate**: complete support for the [Bash 4.3 Brace Expansion][bash] specification (passes all of the Bash braces tests)
7
-
-**[fast and performant](#benchmarks)**: Starts fast, runs fast and [scales well](#performance) as patterns increase in complexity.
8
-
-**Organized code base**: with parser and compiler that are eas(y|ier) to maintain and update when edge cases crop up.
9
-
-**Well-tested**: thousands of test assertions. Passes 100% of the [minimatch][] and [brace-expansion][] unit tests as well (as of the writing of this).
10
20
11
21
## Usage
12
22
13
23
The main export is a function that takes one or more brace `patterns` and `options`.
14
24
15
25
```js
16
-
var braces =require('braces');
17
-
braces(pattern[, options]);
18
-
```
26
+
constbraces=require('braces');
27
+
// braces(patterns[, options]);
19
28
20
-
By default, braces returns an optimized regex-source string. To get an array of brace patterns, use `brace.expand()`.
29
+
console.log(braces(['{01..05}', '{a..e}']));
30
+
//=> ['(0[1-5])', '([a-e])']
21
31
22
-
The following section explains the difference in more detail. _(If you're curious about "why" braces does this by default, see [brace matching pitfalls](#brace-matching-pitfalls)_.
To expand patterns the same way as Bash or [minimatch](https://github.com/isaacs/minimatch), use the [.expand](#expand) method:
51
+
Enable brace expansion by setting the `expand` option to true, or by using [braces.expand()](#expand) (returns an array similar to what you'd expect from Bash, or `echo {1..5}`, or [minimatch](https://github.com/isaacs/minimatch)):
**Description**: Generate an "expanded" brace pattern (this option is unncessary with the `.expand` method, which does the same thing).
184
+
**Description**: Generate an "expanded" brace pattern (alternatively you can use the `braces.expand()` method, which does the same thing).
181
185
182
186
```js
183
-
console.log(braces('a/{b,c}/d', {expand:true}));
187
+
console.log(braces('a/{b,c}/d', {expand:true}));
184
188
//=> [ 'a/b/d', 'a/c/d' ]
185
189
```
186
190
187
-
### options.optimize
188
-
189
-
**Type**: `Boolean`
190
-
191
-
**Default**: `true`
192
-
193
-
**Description**: Enabled by default.
194
-
195
-
```js
196
-
console.log(braces('a/{b,c}/d'));
197
-
//=> [ 'a/(b|c)/d' ]
198
-
```
199
-
200
191
### options.nodupes
201
192
202
193
**Type**: `Boolean`
203
194
204
-
**Default**: `true`
195
+
**Default**: `undefined`
196
+
197
+
**Description**: Remove duplicates from the returned array.
205
198
206
-
**Description**: Duplicates are removed by default. To keep duplicates, pass `{nodupes: false}` on the options
207
199
208
200
### options.rangeLimit
209
201
210
202
**Type**: `Number`
211
203
212
-
**Default**: `250`
204
+
**Default**: `1000`
213
205
214
-
**Description**: When `braces.expand()` is used, or `options.expand` is true, brace patterns will automatically be [optimized](#optionsoptimize) when the difference between the range minimum and range maximum exceeds the `rangeLimit`. This is to prevent huge ranges from freezing your application.
206
+
**Description**: To prevent malicious patterns from being passed by users, an error is thrown when `braces.expand()` is used or `options.expand` is true and the generated range will exceed the `rangeLimit`.
215
207
216
-
You can set this to any number, or change `options.rangeLimit` to `Inifinity` to disable this altogether.
208
+
You can customize `options.rangeLimit` or set it to `Inifinity` to disable this altogether.
@@ -258,10 +266,11 @@ Unfortunately, regex quantifiers happen to share the same syntax as [Bash lists]
258
266
259
267
The `quantifiers` option tells braces to detect when [regex quantifiers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#quantifiers) are defined in the given pattern, and not to try to expand them as lists.
0 commit comments