JSPM

  • Created
  • Published
  • Downloads 85622861
  • Score
    100M100P100Q260420F
  • License

Fastest brace expansion for node.js, with more complete support of Bash 4.3 than minimatch.

Package Exports

  • braces

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (braces) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

braces NPM version

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')
//=> ['a/x/cde', 'a/y/cde']

braces('a/b/c/{x,y}')
//=> ['a/b/c/x', 'a/b/c/y']

braces('a/{x,{1..5},y}/c{d}e')
//=> ['a/x/cde', 'a/1/cde', 'a/y/cde', 'a/2/cde', 'a/3/cde', 'a/4/cde', 'a/5/cde']

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')
//=> ['a1b', 'a2b', 'a3b']

braces('a{5..8}b')
//=> ['a5b', 'a6b', 'a7b', 'a8b']

braces('a{00..05}b')
//=> ['a00b', 'a01b', 'a02b', 'a03b', 'a04b', 'a05b']

braces('a{01..03}b')
//=> ['a01b', 'a02b', 'a03b']

braces('a{000..005}b')
//=> ['a000b', 'a001b', 'a002b', 'a003b', 'a004b', 'a005b']

braces('a{a..e}b')
//=> ['aab', 'abb', 'acb', 'adb', 'aeb']

braces('a{A..E}b')
//=> ['aAb', 'aBb', 'aCb', 'aDb', 'aEb']

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);
//=> ['xa0y', 'xb1y', 'xc2y', 'xd3y', 'xe4y']

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

node benchmark

Run tests

npm test

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) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb on January 11, 2015.