Security News
How Threat Actors are Abusing GitHub’s File Upload Feature to Host Malware
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
extglob
Advanced tools
Changelog
v3.0.0
Breaking changes
extglob
need to also use snapdragon 0.12.Readme
Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.
Install with npm:
$ npm install --save extglob
Install with yarn:
$ yarn add extglob
Heads up!: This library only supports extglobs, to handle full glob patterns and other extended globbing features use micromatch instead.
The main export is a function that takes a string and options, and returns an object with the parsed AST and the compiled .output
, which is a regex-compatible string that can be used for matching.
var extglob = require('extglob');
console.log(extglob('!(xyz)*.js'));
Extended globbing patterns can be defined as follows (as described by the bash man page):
pattern | regex equivalent | description |
---|---|---|
?(pattern-list) | (...|...)? | Matches zero or one occurrence of the given pattern(s) |
*(pattern-list) | (...|...)* | Matches zero or more occurrences of the given pattern(s) |
+(pattern-list) | (...|...)+ | Matches one or more occurrences of the given pattern(s) |
@(pattern-list) | (...|...) [^1] | Matches one of the given pattern(s) |
!(pattern-list) | N/A | Matches anything except one of the given pattern(s) |
Convert the given extglob
pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST.
Params
pattern
{String}options
{Object}returns
{String}Example
const extglob = require('extglob');
console.log(extglob('*.!(*a)'));
//=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
Takes an array of strings and an extglob pattern and returns a new array that contains only the strings that match the pattern.
Params
list
{Array}: Array of strings to matchpattern
{String}: Extglob patternoptions
{Object}returns
{Array}: Returns an array of matchesExample
const extglob = require('extglob');
console.log(extglob.match(['a.a', 'a.b', 'a.c'], '*.!(*a)'));
//=> ['a.b', 'a.c']
Returns true if the specified string
matches the given extglob pattern
.
Params
string
{String}: String to matchpattern
{String}: Extglob patternoptions
{String}returns
{Boolean}Example
const extglob = require('extglob');
console.log(extglob.isMatch('a.a', '*.!(*a)'));
//=> false
console.log(extglob.isMatch('a.b', '*.!(*a)'));
//=> true
Returns true if the given string
contains the given pattern. Similar to .isMatch
but the pattern can match any part of the string.
Params
str
{String}: The string to match.pattern
{String}: Glob pattern to use for matching.options
{Object}returns
{Boolean}: Returns true if the patter matches any part of str
.Example
const extglob = require('extglob');
console.log(extglob.contains('aa/bb/cc', '*b'));
//=> true
console.log(extglob.contains('aa/bb/cc', '*d'));
//=> false
Takes an extglob pattern and returns a matcher function. The returned function takes the string to match as its only argument.
Params
pattern
{String}: Extglob patternoptions
{String}returns
{Boolean}Example
const extglob = require('extglob');
const isMatch = extglob.matcher('*.!(*a)');
console.log(isMatch('a.a'));
//=> false
console.log(isMatch('a.b'));
//=> true
Convert the given extglob
pattern into a regex-compatible string. Returns an object with the compiled result and the parsed AST.
Params
str
{String}options
{Object}returns
{String}Example
const extglob = require('extglob');
console.log(extglob.create('*.!(*a)').output);
//=> '(?!\\.)[^/]*?\\.(?!(?!\\.)[^/]*?a\\b).*?'
Returns an array of matches captured by pattern
in string
, or null
if the pattern did not match.
Params
pattern
{String}: Glob pattern to use for matching.string
{String}: String to matchoptions
{Object}: See available options for changing how matches are performedreturns
{Boolean}: Returns an array of captures if the string matches the glob pattern, otherwise null
.Example
const extglob = require('extglob');
extglob.capture(pattern, string[, options]);
console.log(extglob.capture('test/*.js', 'test/foo.js'));
//=> ['foo']
console.log(extglob.capture('test/*.js', 'foo/bar.css'));
//=> null
Create a regular expression from the given pattern
and options
.
Params
pattern
{String}: The pattern to convert to regex.options
{Object}returns
{RegExp}Example
const extglob = require('extglob');
const re = extglob.makeRe('*.!(*a)');
console.log(re);
//=> /^[^\/]*?\.(?![^\/]*?a)[^\/]*?$/
Available options are based on the options from Bash (and the option names used in bash).
Type: boolean
Default: undefined
When enabled, the pattern itself will be returned when no matches are found.
Alias for options.nullglob, included for parity with minimatch.
Type: boolean
Default: undefined
Functions are memoized based on the given glob patterns and options. Disable memoization by setting options.cache
to false.
Type: boolean
Default: undefined
Throw an error is no matches are found.
Last run on April 30, 2018
# negation-nested (49 bytes)
extglob x 1,380,148 ops/sec ±3.35% (62 runs sampled)
minimatch x 156,800 ops/sec ±4.13% (76 runs sampled)
fastest is extglob (by 880% avg)
# negation-simple (43 bytes)
extglob x 1,821,746 ops/sec ±1.61% (76 runs sampled)
minimatch x 365,618 ops/sec ±1.87% (84 runs sampled)
fastest is extglob (by 498% avg)
# range-false (57 bytes)
extglob x 2,038,592 ops/sec ±3.39% (85 runs sampled)
minimatch x 310,897 ops/sec ±12.62% (87 runs sampled)
fastest is extglob (by 656% avg)
# range-true (56 bytes)
extglob x 2,105,081 ops/sec ±0.69% (91 runs sampled)
minimatch x 332,188 ops/sec ±0.45% (91 runs sampled)
fastest is extglob (by 634% avg)
# star-simple (46 bytes)
extglob x 2,154,184 ops/sec ±0.99% (89 runs sampled)
minimatch x 452,812 ops/sec ±0.51% (88 runs sampled)
fastest is extglob (by 476% avg)
This library has complete parity with Bash 4.3 with only a couple of minor differences.
options.contains
to true.step
to… more | homepagePull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Commits | Contributor |
---|---|
54 | jonschlinkert |
6 | danez |
2 | isiahmeadows |
1 | doowb |
1 | devongovett |
1 | mjbvz |
1 | shinnn |
(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:
$ 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:
$ 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.
FAQs
Extended glob support for JavaScript. Adds (almost) the expressive power of regular expressions to glob patterns.
The npm package extglob receives a total of 11,762,146 weekly downloads. As such, extglob popularity was classified as popular.
We found that extglob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
GitHub is susceptible to a CDN flaw that allows attackers to host malware on any public repository.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.