Skip to content

Commit 9fd8baf

Browse files
Merge pull request DmitrySoshnikov#202 from brettz9/patch-1
Update per latest API and document `blacklist`
2 parents 091d4e9 + 7ef5844 commit 9fd8baf

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

src/optimizer/README.md

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ becomes:
2323

2424
## API
2525

26-
`optimize(regexp, [transformsWhitelist])`: Optimize the regexp. Optionally request specific transforms.
26+
`optimize(regexp, {whitelist: [transformsWhitelist], blacklist: [transformsWhitelist]})`: Optimize the regexp. Optionally request specific transforms.
2727

2828
Transforms will be applied until no further optimization progress is made.
2929

@@ -34,14 +34,33 @@ const optimizer = require('./index.js');
3434
const inefficient = /[0-9]/;
3535

3636
const optimized1 = optimizer.optimize(inefficient);
37-
const optimized2 = optimizer.optimize(inefficient, [
38-
'charClassToMeta', // [0-9] -> [\d]
39-
'charClassToSingleChar', // [\d] -> \d
40-
]);
37+
const optimized2 = optimizer.optimize(inefficient, {
38+
whitelist: [
39+
'charClassToMeta', // [0-9] -> [\d]
40+
'charClassToSingleChar', // [\d] -> \d
41+
]
42+
});
4143

4244
console.log(`${inefficient} -> ${optimized1} === ${optimized2}`);
4345
```
4446

47+
You can also add a `blacklist`, e.g., to disable the defaults (which are all enabled if no whitelist is provided):
48+
49+
```js
50+
const optimizer = require('./index.js');
51+
52+
const original = /[åä]/;
53+
const optimized = /[åä]/;
54+
55+
56+
const optimized1 = optimizer.optimize(original); // [åä] -> [äå]
57+
const optimized2 = optimizer.optimize(original, { // [åä] (does not change)
58+
blacklist: [
59+
'charClassClassrangesMerge'
60+
]
61+
});
62+
```
63+
4564
### Transforms
4665

4766
Here is the list of transforms supported by the Optimizer module.

0 commit comments

Comments
 (0)