Expand POSIX bracket expressions (character classes) in glob patterns.
Installations
npm install expand-brackets
Releases
Unable to fetch releases
Developer
micromatch
Developer Guide
Module System
CommonJS
Min. Node Version
>=4.0.0
Typescript Support
No
Node Version
8.9.4
NPM Version
5.6.0
Statistics
27 Stars
93 Commits
10 Forks
10 Watching
3 Branches
9 Contributors
Updated on 08 Apr 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
5,747,318,955
Last day
-6%
4,110,612
Compared to previous day
Last week
6.7%
24,539,140
Compared to previous week
Last month
55.3%
84,943,113
Compared to previous month
Last year
-19.8%
757,767,555
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
expand-brackets
Expand POSIX bracket expressions (character classes) in glob patterns.
Install
Install with npm:
1$ npm install --save expand-brackets
Install with yarn:
1$ yarn add expand-brackets
Usage
1var brackets = require('expand-brackets'); 2brackets(string[, options]);
Params
The main export is a function that takes the following parameters:
pattern
{String}: the pattern to convertoptions
{Object}: optionally supply an options objectreturns
{String}: returns a string that can be used to create a regex
Example
1console.log(brackets('[![:lower:]]')); 2//=> '[^a-z]'
API
brackets
Parses the given POSIX character class pattern
and returns a
string that can be used for creating regular expressions for matching.
Params
pattern
{String}options
{Object}returns
{Object}
.match
Takes an array of strings and a POSIX character class pattern, and returns a new array with only the strings that matched the pattern.
Params
arr
{Array}: Array of strings to matchpattern
{String}: POSIX character class pattern(s)options
{Object}returns
{Array}
Example
1const brackets = require('expand-brackets'); 2console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]')); 3//=> ['a'] 4 5console.log(brackets.match(['1', 'a', 'ab'], '[[:alpha:]]+')); 6//=> ['a', 'ab']
.isMatch
Returns true if the specified string
matches the given brackets pattern
.
Params
string
{String}: String to matchpattern
{String}: Poxis patternoptions
{String}returns
{Boolean}
Example
1const brackets = require('expand-brackets'); 2 3console.log(brackets.isMatch('a.a', '[[:alpha:]].[[:alpha:]]')); 4//=> true 5console.log(brackets.isMatch('1.2', '[[:alpha:]].[[:alpha:]]')); 6//=> false
.matcher
Takes a POSIX character class pattern and returns a matcher function. The returned function takes the string to match as its only argument.
Params
pattern
{String}: Poxis patternoptions
{String}returns
{Boolean}
Example
1const brackets = require('expand-brackets'); 2const isMatch = brackets.matcher('[[:lower:]].[[:upper:]]'); 3 4console.log(isMatch('a.a')); 5//=> false 6console.log(isMatch('a.A')); 7//=> true
.makeRe
Create a regular expression from the given pattern
.
Params
pattern
{String}: The pattern to convert to regex.options
{Object}returns
{RegExp}
Example
1const brackets = require('expand-brackets'); 2const re = brackets.makeRe('[[:alpha:]]'); 3console.log(re); 4//=> /^(?:[a-zA-Z])$/
.create
Parses the given POSIX character class pattern
and returns an object with the compiled output
and optional source map
.
Params
pattern
{String}options
{Object}returns
{Object}
Example
1const brackets = require('expand-brackets'); 2console.log(brackets('[[:alpha:]]')); 3// { options: { source: 'string' }, 4// input: '[[:alpha:]]', 5// state: {}, 6// compilers: 7// { eos: [Function], 8// noop: [Function], 9// bos: [Function], 10// not: [Function], 11// escape: [Function], 12// text: [Function], 13// posix: [Function], 14// bracket: [Function], 15// 'bracket.open': [Function], 16// 'bracket.inner': [Function], 17// 'bracket.literal': [Function], 18// 'bracket.close': [Function] }, 19// output: '[a-zA-Z]', 20// ast: 21// { type: 'root', 22// errors: [], 23// nodes: [ [Object], [Object], [Object] ] }, 24// parsingErrors: [] }
Options
options.sourcemap
Generate a source map for the given pattern.
Example
1var res = brackets('[:alpha:]', {sourcemap: true}); 2 3console.log(res.map); 4// { version: 3, 5// sources: [ 'brackets' ], 6// names: [], 7// mappings: 'AAAA,MAAS', 8// sourcesContent: [ '[:alpha:]' ] }
POSIX Character classes
The following named POSIX bracket expressions are supported:
[:alnum:]
: Alphanumeric characters (a-zA-Z0-9]
)[:alpha:]
: Alphabetic characters (a-zA-Z]
)[:blank:]
: Space and tab ([ t]
)[:digit:]
: Digits ([0-9]
)[:lower:]
: Lowercase letters ([a-z]
)[:punct:]
: Punctuation and symbols. ([!"#$%&'()*+, -./:;<=>?@ [\]^_``{|}~]
)[:upper:]
: Uppercase letters ([A-Z]
)[:word:]
: Word characters (letters, numbers and underscores) ([A-Za-z0-9_]
)[:xdigit:]
: Hexadecimal digits ([A-Fa-f0-9]
)
See posix-character-classes for more details.
Not supported
- equivalence classes are not supported
- POSIX.2 collating symbols are not supported
Changelog
v4.0.0
Breaking changes
- Snapdragon was updated to 0.12. Other packages that integrate
expand-brackets
need to also use snapdragon 0.12. - Minimum Node.JS version is now version 4.
v3.0.0
Breaking changes
- Snapdragon was updated to 0.11. Other packages that integrate
expand-brackets
need to also use snapdragon 0.11.
v2.0.0
Breaking changes
- The main export now returns the compiled string, instead of the object returned from the compiler
Added features
- Adds a
.create
method to do what the main function did before v2.0.0
v0.2.0
In addition to performance and matching improvements, the v0.2.0 refactor adds complete POSIX character class support, with the exception of equivalence classes and POSIX.2 collating symbols which are not relevant to node.js usage.
Added features
- parser is exposed, so that expand-brackets parsers can be used by upstream parsers (like micromatch)
- compiler is exposed, so that expand-brackets compilers can be used by upstream compilers
- source maps
source map example
1var brackets = require('expand-brackets'); 2var res = brackets('[:alpha:]'); 3console.log(res.map); 4 5{ version: 3, 6 sources: [ 'brackets' ], 7 names: [], 8 mappings: 'AAAA,MAAS', 9 sourcesContent: [ '[:alpha:]' ] }
About
Related projects
- braces: Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… more | homepage
- extglob: Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob… more | homepage
- micromatch: Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | homepage
- nanomatch: Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but complete Bash… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Commits | Contributor |
---|---|
69 | jonschlinkert |
13 | danez |
2 | MartinKolarik |
2 | es128 |
1 | doowb |
1 | eush77 |
1 | mjbvz |
Building docs
(This project's readme.md is generated by verb, please don'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:
1$ npm install -g verbose/verb#dev verb-generate-readme && verb
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:
1$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2018, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on April 30, 2018.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/micromatch/.github/SECURITY.md:1
- Info: Found linked content: github.com/micromatch/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/micromatch/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/micromatch/.github/SECURITY.md:1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to expand-brackets
picomatch
Blazing fast and accurate glob matcher written in JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions.
brace-expansion
Brace expansion as known from sh/bash
dotenv-expand
Expand environment variables using dotenv
expand-tilde
Bash-like tilde expansion for node.js. Expands a leading tilde in a file path to the user home directory, or `~+` to the cwd.