1 | # brace-expansion
|
2 |
|
3 | [Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
|
4 | as known from sh/bash, in JavaScript.
|
5 |
|
6 | [](https://github.com/juliangruber/brace-expansion/actions/workflows/ci.yml)
|
7 | [](https://www.npmjs.org/package/brace-expansion)
|
8 |
|
9 | ## Example
|
10 |
|
11 | ```js
|
12 | import expand from 'brace-expansion'
|
13 |
|
14 | expand('file-{a,b,c}.jpg')
|
15 | // => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
16 |
|
17 | expand('-v{,,}')
|
18 | // => ['-v', '-v', '-v']
|
19 |
|
20 | expand('file{0..2}.jpg')
|
21 | // => ['file0.jpg', 'file1.jpg', 'file2.jpg']
|
22 |
|
23 | expand('file-{a..c}.jpg')
|
24 | // => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
25 |
|
26 | expand('file{2..0}.jpg')
|
27 | // => ['file2.jpg', 'file1.jpg', 'file0.jpg']
|
28 |
|
29 | expand('file{0..4..2}.jpg')
|
30 | // => ['file0.jpg', 'file2.jpg', 'file4.jpg']
|
31 |
|
32 | expand('file-{a..e..2}.jpg')
|
33 | // => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
|
34 |
|
35 | expand('file{00..10..5}.jpg')
|
36 | // => ['file00.jpg', 'file05.jpg', 'file10.jpg']
|
37 |
|
38 | expand('{{A..C},{a..c}}')
|
39 | // => ['A', 'B', 'C', 'a', 'b', 'c']
|
40 |
|
41 | expand('ppp{,config,oe{,conf}}')
|
42 | // => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
|
43 | ```
|
44 |
|
45 | ## API
|
46 |
|
47 | ```js
|
48 | import expand from 'brace-expansion'
|
49 | ```
|
50 |
|
51 | ### const expanded = expand(str)
|
52 |
|
53 | Return an array of all possible and valid expansions of `str`. If none are
|
54 | found, `[str]` is returned.
|
55 |
|
56 | Valid expansions are:
|
57 |
|
58 | ```js
|
59 | /^(.*,)+(.+)?$/
|
60 | // {a,b,...}
|
61 | ```
|
62 |
|
63 | A comma separated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
|
64 |
|
65 | ```js
|
66 | /^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
67 | // {x..y[..incr]}
|
68 | ```
|
69 |
|
70 | A numeric sequence from `x` to `y` inclusive, with optional increment.
|
71 | If `x` or `y` start with a leading `0`, all the numbers will be padded
|
72 | to have equal length. Negative numbers and backwards iteration work too.
|
73 |
|
74 | ```js
|
75 | /^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
76 | // {x..y[..incr]}
|
77 | ```
|
78 |
|
79 | An alphabetic sequence from `x` to `y` inclusive, with optional increment.
|
80 | `x` and `y` must be exactly one character, and if given, `incr` must be a
|
81 | number.
|
82 |
|
83 | For compatibility reasons, the string `${` is not eligible for brace expansion.
|
84 |
|
85 | ## Installation
|
86 |
|
87 | With [npm](https://npmjs.org) do:
|
88 |
|
89 | ```bash
|
90 | npm install brace-expansion
|
91 | ```
|
92 |
|
93 | ## Contributors
|
94 |
|
95 | - [Julian Gruber](https://github.com/juliangruber)
|
96 | - [Isaac Z. Schlueter](https://github.com/isaacs)
|
97 | - [Haelwenn Monnier](https://github.com/lanodan)
|
98 |
|
99 | ## Sponsors
|
100 |
|
101 | This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!
|
102 |
|
103 | Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my [Patreon](https://www.patreon.com/juliangruber). Not sure how much of my modules you're using? Try [feross/thanks](https://github.com/feross/thanks)!
|
104 |
|
105 | ## Security contact information
|
106 |
|
107 | To report a security vulnerability, please use the
|
108 | [Tidelift security contact](https://tidelift.com/security).
|
109 | Tidelift will coordinate the fix and disclosure.
|
110 |
|
111 | ## License
|
112 |
|
113 | (MIT)
|
114 |
|
115 | Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
116 |
|
117 | Permission is hereby granted, free of charge, to any person obtaining a copy of
|
118 | this software and associated documentation files (the "Software"), to deal in
|
119 | the Software without restriction, including without limitation the rights to
|
120 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
121 | of the Software, and to permit persons to whom the Software is furnished to do
|
122 | so, subject to the following conditions:
|
123 |
|
124 | The above copyright notice and this permission notice shall be included in all
|
125 | copies or substantial portions of the Software.
|
126 |
|
127 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
128 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
129 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
130 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
131 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
132 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
133 | SOFTWARE.
|