Organized code base, easy to maintain and make changes when edge cases arise
As you can see by the benchmarks, extglob doesn't pay with speed for it's completeness, accuracy and quality.
Heads up!: This library only supports extglobs, to handle full glob patterns and other extended globbing features use micromatch instead.
Usage
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'));
Extglob cheatsheet
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)
Functions are memoized based on the given glob patterns and options. Disable memoization by setting options.cache to false.
options.failglob
Type: boolean
Default: undefined
Throw an error is no matches are found.
Benchmarks
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
Differences from Bash
This library has complete parity with Bash 4.3 with only a couple of minor differences.
In some cases Bash returns true if the given string "contains" the pattern, whereas this library returns true if the string is an exact match for the pattern. You can relax this by setting options.contains to true.
This library is more accurate than Bash and thus does not fail some of the tests that Bash 4.3 still lists as failing in their unit tests
About
Related projects
braces: Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… more | homepage
(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:
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: