braces
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
arr-flatten | 1.1.0 | 2.8 kB | MIT | prod | |
array-unique | 0.3.2 | 2.72 kB | MIT | prod | |
define-property | 1.0.0 | 2.71 kB | MIT | prod | |
extend-shallow | 2.0.1 | 2.17 kB | MIT | prod | |
fill-range | 4.0.0 | 5.57 kB | MIT | prod | |
isobject | 3.0.1 | 2.77 kB | MIT | prod | |
repeat-element | 1.1.4 | 2.36 kB | MIT | prod | |
snapdragon-node | 2.1.1 | 6.06 kB | MIT | prod | |
snapdragon | 0.8.2 | 9.86 kB | MIT | prod | 4 |
split-string | 3.1.0 | 4.61 kB | MIT | prod | |
to-regex | 3.0.2 | 4.49 kB | MIT | prod |
Braces is a JavaScript library that implements Bash-like brace expansion. This library enables users to safely generate and match brace patterns. It offers complete support for the Bash 4.3 braces specification and is designed to be fast and efficient without compromising on safety. This makes it an ideal choice when dealing with brace patterns in JavaScript, as it can prevent aggressive or malicious brace patterns from breaking your application, such as those that could be used for DDoS attacks.
You can use the braces library by first installing it with npm using the following command: npm install --save braces
. Once installed, you can require it in your JavaScript file and use it like so:
const braces = require('braces');
console.log(braces(['{01..05}', '{a..e}']));
//=> ['(0[1-5])', '([a-e])']
console.log(braces(['{01..05}', '{a..e}'], { expand: true }));
//=> ['01', '02', '03', '04', '05', 'a', 'b', 'c', 'd', 'e']
The main export is a function that takes one or more brace 'patterns' and 'options'. By default, brace patterns are compiled into strings that are optimized for creating regular expressions and matching. You can set the expand
option to true if you want to enable brace expansion, which returns an array similar to what you'd expect from Bash. Additionally, it supports lists (aka "sets"), sequences (aka "ranges"), steps (aka "increments"), and escaping.
The official documentation for the braces library is in its README file, which is available on the project's GitHub page. You can visit the URL git+https://github.com/micromatch/braces.git to access the complete documentation. This includes detailed explanations on the use of the brace library, its options and different use-cases it supports, performance considerations, among others.