Wildmatch
Port in JS of the matching library used by Git.
Unlike other libraries like minimatch
, it doesn't use regexp and use a real parser.
Usage
var wildmatch = ; ; //=> true; //=> false; //=> true
Syntax
Wildmatch support the following features:
?
: Match a singe character*
: Match any string- Character classes: list (
[asd]
), ranges ([a-z]
), POSIX named classes ([[:alpha:]]
), negation ([!a-f]
or[^a-f]
) - Braces expansion:
file.{js,json}
will matchfile.js
andfile.json
. - Sequences:
{-1..1}
will turn into (-1
or0
or1
). You can also set a step size ({-5..5..5}
=>-5
,0
,5
), use letters ({a..e..2}
=>a
,c
,e
), and count backward ({Z..X}
=>Z
,Y
,X
) - Extended glob:
pattern-list
is a list of patterns separated by|
?(pattern-list)
: Matches zero or one occurrence of the given patterns*(pattern-list)
: Matches zero or more occurrences of the given patterns+(pattern-list)
: Matches one or more occurrences of the given patterns@(pattern-list)
: Matches one occurrences of the given patterns!(pattern-list)
: Matches anything except one of the given patterns
Options
You can path an options object to wildmatch as third parameter. Options include:
matchBase
: If set, then patterns without slashes will be matched against the basename of the path if it contains slashes. For example,a?b
would match the path/xyz/123/acb
, but not/xyz/acb/123
.case
: if set tofalse
, perform a case-insensitive matchpathname
: if set,?
,*
and character class do not match the/
characterbraces
: set it tofalse
to disable the processing of curly braces (braces expansion and sequences)extglob
: set it tofalse
to disable the match of extended glob pattern lists