
Security News
Software Engineering Daily Podcast: Feross on AI, Open Source, and Supply Chain Risk
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.
brace-expansion-parser
Advanced tools
Parses strings with brace expansions, like this: foo.{bar,baz}.
$ npm install [--save] brace-expansion-parser
expandIf all you want is the set of expanded strings, use this.
import { expand } from 'brace-expansion-parser';
expand('foo.bar'); // [ 'foo.bar' ]
expand('foo.{bar,baz}'); // [ 'foo.bar', 'foo.baz' ]
expand('{a,b}.{c,d}'); // [ 'a.c', 'a.d', 'b.c', 'b.d' ]
parseProvides detailed information about the brace expansion expression.
import { parse } from 'brace-expansion-parser';
parse('foo.{bar,baz}');
/*
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:
import { parse } from 'brace-expansion-parser';
parse('foo.{bar,baz}').serialize(); // 'foo.{bar,baz}'
You can modify an expression object and use it to generate a modified expression string:
import { parse, StringExpression } from 'brace-expansion-parser';
const ast = parse('foo.{bar,baz}');
ast.elements[0].content = 'FOO.';
ast.elements[1].elements.push(new StringExpression('moo'));
ast.serialize(); // 'FOO.{bar,baz,moo}'
lexBreaks the brace expresion string into a stream of tokens.
import { lex, TokenType } from 'brace-expansion-parser';
lex('foo.{bar,baz}');
/*
[ 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 }
*/
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.
FAQs
Parses strings with brace expansions
We found that brace-expansion-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.

Security News
Rust’s crates.io team is advancing an RFC to add a Security tab that surfaces RustSec vulnerability and unsoundness advisories directly on crate pages.