Socket
Socket
Sign inDemoInstall

braces

Package Overview
Dependencies
3
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    braces

Fastest brace expansion lib. Typically used with file paths, but can be used with any string. Expands comma-separated values (e.g. `foo/{a,b,c}/bar`) and alphabetical or numerical ranges (e.g. `{1..9}`)


Version published
Weekly downloads
64M
increased by2.71%
Maintainers
1
Install size
48.2 kB
Created
Weekly downloads
 

Package description

What is braces?

The braces npm package is a library for expanding braces in a string, similar to how shells like bash perform brace expansion. It is used to generate permutations of strings based on patterns with braces, which is useful for file globbing, configuration, and other tasks where such patterns are needed.

What are braces's main functionalities?

Brace Expansion

Expands a pattern with comma-separated values inside braces into an array of strings.

"{a,b,c}d" -> ['ad', 'bd', 'cd']

Sequence Expansion

Expands a pattern with numerical sequences inside braces into an array of strings.

"{1..3}d" -> ['1d', '2d', '3d']

Nested Expansion

Expands a pattern with nested braces into an array of strings.

"{a,{b,c}d}e" -> ['ae', 'bde', 'cde']

Other packages similar to braces

Readme

Source

braces NPM version

Fastest brace expansion lib. Typically used with file paths, but can be used with any string. Expands comma-separated values (e.g. foo/{a,b,c}/bar) and alphabetical or numerical ranges (e.g. {1..9})

Benchmarks

node benchmark

Example usage

var expand = require('braces');

expand('a/{x,y}/c{d}e')
//=> ['a/x/cde', 'a/y/cde']

expand('a/b/c/{x,y}')
//=> ['a/b/c/x', 'a/b/c/y']

expand('a/{x,{1..5},y}/c{d}e')
//=> ['a/x/cde', 'a/1/cde', 'a/y/cde', 'a/2/cde', 'a/3/cde', 'a/4/cde', 'a/5/cde']

See the examples and tests to see more use cases.

Range expansion

Uses expand-range for range expansion.

expand('a{1..3}b')
//=> ['a1b', 'a2b', 'a3b']

expand('a{5..8}b')
//=> ['a5b', 'a6b', 'a7b', 'a8b']

expand('a{00..05}b')
//=> ['a00b', 'a01b', 'a02b', 'a03b', 'a04b', 'a05b']

expand('a{01..03}b')
//=> ['a01b', 'a02b', 'a03b']

expand('a{000..005}b')
//=> ['a000b', 'a001b', 'a002b', 'a003b', 'a004b', 'a005b']

expand('a{a..e}b')
//=> ['aab', 'abb', 'acb', 'adb', 'aeb']

expand('a{A..E}b')
//=> ['aAb', 'aBb', 'aCb', 'aDb', 'aEb']

Pass a function as the last argument to customize range expansions:

var range = expand('x{a..e}y', function (str, i) {
  return String.fromCharCode(str) + i;
});

console.log(range);
//=> ['xa0y', 'xb1y', 'xc2y', 'xd3y', 'xe4y']

See expand-range for benchmarks, tests and information related to expanding ranges.

Install

Install with npm

npm i braces --save

Run tests

npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on November 23, 2014.

Keywords

FAQs

Last updated on 24 Nov 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc