Gathering detailed insights and metrics for expand-brackets
Gathering detailed insights and metrics for expand-brackets
Gathering detailed insights and metrics for expand-brackets
Gathering detailed insights and metrics for 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.
Expand POSIX bracket expressions (character classes) in glob patterns.
npm install expand-brackets
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
27 Stars
93 Commits
10 Forks
10 Watching
3 Branches
9 Contributors
Updated on 08 Apr 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
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
Expand POSIX bracket expressions (character classes) in glob patterns.
Install with npm:
1$ npm install --save expand-brackets
Install with yarn:
1$ yarn add expand-brackets
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 regexExample
1console.log(brackets('[![:lower:]]')); 2//=> '[^a-z]'
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}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']
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
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
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])$/
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: [] }
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:]' ] }
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
Breaking changes
expand-brackets
need to also use snapdragon 0.12.Breaking changes
expand-brackets
need to also use snapdragon 0.11.Breaking changes
Added features
.create
method to do what the main function did before v2.0.0In 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
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:]' ] }
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
69 | jonschlinkert |
13 | danez |
2 | MartinKolarik |
2 | es128 |
1 | doowb |
1 | eush77 |
1 | mjbvz |
(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 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
Jon Schlinkert
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
Reason
security policy file detected
Details
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
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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 More