brace-expansion-parser
Parses strings with brace expansions, like this: foo.{bar,baz}
.
Install
$ npm install [--save] brace-expansion-parser
Use
expand
If all you want is the set of expanded strings, use this.
; ; // [ 'foo.bar' ]; // [ 'foo.bar', 'foo.baz' ]; // [ 'a.c', 'a.d', 'b.c', 'b.d' ]
parse
Provides detailed information about the brace expansion expression.
; ;/*BraceExpression { start: 0, end: 13, elements: [ StringExpression { start: 0, end: 4, content: 'foo.' }, ExpansionExpression { start: 4, end: 13, elements: [Object] } ] }*/
If you want to get the string version of the expression, call serialize
:
; ; // 'foo.{bar,baz}'
You can modify an expression object and use it to generate a modified expression string:
; const ast = ; astelements0content = 'FOO.';astelements1elements; ast; // 'FOO.{bar,baz,moo}'
lex
Breaks the brace expresion string into a stream of tokens.
; ;/*[ Token { type: 3, start: 0, end: 4 }, Token { type: 0, start: 4, end: 5 }, Token { type: 3, start: 5, end: 8 }, Token { type: 2, start: 8, end: 9 }, Token { type: 3, start: 9, end: 12 }, Token { type: 1, start: 12, end: 13 } ]*/TokenType;/*{ '0': 'LBRACE', '1': 'RBRACE', '2': 'COMMA', '3': 'STRING', LBRACE: 0, RBRACE: 1, COMMA: 2, STRING: 3 }*/
Development
Clone this repo, then run npm install
and npm test
to make sure everything
works. Add features or fix bugs on a new branch and create a pull request.