0.1.0 • Published 12 years ago
wildmatch v0.1.0
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 = require('wildmatch');
wildmatch('bar.foo', '*.foo'); //=> true
wildmatch('bar.foo', '*.bar'); //=> false
wildmatch('D', '[[:xdigit:]]'); //=> trueSyntax
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.jsandfile.json. - Sequences:
{-1..1}will turn into (-1or0or1). 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-listis 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?bwould 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 tofalseto disable the processing of curly braces (braces expansion and sequences)extglob: set it tofalseto disable the match of extended glob pattern lists