braces
Fastest brace expansion for node.js, with more complete support of Bash 4.3 than minimatch.
Install with npm
npm i braces --save
Example usage
var braces = require('braces');
braces('a/{x,y}/c{d}e')
braces('a/b/c/{x,y}')
braces('a/{x,{1..5},y}/c{d}e')
Pro tip!
Use braces to generate test fixtures!
Example
var braces = require('./');
var path = require('path');
var fs = require('fs');
braces('blah/{a..z}.js').forEach(function(fp) {
if (!fs.existsSync(path.dirname(fp))) {
fs.mkdirSync(path.dirname(fp));
}
fs.writeFileSync(fp, '');
});
See the tests for more examples and use cases (also see the bash spec tests);
Range expansion
Uses expand-range for range expansion.
braces('a{1..3}b')
braces('a{5..8}b')
braces('a{00..05}b')
braces('a{01..03}b')
braces('a{000..005}b')
braces('a{a..e}b')
braces('a{A..E}b')
Pass a function as the last argument to customize range expansions:
var range = braces('x{a..e}y', function (str, i) {
return String.fromCharCode(str) + i;
});
console.log(range);
See expand-range for benchmarks, tests and the full list of range expansion features.
Bash 4.3
Better support for Bash 4.3 than minimatch
This project has comprehensive unit tests, including tests coverted from Bash 4.3. Currently only 8 of 102 unit tests fail, and
Differences
Main differences from Bash:
- In bash (and minimatch) the braces are retained when only one set exists. ex:
a{b}c
=> ['a{b}c']
. Since this can cause problems with routes and config templates etc., single-set valid braces are removed. e.g a{b}c
=> ['abc']
- duplicates are removed by default. To keep dupes, pass
nodupes: false
on the options
New features:
- Support for (ignoring) es6 delimiters. ex:
a/${b}/{c,d}
=> ['a/${b}/c', 'a/${b}/d']
Benchmarks
brace-expansion.js x 114,934 ops/sec ±1.24% (93 runs sampled)
braces.js x 342,254 ops/sec ±0.84% (90 runs sampled)
brace-expansion.js x 12,359 ops/sec ±0.86% (96 runs sampled)
braces.js x 20,389 ops/sec ±0.71% (97 runs sampled)
brace-expansion.js x 114,469 ops/sec ±1.44% (94 runs sampled)
braces.js x 401,621 ops/sec ±0.87% (91 runs sampled)
brace-expansion.js x 102,769 ops/sec ±1.55% (92 runs sampled)
braces.js x 314,088 ops/sec ±0.71% (98 runs sampled)
brace-expansion.js x 157,577 ops/sec ±1.65% (91 runs sampled)
braces.js x 1,115,950 ops/sec ±0.74% (94 runs sampled)
brace-expansion.js x 138,822 ops/sec ±1.71% (91 runs sampled)
braces.js x 1,108,353 ops/sec ±0.85% (94 runs sampled)
Run the benchmarks:
node benchmark
Run tests
Install dev dependencies:
npm i -d && npm test
Related
- micromatch: wildcard/glob matcher for javascript. a faster alternative to minimatch.
- fill-range: Fill in a range of numbers or letters, optionally passing an increment or multiplier to use
- [expand-range]: Wraps fill-range for fast, bash-like range expansion in strings. Expand a range of numbers or letters, uppercase or lowercase
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please run benchmarks before and after any code changes to what the impact of the code changes are before submitting a PR.
Author
Jon Schlinkert
License
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on January 28, 2015.