{\bfseries{More about brace expansion}} (click to expand)

\begin{quote}
Bash-\/like brace expansion, implemented in Java\+Script. Safer than other brace expansion libs, with complete support for the Bash 4.\+3 braces specification, without sacrificing speed. \end{quote}
Please consider following this project\textquotesingle{}s author, \href{https://github.com/jonschlinkert}{\texttt{ Jon Schlinkert}}, and consider starring the project to show your \+:heart\+: and support.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4320}{}\doxysection{Install}\label{md_sfcode_node_modules_braces_README_autotoc_md4320}
Install with \href{https://www.npmjs.com/}{\texttt{ npm}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/-\/save braces }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4321}{}\doxysection{v3.\+0.\+0 Released!!}\label{md_sfcode_node_modules_braces_README_autotoc_md4321}
See the \mbox{\hyperlink{md_sfcode_node_modules_braces_CHANGELOG}{changelog}} for details.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4322}{}\doxysection{Why use braces?}\label{md_sfcode_node_modules_braces_README_autotoc_md4322}
Brace patterns make globs more powerful by adding the ability to match specific ranges and sequences of characters.


\begin{DoxyItemize}
\item {\bfseries{Accurate}} -\/ complete support for the \href{www.gnu.org/software/bash/}{\texttt{ Bash 4.\+3 Brace Expansion}} specification (passes all of the Bash braces tests)
\item {\bfseries{\href{\#benchmarks}{\texttt{ fast and performant}}}} -\/ Starts fast, runs fast and \href{\#performance}{\texttt{ scales well}} as patterns increase in complexity.
\item {\bfseries{Organized code base}} -\/ The parser and compiler are easy to maintain and update when edge cases crop up.
\item {\bfseries{Well-\/tested}} -\/ Thousands of test assertions, and passes all of the Bash, minimatch, and \href{https://github.com/juliangruber/brace-expansion}{\texttt{ brace-\/expansion}} unit tests (as of the date this was written).
\item {\bfseries{Safer}} -\/ You shouldn\textquotesingle{}t have to worry about users defining aggressive or malicious brace patterns that can break your application. Braces takes measures to prevent malicious regex that can be used for DDoS attacks (see \href{https://www.regular-expressions.info/catastrophic.html}{\texttt{ catastrophic backtracking}}).
\item \href{\#lists}{\texttt{ Supports lists}} -\/ (aka \char`\"{}sets\char`\"{}) {\ttfamily a/\{b,c\}/d} =$>$ `\mbox{[}\textquotesingle{}a/b/d', \textquotesingle{}a/c/d\textquotesingle{}\mbox{]}{\ttfamily }
\item {\ttfamily \mbox{[}Supports sequences\mbox{]}(\#sequences) -\/ (aka \char`\"{}ranges\char`\"{})}\{01..03\}{\ttfamily =$>$}\mbox{[}\textquotesingle{}01\textquotesingle{}, \textquotesingle{}02\textquotesingle{}, \textquotesingle{}03\textquotesingle{}\mbox{]}{\ttfamily }
\item {\ttfamily \mbox{[}Supports steps\mbox{]}(\#steps) -\/ (aka \char`\"{}increments\char`\"{})}\{2..10..2\}{\ttfamily =$>$}\mbox{[}\textquotesingle{}2\textquotesingle{}, \textquotesingle{}4\textquotesingle{}, \textquotesingle{}6\textquotesingle{}, \textquotesingle{}8\textquotesingle{}, \textquotesingle{}10\textquotesingle{}\mbox{]}\`{}
\item \href{\#escaping}{\texttt{ Supports escaping}} -\/ To prevent evaluation of special characters.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4323}{}\doxysection{Usage}\label{md_sfcode_node_modules_braces_README_autotoc_md4323}
The main export is a function that takes one or more brace {\ttfamily patterns} and {\ttfamily options}.


\begin{DoxyCode}{0}
\DoxyCodeLine{const braces = require('braces');}
\DoxyCodeLine{// braces(patterns[, options]);}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces(['\{01..05\}', '\{a..e\}']));}
\DoxyCodeLine{//=> ['(0[1-\/5])', '([a-\/e])']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces(['\{01..05\}', '\{a..e\}'], \{ expand: true \}));}
\DoxyCodeLine{//=> ['01', '02', '03', '04', '05', 'a', 'b', 'c', 'd', 'e'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4324}{}\doxysubsection{Brace Expansion vs. Compilation}\label{md_sfcode_node_modules_braces_README_autotoc_md4324}
By default, brace patterns are compiled into strings that are optimized for creating regular expressions and matching.

{\bfseries{Compiled}}


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces('a/\{x,y,z\}/b')); }
\DoxyCodeLine{//=> ['a/(x|y|z)/b']}
\DoxyCodeLine{console.log(braces(['a/\{01..20\}/b', 'a/\{1..5\}/b'])); }
\DoxyCodeLine{//=> [ 'a/(0[1-\/9]|1[0-\/9]|20)/b', 'a/([1-\/5])/b' ] }

\end{DoxyCode}


{\bfseries{Expanded}}

Enable brace expansion by setting the {\ttfamily expand} option to true, or by using \href{\#expand}{\texttt{ braces.\+expand()}} (returns an array similar to what you\textquotesingle{}d expect from Bash, or {\ttfamily echo \{1..5\}}, or \href{https://github.com/isaacs/minimatch}{\texttt{ minimatch}})\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces('a/\{x,y,z\}/b', \{ expand: true \}));}
\DoxyCodeLine{//=> ['a/x/b', 'a/y/b', 'a/z/b']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces.expand('\{01..10\}'));}
\DoxyCodeLine{//=> ['01','02','03','04','05','06','07','08','09','10'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4325}{}\doxysubsection{Lists}\label{md_sfcode_node_modules_braces_README_autotoc_md4325}
Expand lists (like Bash \char`\"{}sets\char`\"{})\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces('a/\{foo,bar,baz\}/*.js'));}
\DoxyCodeLine{//=> ['a/(foo|bar|baz)/*.js']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces.expand('a/\{foo,bar,baz\}/*.js'));}
\DoxyCodeLine{//=> ['a/foo/*.js', 'a/bar/*.js', 'a/baz/*.js'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4326}{}\doxysubsection{Sequences}\label{md_sfcode_node_modules_braces_README_autotoc_md4326}
Expand ranges of characters (like Bash \char`\"{}sequences\char`\"{})\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces.expand('\{1..3\}'));                // ['1', '2', '3']}
\DoxyCodeLine{console.log(braces.expand('a/\{1..3\}/b'));            // ['a/1/b', 'a/2/b', 'a/3/b']}
\DoxyCodeLine{console.log(braces('\{a..c\}', \{ expand: true \}));     // ['a', 'b', 'c']}
\DoxyCodeLine{console.log(braces('foo/\{a..c\}', \{ expand: true \})); // ['foo/a', 'foo/b', 'foo/c']}
\DoxyCodeLine{}
\DoxyCodeLine{// supports zero-\/padded ranges}
\DoxyCodeLine{console.log(braces('a/\{01..03\}/b'));   //=> ['a/(0[1-\/3])/b']}
\DoxyCodeLine{console.log(braces('a/\{001..300\}/b')); //=> ['a/(0\{2\}[1-\/9]|0[1-\/9][0-\/9]|[12][0-\/9]\{2\}|300)/b'] }

\end{DoxyCode}


See \href{https://github.com/jonschlinkert/fill-range}{\texttt{ fill-\/range}} for all available range-\/expansion options.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4327}{}\doxysubsection{Steppped ranges}\label{md_sfcode_node_modules_braces_README_autotoc_md4327}
Steps, or increments, may be used with ranges\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces.expand('\{2..10..2\}'));}
\DoxyCodeLine{//=> ['2', '4', '6', '8', '10']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces('\{2..10..2\}'));}
\DoxyCodeLine{//=> ['(2|4|6|8|10)'] }

\end{DoxyCode}


When the \href{\#optimize}{\texttt{ .optimize}} method is used, or \href{\#optionsoptimize}{\texttt{ options.\+optimize}} is set to true, sequences are passed to \href{https://github.com/jonschlinkert/to-regex-range}{\texttt{ to-\/regex-\/range}} for expansion.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4328}{}\doxysubsection{Nesting}\label{md_sfcode_node_modules_braces_README_autotoc_md4328}
Brace patterns may be nested. The results of each expanded string are not sorted, and left to right order is preserved.

$\ast$$\ast$\char`\"{}\+Expanded\char`\"{} braces$\ast$$\ast$


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces.expand('a\{b,c,/\{x,y\}\}/e'));}
\DoxyCodeLine{//=> ['ab/e', 'ac/e', 'a/x/e', 'a/y/e']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces.expand('a/\{x,\{1..5\},y\}/c'));}
\DoxyCodeLine{//=> ['a/x/c', 'a/1/c', 'a/2/c', 'a/3/c', 'a/4/c', 'a/5/c', 'a/y/c'] }

\end{DoxyCode}


$\ast$$\ast$\char`\"{}\+Optimized\char`\"{} braces$\ast$$\ast$


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces('a\{b,c,/\{x,y\}\}/e'));}
\DoxyCodeLine{//=> ['a(b|c|/(x|y))/e']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces('a/\{x,\{1..5\},y\}/c'));}
\DoxyCodeLine{//=> ['a/(x|([1-\/5])|y)/c'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4329}{}\doxysubsection{Escaping}\label{md_sfcode_node_modules_braces_README_autotoc_md4329}
{\bfseries{Escaping braces}}

A brace pattern will not be expanded or evaluted if {\itshape either the opening or closing brace is escaped}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces.expand('a\(\backslash\)\(\backslash\)\{d,c,b\}e'));}
\DoxyCodeLine{//=> ['a\{d,c,b\}e']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces.expand('a\{d,c,b\(\backslash\)\(\backslash\)\}e'));}
\DoxyCodeLine{//=> ['a\{d,c,b\}e'] }

\end{DoxyCode}


{\bfseries{Escaping commas}}

Commas inside braces may also be escaped\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces.expand('a\{b\(\backslash\)\(\backslash\),c\}d'));}
\DoxyCodeLine{//=> ['a\{b,c\}d']}
\DoxyCodeLine{}
\DoxyCodeLine{console.log(braces.expand('a\{d\(\backslash\)\(\backslash\),c,b\}e'));}
\DoxyCodeLine{//=> ['ad,ce', 'abe'] }

\end{DoxyCode}


{\bfseries{Single items}}

Following bash conventions, a brace pattern is also not expanded when it contains a single character\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces.expand('a\{b\}c'));}
\DoxyCodeLine{//=> ['a\{b\}c'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4330}{}\doxysection{Options}\label{md_sfcode_node_modules_braces_README_autotoc_md4330}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4331}{}\doxysubsection{options.\+max\+Length}\label{md_sfcode_node_modules_braces_README_autotoc_md4331}
{\bfseries{Type}}\+: {\ttfamily Number}

{\bfseries{Default}}\+: {\ttfamily 65,536}

{\bfseries{Description}}\+: Limit the length of the input string. Useful when the input string is generated or your application allows users to pass a string, et cetera.


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces('a/\{b,c\}/d', \{ maxLength: 3 \}));  //=> throws an error }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4332}{}\doxysubsection{options.\+expand}\label{md_sfcode_node_modules_braces_README_autotoc_md4332}
{\bfseries{Type}}\+: {\ttfamily Boolean}

{\bfseries{Default}}\+: {\ttfamily undefined}

{\bfseries{Description}}\+: Generate an \char`\"{}expanded\char`\"{} brace pattern (alternatively you can use the {\ttfamily braces.\+expand()} method, which does the same thing).


\begin{DoxyCode}{0}
\DoxyCodeLine{console.log(braces('a/\{b,c\}/d', \{ expand: true \}));}
\DoxyCodeLine{//=> [ 'a/b/d', 'a/c/d' ] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4333}{}\doxysubsection{options.\+nodupes}\label{md_sfcode_node_modules_braces_README_autotoc_md4333}
{\bfseries{Type}}\+: {\ttfamily Boolean}

{\bfseries{Default}}\+: {\ttfamily undefined}

{\bfseries{Description}}\+: Remove duplicates from the returned array.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4334}{}\doxysubsection{options.\+range\+Limit}\label{md_sfcode_node_modules_braces_README_autotoc_md4334}
{\bfseries{Type}}\+: {\ttfamily Number}

{\bfseries{Default}}\+: {\ttfamily 1000}

{\bfseries{Description}}\+: To prevent malicious patterns from being passed by users, an error is thrown when {\ttfamily braces.\+expand()} is used or {\ttfamily options.\+expand} is true and the generated range will exceed the {\ttfamily range\+Limit}.

You can customize {\ttfamily options.\+range\+Limit} or set it to {\ttfamily Inifinity} to disable this altogether.

{\bfseries{Examples}}


\begin{DoxyCode}{0}
\DoxyCodeLine{// pattern exceeds the "{}rangeLimit"{}, so it's optimized automatically}
\DoxyCodeLine{console.log(braces.expand('\{1..1000\}'));}
\DoxyCodeLine{//=> ['([1-\/9]|[1-\/9][0-\/9]\{1,2\}|1000)']}
\DoxyCodeLine{}
\DoxyCodeLine{// pattern does not exceed "{}rangeLimit"{}, so it's NOT optimized}
\DoxyCodeLine{console.log(braces.expand('\{1..100\}'));}
\DoxyCodeLine{//=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '100'] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4335}{}\doxysubsection{options.\+transform}\label{md_sfcode_node_modules_braces_README_autotoc_md4335}
{\bfseries{Type}}\+: {\ttfamily Function}

{\bfseries{Default}}\+: {\ttfamily undefined}

{\bfseries{Description}}\+: Customize range expansion.

{\bfseries{Example\+: Transforming non-\/numeric values}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const alpha = braces.expand('x/\{a..e\}/y', \{}
\DoxyCodeLine{  transform(value, index) \{}
\DoxyCodeLine{    // When non-\/numeric values are passed, "{}value"{} is a character code.}
\DoxyCodeLine{    return 'foo/' + String.fromCharCode(value) + '-\/' + index;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\});}
\DoxyCodeLine{console.log(alpha);}
\DoxyCodeLine{//=> [ 'x/foo/a-\/0/y', 'x/foo/b-\/1/y', 'x/foo/c-\/2/y', 'x/foo/d-\/3/y', 'x/foo/e-\/4/y' ] }

\end{DoxyCode}


{\bfseries{Example\+: Transforming numeric values}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const numeric = braces.expand('\{1..5\}', \{}
\DoxyCodeLine{  transform(value) \{}
\DoxyCodeLine{    // when numeric values are passed, "{}value"{} is a number}
\DoxyCodeLine{    return 'foo/' + value * 2;}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\});}
\DoxyCodeLine{console.log(numeric); }
\DoxyCodeLine{//=> [ 'foo/2', 'foo/4', 'foo/6', 'foo/8', 'foo/10' ] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4336}{}\doxysubsection{options.\+quantifiers}\label{md_sfcode_node_modules_braces_README_autotoc_md4336}
{\bfseries{Type}}\+: {\ttfamily Boolean}

{\bfseries{Default}}\+: {\ttfamily undefined}

{\bfseries{Description}}\+: In regular expressions, quanitifiers can be used to specify how many times a token can be repeated. For example, {\ttfamily a\{1,3\}} will match the letter {\ttfamily a} one to three times.

Unfortunately, regex quantifiers happen to share the same syntax as \href{\#lists}{\texttt{ Bash lists}}

The {\ttfamily quantifiers} option tells braces to detect when \href{https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp\#quantifiers}{\texttt{ regex quantifiers}} are defined in the given pattern, and not to try to expand them as lists.

{\bfseries{Examples}}


\begin{DoxyCode}{0}
\DoxyCodeLine{const braces = require('braces');}
\DoxyCodeLine{console.log(braces('a/b\{1,3\}/\{x,y,z\}'));}
\DoxyCodeLine{//=> [ 'a/b(1|3)/(x|y|z)' ]}
\DoxyCodeLine{console.log(braces('a/b\{1,3\}/\{x,y,z\}', \{quantifiers: true\}));}
\DoxyCodeLine{//=> [ 'a/b\{1,3\}/(x|y|z)' ]}
\DoxyCodeLine{console.log(braces('a/b\{1,3\}/\{x,y,z\}', \{quantifiers: true, expand: true\}));}
\DoxyCodeLine{//=> [ 'a/b\{1,3\}/x', 'a/b\{1,3\}/y', 'a/b\{1,3\}/z' ] }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4337}{}\doxysubsection{options.\+unescape}\label{md_sfcode_node_modules_braces_README_autotoc_md4337}
{\bfseries{Type}}\+: {\ttfamily Boolean}

{\bfseries{Default}}\+: {\ttfamily undefined}

{\bfseries{Description}}\+: Strip backslashes that were used for escaping from the result.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4338}{}\doxysection{What is \char`\"{}brace expansion\char`\"{}?}\label{md_sfcode_node_modules_braces_README_autotoc_md4338}
Brace expansion is a type of parameter expansion that was made popular by unix shells for generating lists of strings, as well as regex-\/like matching when used alongside wildcards (globs).

In addition to \char`\"{}expansion\char`\"{}, braces are also used for matching. In other words\+:


\begin{DoxyItemize}
\item \href{\#brace-expansion}{\texttt{ brace expansion}} is for generating new lists
\item \href{\#brace-matching}{\texttt{ brace matching}} is for filtering existing lists
\end{DoxyItemize}

$<$details$>$

There are two main types of brace expansion\+:


\begin{DoxyEnumerate}
\item {\bfseries{lists}}\+: which are defined using comma-\/separated values inside curly braces\+: {\ttfamily \{a,b,c\}}
\item {\bfseries{sequences}}\+: which are defined using a starting value and an ending value, separated by two dots\+: {\ttfamily a\{1..3\}b}. Optionally, a third argument may be passed to define a \char`\"{}step\char`\"{} or increment to use\+: {\ttfamily a\{1..100..10\}b}. These are also sometimes referred to as \char`\"{}ranges\char`\"{}.
\end{DoxyEnumerate}

Here are some example brace patterns to illustrate how they work\+:

{\bfseries{Sets}}


\begin{DoxyCode}{0}
\DoxyCodeLine{\{a,b,c\}       => a b c}
\DoxyCodeLine{\{a,b,c\}\{1,2\}  => a1 a2 b1 b2 c1 c2 }

\end{DoxyCode}


{\bfseries{Sequences}}


\begin{DoxyCode}{0}
\DoxyCodeLine{\{1..9\}        => 1 2 3 4 5 6 7 8 9}
\DoxyCodeLine{\{4..-\/4\}       => 4 3 2 1 0 -\/1 -\/2 -\/3 -\/4}
\DoxyCodeLine{\{1..20..3\}    => 1 4 7 10 13 16 19}
\DoxyCodeLine{\{a..j\}        => a b c d e f g h i j}
\DoxyCodeLine{\{j..a\}        => j i h g f e d c b a}
\DoxyCodeLine{\{a..z..3\}     => a d g j m p s v y }

\end{DoxyCode}


{\bfseries{Combination}}

Sets and sequences can be mixed together or used along with any other strings.


\begin{DoxyCode}{0}
\DoxyCodeLine{\{a,b,c\}\{1..3\}   => a1 a2 a3 b1 b2 b3 c1 c2 c3}
\DoxyCodeLine{foo/\{a,b,c\}/bar => foo/a/bar foo/b/bar foo/c/bar }

\end{DoxyCode}


The fact that braces can be \char`\"{}expanded\char`\"{} from relatively simple patterns makes them ideal for quickly generating test fixtures, file paths, and similar use cases.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4339}{}\doxysection{Brace matching}\label{md_sfcode_node_modules_braces_README_autotoc_md4339}
In addition to {\itshape expansion}, brace patterns are also useful for performing regular-\/expression-\/like matching.

For example, the pattern {\ttfamily foo/\{1..3\}/bar} would match any of following strings\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{foo/1/bar}
\DoxyCodeLine{foo/2/bar}
\DoxyCodeLine{foo/3/bar }

\end{DoxyCode}


But not\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{baz/1/qux}
\DoxyCodeLine{baz/2/qux}
\DoxyCodeLine{baz/3/qux }

\end{DoxyCode}


Braces can also be combined with \href{https://github.com/jonschlinkert/micromatch}{\texttt{ glob patterns}} to perform more advanced wildcard matching. For example, the pattern {\ttfamily $\ast$/\{1..3\}/$\ast$} would match any of following strings\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{foo/1/bar}
\DoxyCodeLine{foo/2/bar}
\DoxyCodeLine{foo/3/bar}
\DoxyCodeLine{baz/1/qux}
\DoxyCodeLine{baz/2/qux}
\DoxyCodeLine{baz/3/qux }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4340}{}\doxysection{Brace matching pitfalls}\label{md_sfcode_node_modules_braces_README_autotoc_md4340}
Although brace patterns offer a user-\/friendly way of matching ranges or sets of strings, there are also some major disadvantages and potential risks you should be aware of.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4341}{}\doxysubsection{tldr}\label{md_sfcode_node_modules_braces_README_autotoc_md4341}
$\ast$$\ast$\char`\"{}brace bombs\char`\"{}$\ast$$\ast$


\begin{DoxyItemize}
\item brace expansion can eat up a huge amount of processing resources
\item as brace patterns increase {\itshape linearly in size}, the system resources required to expand the pattern increase exponentially
\item users can accidentally (or intentially) exhaust your system\textquotesingle{}s resources resulting in the equivalent of a DoS attack (bonus\+: no programming knowledge is required!)
\end{DoxyItemize}

For a more detailed explanation with examples, see the \href{\#geometric-complexity}{\texttt{ geometric complexity}} section.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4342}{}\doxysubsection{The solution}\label{md_sfcode_node_modules_braces_README_autotoc_md4342}
Jump to the \href{\#performance}{\texttt{ performance section}} to see how Braces solves this problem in comparison to other libraries.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4343}{}\doxysubsection{Geometric complexity}\label{md_sfcode_node_modules_braces_README_autotoc_md4343}
At minimum, brace patterns with sets limited to two elements have quadradic or {\ttfamily O(n$^\wedge$2)} complexity. But the complexity of the algorithm increases exponentially as the number of sets, {\itshape and elements per set}, increases, which is {\ttfamily O(n$^\wedge$c)}.

For example, the following sets demonstrate quadratic ({\ttfamily O(n$^\wedge$2)}) complexity\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{1,2\}\{3,4\}      => (2X2)    => 13 14 23 24}
\DoxyCodeLine{\{1,2\}\{3,4\}\{5,6\} => (2X2X2)  => 135 136 145 146 235 236 245 246 }

\end{DoxyCode}


But add an element to a set, and we get a n-\/fold Cartesian product with {\ttfamily O(n$^\wedge$c)} complexity\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{1,2,3\}\{4,5,6\}\{7,8,9\} => (3X3X3) => 147 148 149 157 158 159 167 168 169 247 248 }
\DoxyCodeLine{                                    249 257 258 259 267 268 269 347 348 349 357 }
\DoxyCodeLine{                                    358 359 367 368 369 }

\end{DoxyCode}


Now, imagine how this complexity grows given that each element is a n-\/tuple\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{1..100\}\{1..100\}         => (100X100)     => 10,000 elements (38.4 kB)}
\DoxyCodeLine{\{1..100\}\{1..100\}\{1..100\} => (100X100X100) => 1,000,000 elements (5.76 MB) }

\end{DoxyCode}


Although these examples are clearly contrived, they demonstrate how brace patterns can quickly grow out of control.

{\bfseries{More information}}

Interested in learning more about brace expansion?


\begin{DoxyItemize}
\item \href{http://www.linuxjournal.com/content/bash-brace-expansion}{\texttt{ linuxjournal/bash-\/brace-\/expansion}}
\item \href{https://rosettacode.org/wiki/Brace_expansion}{\texttt{ rosettacode/\+Brace\+\_\+expansion}}
\item \href{https://en.wikipedia.org/wiki/Cartesian_product}{\texttt{ cartesian product}}
\end{DoxyItemize}

$<$/details$>$\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4344}{}\doxysection{Performance}\label{md_sfcode_node_modules_braces_README_autotoc_md4344}
Braces is not only screaming fast, it\textquotesingle{}s also more accurate the other brace expansion libraries.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4345}{}\doxysubsection{Better algorithms}\label{md_sfcode_node_modules_braces_README_autotoc_md4345}
Fortunately there is a solution to the \href{\#brace-matching-pitfalls}{\texttt{ \char`\"{}brace bomb\char`\"{} problem}}\+: {\itshape don\textquotesingle{}t expand brace patterns into an array when they\textquotesingle{}re used for matching}.

Instead, convert the pattern into an optimized regular expression. This is easier said than done, and braces is the only library that does this currently.

{\bfseries{The proof is in the numbers}}

Minimatch gets exponentially slower as patterns increase in complexity, braces does not. The following results were generated using {\ttfamily braces()} and {\ttfamily minimatch.\+brace\+Expand()}, respectively.

\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{3}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Pattern}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{braces}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{\mbox{[}minimatch\mbox{]}\mbox{[}\mbox{]}}}    }\\\cline{1-3}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Pattern}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{braces}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{\mbox{[}minimatch\mbox{]}\mbox{[}\mbox{]}}}    }\\\cline{1-3}
\endhead
{\ttfamily \{1..9007199254740991\}}\mbox{[}$^\wedge$1\mbox{]}   &{\ttfamily 298 B} (5ms 459μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..1000000000000000\}}   &{\ttfamily 41 B} (1ms 15μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..100000000000000\}}   &{\ttfamily 40 B} (890μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..10000000000000\}}   &{\ttfamily 39 B} (2ms 49μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..1000000000000\}}   &{\ttfamily 38 B} (608μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..100000000000\}}   &{\ttfamily 37 B} (397μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..10000000000\}}   &{\ttfamily 35 B} (983μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..1000000000\}}   &{\ttfamily 34 B} (798μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..100000000\}}   &{\ttfamily 33 B} (733μs)   &N/A (freezes)    \\\cline{1-3}
{\ttfamily \{1..10000000\}}   &{\ttfamily 32 B} (5ms 632μs)   &{\ttfamily 78.\+89 MB} (16s 388ms 569μs)    \\\cline{1-3}
{\ttfamily \{1..1000000\}}   &{\ttfamily 31 B} (1ms 381μs)   &{\ttfamily 6.\+89 MB} (1s 496ms 887μs)    \\\cline{1-3}
{\ttfamily \{1..100000\}}   &{\ttfamily 30 B} (950μs)   &{\ttfamily 588.\+89 kB} (146ms 921μs)    \\\cline{1-3}
{\ttfamily \{1..10000\}}   &{\ttfamily 29 B} (1ms 114μs)   &{\ttfamily 48.\+89 kB} (14ms 187μs)    \\\cline{1-3}
{\ttfamily \{1..1000\}}   &{\ttfamily 28 B} (760μs)   &{\ttfamily 3.\+89 kB} (1ms 453μs)    \\\cline{1-3}
{\ttfamily \{1..100\}}   &{\ttfamily 22 B} (345μs)   &{\ttfamily 291 B} (196μs)    \\\cline{1-3}
{\ttfamily \{1..10\}}   &{\ttfamily 10 B} (533μs)   &{\ttfamily 20 B} (37μs)    \\\cline{1-3}
{\ttfamily \{1..3\}}   &{\ttfamily 7 B} (190μs)   &{\ttfamily 5 B} (27μs)   \\\cline{1-3}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4346}{}\doxysubsection{Faster algorithms}\label{md_sfcode_node_modules_braces_README_autotoc_md4346}
When you need expansion, braces is still much faster.

\+\_\+(the following results were generated using {\ttfamily braces.\+expand()} and {\ttfamily minimatch.\+brace\+Expand()}, respectively)\+\_\+

\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{3}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Pattern}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{braces}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{\mbox{[}minimatch\mbox{]}\mbox{[}\mbox{]}}}    }\\\cline{1-3}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Pattern}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{braces}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{\mbox{[}minimatch\mbox{]}\mbox{[}\mbox{]}}}    }\\\cline{1-3}
\endhead
{\ttfamily \{1..10000000\}}   &{\ttfamily 78.\+89 MB} (2s 698ms 642μs)   &{\ttfamily 78.\+89 MB} (18s 601ms 974μs)    \\\cline{1-3}
{\ttfamily \{1..1000000\}}   &{\ttfamily 6.\+89 MB} (458ms 576μs)   &{\ttfamily 6.\+89 MB} (1s 491ms 621μs)    \\\cline{1-3}
{\ttfamily \{1..100000\}}   &{\ttfamily 588.\+89 kB} (20ms 728μs)   &{\ttfamily 588.\+89 kB} (156ms 919μs)    \\\cline{1-3}
{\ttfamily \{1..10000\}}   &{\ttfamily 48.\+89 kB} (2ms 202μs)   &{\ttfamily 48.\+89 kB} (13ms 641μs)    \\\cline{1-3}
{\ttfamily \{1..1000\}}   &{\ttfamily 3.\+89 kB} (1ms 796μs)   &{\ttfamily 3.\+89 kB} (1ms 958μs)    \\\cline{1-3}
{\ttfamily \{1..100\}}   &{\ttfamily 291 B} (424μs)   &{\ttfamily 291 B} (211μs)    \\\cline{1-3}
{\ttfamily \{1..10\}}   &{\ttfamily 20 B} (487μs)   &{\ttfamily 20 B} (72μs)    \\\cline{1-3}
{\ttfamily \{1..3\}}   &{\ttfamily 5 B} (166μs)   &{\ttfamily 5 B} (27μs)   \\\cline{1-3}
\end{longtabu}


If you\textquotesingle{}d like to run these comparisons yourself, see \href{test/support/generate.js}{\texttt{ test/support/generate.\+js}}.\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4347}{}\doxysection{Benchmarks}\label{md_sfcode_node_modules_braces_README_autotoc_md4347}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4348}{}\doxysubsection{Running benchmarks}\label{md_sfcode_node_modules_braces_README_autotoc_md4348}
Install dev dependencies\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{npm i -\/d \&\& npm benchmark }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4349}{}\doxysubsection{Latest results}\label{md_sfcode_node_modules_braces_README_autotoc_md4349}
Braces is more accurate, without sacrificing performance.


\begin{DoxyCode}{0}
\DoxyCodeLine{\# range (expanded)}
\DoxyCodeLine{  braces x 29,040 ops/sec ±3.69\% (91 runs sampled))}
\DoxyCodeLine{  minimatch x 4,735 ops/sec ±1.28\% (90 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# range (optimized for regex)}
\DoxyCodeLine{  braces x 382,878 ops/sec ±0.56\% (94 runs sampled)}
\DoxyCodeLine{  minimatch x 1,040 ops/sec ±0.44\% (93 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# nested ranges (expanded)}
\DoxyCodeLine{  braces x 19,744 ops/sec ±2.27\% (92 runs sampled))}
\DoxyCodeLine{  minimatch x 4,579 ops/sec ±0.50\% (93 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# nested ranges (optimized for regex)}
\DoxyCodeLine{  braces x 246,019 ops/sec ±2.02\% (93 runs sampled)}
\DoxyCodeLine{  minimatch x 1,028 ops/sec ±0.39\% (94 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# set (expanded) }
\DoxyCodeLine{  braces x 138,641 ops/sec ±0.53\% (95 runs sampled)}
\DoxyCodeLine{  minimatch x 219,582 ops/sec ±0.98\% (94 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# set (optimized for regex)}
\DoxyCodeLine{  braces x 388,408 ops/sec ±0.41\% (95 runs sampled)}
\DoxyCodeLine{  minimatch x 44,724 ops/sec ±0.91\% (89 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# nested sets (expanded)}
\DoxyCodeLine{  braces x 84,966 ops/sec ±0.48\% (94 runs sampled)}
\DoxyCodeLine{  minimatch x 140,720 ops/sec ±0.37\% (95 runs sampled)}
\DoxyCodeLine{}
\DoxyCodeLine{\# nested sets (optimized for regex)}
\DoxyCodeLine{  braces x 263,340 ops/sec ±2.06\% (92 runs sampled)}
\DoxyCodeLine{  minimatch x 28,714 ops/sec ±0.40\% (90 runs sampled) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4350}{}\doxysection{About}\label{md_sfcode_node_modules_braces_README_autotoc_md4350}
$<$details$>$

{\bfseries{Contributing}} 

Pull requests and stars are always welcome. For bugs and feature requests, \href{../../issues/new}{\texttt{ please create an issue}}.

$<$/details$>$

$<$details$>$

{\bfseries{Running Tests}} 

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install \&\& npm test }

\end{DoxyCode}


$<$/details$>$

$<$details$>$

{\bfseries{Building docs}} 

\+\_\+(This project\textquotesingle{}s readme.\+md is generated by \href{https://github.com/verbose/verb-generate-readme}{\texttt{ verb}}, please don\textquotesingle{}t edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)\+\_\+

To generate the readme, run the following command\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install -\/g verbose/verb\#dev verb-\/generate-\/readme \&\& verb }

\end{DoxyCode}


$<$/details$>$\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4351}{}\doxysubsection{Contributors}\label{md_sfcode_node_modules_braces_README_autotoc_md4351}
\tabulinesep=1mm
\begin{longtabu}spread 0pt [c]{*{2}{|X[-1]}|}
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Commits}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Contributor}}    }\\\cline{1-2}
\endfirsthead
\hline
\endfoot
\hline
\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Commits}}   }&\PBS\centering \cellcolor{\tableheadbgcolor}\textbf{ {\bfseries{Contributor}}    }\\\cline{1-2}
\endhead
197   &\href{https://github.com/jonschlinkert}{\texttt{ jonschlinkert}}    \\\cline{1-2}
4   &\href{https://github.com/doowb}{\texttt{ doowb}}    \\\cline{1-2}
1   &\href{https://github.com/es128}{\texttt{ es128}}    \\\cline{1-2}
1   &\href{https://github.com/eush77}{\texttt{ eush77}}    \\\cline{1-2}
1   &\href{https://github.com/hemanth}{\texttt{ hemanth}}    \\\cline{1-2}
1   &\href{https://github.com/wtgtybhertgeghgtwtg}{\texttt{ wtgtybhertgeghgtwtg}}   \\\cline{1-2}
\end{longtabu}
\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4352}{}\doxysubsection{Author}\label{md_sfcode_node_modules_braces_README_autotoc_md4352}
{\bfseries{Jon Schlinkert}}


\begin{DoxyItemize}
\item \href{https://github.com/jonschlinkert}{\texttt{ Git\+Hub Profile}}
\item \href{https://twitter.com/jonschlinkert}{\texttt{ Twitter Profile}}
\item \href{https://linkedin.com/in/jonschlinkert}{\texttt{ Linked\+In Profile}}
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_braces_README_autotoc_md4353}{}\doxysubsection{License}\label{md_sfcode_node_modules_braces_README_autotoc_md4353}
Copyright © 2019, \href{https://github.com/jonschlinkert}{\texttt{ Jon Schlinkert}}. Released under the \mbox{[}MIT License\mbox{]}(LICENSE).

\DoxyHorRuler{0}


{\itshape This file was generated by \href{https://github.com/verbose/verb-generate-readme}{\texttt{ verb-\/generate-\/readme}}, v0.\+8.\+0, on April 08, 2019.} 