Socket
Socket
Sign inDemoInstall

micromatch

Package Overview
Dependencies
33
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.6 to 2.2.0

8

index.js

@@ -11,5 +11,5 @@ /*!

var diff = require('arr-diff');
var debug = require('debug')('micromatch');
var typeOf = require('kind-of');
var omit = require('object.omit');
var unique = require('array-unique');
var cache = require('regex-cache');

@@ -116,4 +116,8 @@ var isGlob = require('is-glob');

opts = omit(opts, ['ignore']);
return diff(res, micromatch(res, pattern, opts));
res = diff(res, micromatch(res, pattern, opts));
}
if (opts.nodupes) {
return unique(res);
}
return res;

@@ -120,0 +124,0 @@ }

'use strict';
var reverse = function(object, prepender) {
return Object.keys(object).reduce(function(reversed, key) {
var newKey = prepender ? prepender + key : key; // Optionally prepend a string to key.
reversed[object[key]] = newKey; // Swap key and value.
return reversed; // Return the result.
}, {});
};
var chars = {};

@@ -42,14 +50,3 @@

chars.UNESC = {
'__UNESC_QMRK__' : '\\?',
'__UNESC_AMPE__' : '\\@',
'__UNESC_EXCL__' : '\\!',
'__UNESC_PLUS__' : '\\+',
'__UNESC_STAR__' : '\\*',
'__UNESC_COMMA__' : '\\*',
'__UNESC_LTPAREN__': '\\(',
'__UNESC_RTPAREN__': '\\)',
'__UNESC_LTBRACK__': '\\[',
'__UNESC_RTBRACK__': '\\]',
};
chars.UNESC = reverse(chars.ESC, '\\');

@@ -69,15 +66,4 @@ chars.ESC_TEMP = {

chars.TEMP = {
'__TEMP_QMRK__' : '?',
'__TEMP_AMPE__' : '@',
'__TEMP_EXCL__' : '!',
'__TEMP_STAR__' : '*',
'__TEMP_PLUS__' : '+',
'__TEMP_COMMA__' : ',',
'__TEMP_LTPAREN__': '(',
'__TEMP_RTPAREN__': ')',
'__TEMP_LTBRACK__': '[',
'__TEMP_RTBRACK__': ']',
};
chars.TEMP = reverse(chars.ESC_TEMP);
module.exports = chars;

@@ -37,2 +37,6 @@ /*!

if (typeof opts.braces !== 'boolean' && typeof opts.nobraces !== 'boolean') {
opts.braces = true;
}
// return early if glob pattern matches special patterns

@@ -43,28 +47,43 @@ if (specialCase(pattern) && opts.safemode) {

if (opts.nonegate !== true) {
opts.negated = glob.negated;
if (glob.pattern === '.*') {
return {
pattern: '\\.' + star,
tokens: tok,
options: opts
};
}
glob._replace('/.', '/\\.');
if (glob.pattern === '.') {
return {
pattern: '\\.',
tokens: tok,
options: opts
};
}
if (glob.pattern === '*') {
return {
pattern: oneStar(opts.dot),
tokens: tok,
options: opts
};
}
// parse the glob pattern into tokens
glob.parse();
var tok = glob.tokens;
tok.is.negated = opts.negated;
if (tok.is.dotfile) {
glob.options.dot = true;
// dotfile handling
if ((opts.dotfiles === true || tok.is.dotfile) && opts.dot !== false) {
opts.dotfiles = true;
opts.dot = true;
}
if (!tok.is.glob) {
return {
pattern: utils.escapePath(glob.pattern),
tokens: tok,
options: opts
};
if ((opts.dotdirs === true || tok.is.dotdir) && opts.dot !== false) {
opts.dotdirs = true;
opts.dot = true;
}
// see if it might be a dotfile pattern
// check for braces with a dotfile pattern
if (/[{,]\./.test(glob.pattern)) {

@@ -75,3 +94,16 @@ opts.makeRe = false;

// expand braces, e.g `{1..5}`
if (opts.nonegate !== true) {
opts.negated = glob.negated;
}
// if the leading character is a dot or a slash, escape it
if (glob.pattern.charAt(0) === '.' && glob.pattern.charAt(1) !== '/') {
glob.pattern = '\\' + glob.pattern;
}
/**
* Extended globs
*/
// expand brackets, e.g `[[:alpha:]]`
glob.track('before brackets');

@@ -81,2 +113,5 @@ if (tok.is.brackets) {

}
glob.track('after brackets');
// expand braces, e.g `{1..5}`
glob.track('before braces');

@@ -86,10 +121,21 @@ if (tok.is.braces) {

}
glob.track('after braces');
// expand extglobs, e.g `foo/!(a|b)`
glob.track('before extglob');
if (tok.is.extglob) {
glob.extglob();
}
glob.track('after extglob');
// special patterns
glob._replace('[!', '[^');
glob._replace('(?', '(%~');
glob._replace('[]', '\\[\\]');
glob._replace('(?', '__QMARK_GROUP__');
glob._replace('/[', '/' + (opts.dot ? dotfiles : nodot) + '[', true);
glob._replace('/?', '/' + (opts.dot ? dotfiles : nodot) + '[^/]', true);
glob._replace('/.', '/(?=.)\\.', true);
// windows drives
glob._replace(/^(\w):([\\\/]+?)/gi, lookahead + '$1:$2', true);
glob._replace(/^(\w):([\\\/]+?)/gi, '(?=.)$1:$2', true);

@@ -101,12 +147,6 @@ // negate slashes in exclusion ranges

if (glob.pattern === '**' && opts.globstar !== false) {
glob.pattern = globstar(opts);
if (opts.globstar !== false && glob.pattern === '**') {
glob.pattern = globstar(opts.dot);
} else {
if (/^\*\.\w*$/.test(glob.pattern)) {
glob._replace('*', star(opts.dot) + '\\');
glob._replace('__QMARK_GROUP__', '(?');
return glob;
}
// '/*/*/*' => '(?:/*){3}'

@@ -122,29 +162,30 @@ glob._replace(/(\/\*)+/g, function (match) {

// if the glob is for one directory deep, we can
// simplify the parsing and generated regex
if (tok.path.dirname === '' && !tok.is.globstar) {
glob.track('before expand filename');
return expandFilename(glob, opts);
}
// if the pattern has `**`
if (tok.is.globstar) {
glob.pattern = collapse(glob.pattern, '/**');
glob.pattern = collapse(glob.pattern, '**/');
glob._replace(/\*{2,}/g, '**');
glob.pattern = collapse(glob.pattern, '/**');
glob.pattern = optionalGlobstar(glob.pattern);
// reduce extraneous globstars
glob._replace(/(^|[^\\])\*{2,}([^\\]|$)/g, '$1**$2');
// 'foo/*'
glob._replace(/(\w+)\*(?!\/)/g, '$1[^/]*?', true);
glob._replace(/\*\*\/\*(\w)/g, globstar(opts.dot) + '\\/' + (opts.dot ? dotfiles : nodot) + '[^/]*?$1', true);
// 'foo/*'
glob._replace(/(\w+)\*(?!\/)/g, '(?=.)$1[^/]*?', true);
glob._replace('**', globstar(opts), true);
if (opts.dot !== true) {
glob._replace(/\*\*\/(.)/g, '(?:**\\/|)$1');
}
// 'foo/**' or '{**,*}', but not 'foo**'
if (tok.path.dirname !== '' || /,\*\*|\*\*,/.test(glob.orig)) {
glob._replace('**', globstar(opts.dot), true);
}
}
// ends with /*
glob._replace(/\/\*$/, '\\/' + stardot(opts), true);
glob._replace(/\/\*$/, '\\/' + oneStar(opts.dot), true);
// ends with *, no slashes
glob._replace(/(?!\/)\*$/, boxQ, true);
glob._replace(/(?!\/)\*$/, star, true);
// has 'n*.' (partial wildcard w/ file extension)
glob._replace(/([^\/]+)\*/, '$1' + oneStar(true), true);
// has '*'
glob._replace('*', stardot(opts), true);
glob._replace('*', oneStar(opts.dot), true);
glob._replace('?.', '?\\.', true);

@@ -156,5 +197,5 @@ glob._replace('?:', '?:', true);

if (len === 1) {
return box;
return qmark;
}
return box + '{' + len + '}';
return qmark + '{' + len + '}';
});

@@ -165,3 +206,3 @@

// fix '[^\\\\/]'
glob._replace(/\[\^[\\\/]+\]/g, box);
glob._replace(/\[\^[\\\/]+\]/g, qmark);
// '///' => '\/'

@@ -173,58 +214,21 @@ glob._replace(/\/+/g, '\\/');

glob._replace('__QMARK_GROUP__', '(?');
// unescape previously escaped patterns
glob.unescape(glob.pattern);
glob._replace('__UNESC_STAR__', '*');
glob._replace('%~', '?');
glob._replace('%%', '*');
// escape dots that follow qmarks
glob._replace('?.', '?\\.');
glob._replace('[^\\/]', '[^/]');
return glob;
}
/**
* Expand the filename part of the glob into a regex
* compatible string
*
* @param {String} glob
* @param {Object} tok Tokens
* @param {Options} opts
* @return {Object}
*/
// remove unnecessary slashes in character classes
glob._replace('[^\\/]', qmark);
function expandFilename(glob, opts) {
var tok = glob.tokens;
switch (glob.pattern) {
case '.':
glob.pattern = '\\.';
break;
case '.*':
glob.pattern = '\\..*';
break;
case '*.*':
glob.pattern = star(opts.dot) + '\\.[^/]*?';
break;
case '*':
glob.pattern = star(opts.dot);
break;
default:
if (tok.path.filename === '*' && !tok.path.dirname) {
glob.pattern = star(opts.dot) + '\\' + glob.pattern.slice(1);
} else {
glob._replace(/(?!\()\?/g, '[^/]');
if (tok.path.basename.charAt(0) !== '.') {
opts.dot = true;
}
glob._replace('*', star(opts.dot));
if (glob.pattern.length > 1) {
if (glob.pattern.indexOf('\\/') === 0 && glob.pattern.indexOf('\\/' + nodot) !== 0) {
glob.pattern = '\\/' + nodot + glob.pattern.slice(2);
} else if (/^[\[?*]/.test(glob.pattern)) {
// only prepend the string if we don't want to match dotfiles
glob.pattern = (opts.dot ? dotfiles : nodot) + glob.pattern;
}
}
if (glob.pattern.charAt(0) === '.') {
glob.pattern = '\\' + glob.pattern;
}
glob._replace('__QMARK_GROUP__', '(?');
glob.unescape(glob.pattern);
glob._replace('__UNESC_STAR__', '*');
glob._replace('%~', '?');
glob._replace('%%', '*');
return glob;

@@ -234,3 +238,4 @@ }

/**
* Special cases
* Special cases. This is somewhat of a placeholder
* for more advanced logic.
*/

@@ -254,22 +259,13 @@

* @param {String} `str`
* @param {String} `ch`
* @param {String} `ch` Character sequence to collapse
* @return {String}
*/
function collapse(str, ch, repeat) {
function collapse(str, ch) {
var res = str.split(ch);
var len = res.length;
var isFirst = res[0] === '';
var isLast = res[res.length - 1] === '';
res = res.filter(Boolean);
if (isFirst) {
res.unshift('');
}
if (isLast) {
res.push('');
}
var diff = len - res.length;
if (repeat && diff >= 1) {
ch = '(?:' + ch + '){' + (diff + 1) + '}';
}
if (isFirst) res.unshift('');
if (isLast) res.push('');
return res.join(ch);

@@ -279,26 +275,2 @@ }

/**
* Make globstars optional, as in glob spec:
*
* ```js
* optionalGlobstar('a\/**\/b');
* //=> '(?:a\/b|a\/**\/b)'
* ```
*
* @param {String} `str`
* @return {String}
*/
function optionalGlobstar(glob) {
// globstars preceded and followed by a word character
if (/[^\/]\/\*\*\/[^\/]/.test(glob)) {
var tmp = glob.split('/**/').join('/');
glob = '(?:' + tmp + '|' + glob + ')';
// leading globstars
} else if (/^\*\*\/[^\/]/.test(glob)) {
glob = glob.split(/^\*\*\//).join('(^|.+\\/)');
}
return glob;
}
/**
* Negate slashes in exclusion ranges, per glob spec:

@@ -311,9 +283,8 @@ *

*
* @param {[type]} str [description]
* @return {[type]}
* @param {String} `str` glob pattern
* @return {String}
*/
function negateSlash(str) {
var re = /\[\^([^\]]*?)\]/g;
return str.replace(re, function (match, inner) {
return str.replace(/\[\^([^\]]*?)\]/g, function (match, inner) {
if (inner.indexOf('/') === -1) {

@@ -327,3 +298,5 @@ inner = '\\/' + inner;

/**
* Escape imbalanced braces/bracket
* Escape imbalanced braces/bracket. This is a very
* basic, naive implementation that only does enough
* to serve the purpose.
*/

@@ -344,12 +317,2 @@

/**
* Escape utils
*/
function esc(str) {
str = str.split('?').join('%~');
str = str.split('*').join('%%');
return str;
}
/**
* Special patterns to be converted to regex.

@@ -360,34 +323,23 @@ * Heuristics are used to simplify patterns

var box = '[^/]';
var boxQ = '[^/]*?';
var lookahead = '(?=.)';
var qmark = '[^/]';
var star = qmark + '*?';
var nodot = '(?!\\.)(?=.)';
var dotfileGlob = '(?:\\/|^)\\.{1,2}($|\\/)';
var dotfiles = '(?!' + dotfileGlob + ')(?=.)';
var twoStarDot = '(?:(?!' + dotfileGlob + ').)*?';
var ex = {};
ex.dotfileGlob = '(?:^|\\/)(?:\\.{1,2})(?:$|\\/)';
ex.stardot = '(?!' + ex.dotfileGlob + ')(?=.)[^/]*?';
ex.twoStarDot = '(?:(?!' + ex.dotfileGlob + ').)*?';
/**
* Create a regex for `*`. If `dot` is true,
* or the pattern does not begin with a leading
* star, then return the simple regex.
* Create a regex for `*`.
*
* If `dot` is true, or the pattern does not begin with
* a leading star, then return the simpler regex.
*/
function star(dotfile) {
return dotfile ? boxQ : nodot + boxQ;
function oneStar(dotfile) {
return dotfile ? '(?!' + dotfileGlob + ')(?=.)' + star : (nodot + star);
}
function dotstarbase(dotfile) {
var re = dotfile ? ex.dotfileGlob : '\\.';
return '(?!' + re + ')' + lookahead;
function globstar(dotfile) {
if (dotfile) { return twoStarDot; }
return '(?:(?!(?:\\/|^)\\.).)*?';
}
function globstar(opts) {
if (opts.dot) { return ex.twoStarDot; }
return '(?:(?!(?:^|\\/)\\.).)*?';
}
function stardot(opts) {
return dotstarbase(opts && opts.dot) + '[^/]*?';
}
'use strict';
var braces = require('braces');
var brackets = require('expand-brackets');
var braces = require('braces');
var extglob = require('extglob');
var parse = require('parse-glob');

@@ -30,3 +31,2 @@ var chars = require('./chars');

this.options.track = this.options.track || false;
this.options.dot = this.options.dot || this.options.dotfiles;
this.options.makeRe = true;

@@ -70,2 +70,3 @@ };

Glob.prototype.isNegated = function() {
if (this.tokens.isNegated) return true;
if (this.pattern.charCodeAt(0) === 33 /* '!' */) {

@@ -79,13 +80,2 @@ this.pattern = this.pattern.slice(1);

/**
* Return true if the glob pattern has braces
*
* @param {String} `pattern`
* @return {Boolean}
*/
Glob.prototype.hasBraces = function(pattern) {
return this.has((pattern || this.pattern), '{');
};
/**
* Expand braces in the given glob pattern.

@@ -98,8 +88,13 @@ *

Glob.prototype.braces = function() {
if (this.hasBraces() && this.options.nobraces !== true) {
if (this.options.nobraces !== true && this.options.nobrace !== true) {
// naive/fast check for imbalanced characters
var a = this.pattern.match(/[\{\(\[]/g);
var b = this.pattern.match(/[\}\)\]]/g);
// if imbalanced, don't optimize the pattern
if (a && b && (a.length !== b.length)) {
this.options.makeRe = false;
}
// expand brace patterns and join the resulting array
var expanded = braces(this.pattern, this.options);

@@ -111,11 +106,9 @@ this.pattern = expanded.join('|');

/**
* Return true if the glob pattern has a POSIX
* bracket expression (character class)
*
* @param {String} `pattern`
* @return {Boolean}
* Expand bracket expressions in `glob.pattern`
*/
Glob.prototype.hasBrackets = function(pattern) {
return this.has((pattern || this.pattern), '[:');
Glob.prototype.brackets = function() {
if (this.options.nobrackets !== true) {
this.pattern = brackets(this.pattern);
}
};

@@ -127,5 +120,5 @@

Glob.prototype.brackets = function() {
if (this.hasBrackets() && this.options.nobrackets !== true) {
this.pattern = brackets(this.pattern);
Glob.prototype.extglob = function() {
if (this.options.noextglob !== true) {
this.pattern = extglob(this.pattern, {escape: true});
}

@@ -206,6 +199,7 @@ };

});
this.pattern = unesc(this.pattern);
};
/**
* Escape utils
* Escape/unescape utils
*/

@@ -218,1 +212,7 @@

}
function unesc(str) {
str = str.split('%~').join('?');
str = str.split('%%').join('*');
return str;
}

@@ -6,6 +6,10 @@ 'use strict';

var win32 = process && process.platform === 'win32';
var win;
var utils = {};
/**
* Expose `utils`
*/
var utils = module.exports;
utils.filename = function filename(fp) {

@@ -56,3 +60,4 @@ var seg = fp.match(fileRe());

/**
* Convert a file path to a unix path.
* Normalize all slashes in a file path or glob pattern to
* forward slashes.
*/

@@ -65,2 +70,5 @@

}
if (opts && opts.unescape === true) {
return fp ? fp.toString().replace(/\\(\w)/g, '$1') : '';
}
return fp;

@@ -84,7 +92,1 @@ };

};
/**
* Expose `utils`
*/
module.exports = utils;
{
"name": "micromatch",
"description": "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just use `micromatch.isMatch()` instead of `minimatch()`, or use `micromatch()` instead of `multimatch()`.",
"version": "2.1.6",
"version": "2.2.0",
"homepage": "https://github.com/jonschlinkert/micromatch",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"repository": {
"type": "git",
"url": "https://github.com/jonschlinkert/micromatch.git"
},
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"repository": "jonschlinkert/micromatch",
"bugs": {
"url": "https://github.com/jonschlinkert/micromatch/issues"
},
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/micromatch/blob/master/LICENSE"
},
"license": "MIT",
"files": [

@@ -35,22 +26,23 @@ "index.js",

"arr-diff": "^1.0.1",
"array-unique": "^0.2.1",
"braces": "^1.8.0",
"debug": "^2.1.3",
"expand-brackets": "^0.1.1",
"extglob": "^0.3.0",
"filename-regex": "^2.0.0",
"is-glob": "^1.1.3",
"kind-of": "^1.1.0",
"object.omit": "^0.2.1",
"parse-glob": "^3.0.0",
"regex-cache": "^0.4.0"
"object.omit": "^1.1.0",
"parse-glob": "^3.0.1",
"regex-cache": "^0.4.2"
},
"devDependencies": {
"benchmarked": "^0.1.3",
"browserify": "^9.0.3",
"benchmarked": "^0.1.4",
"browserify": "^9.0.8",
"chalk": "^1.0.0",
"minimatch": "^2.0.1",
"minimist": "^1.1.0",
"mocha": "^2.1.0",
"minimatch": "^2.0.4",
"minimist": "^1.1.1",
"mocha": "^2.2.4",
"multimatch": "^2.0.0",
"should": "^5.0.1",
"write": "^0.1.1"
"should": "^6.0.1",
"write": "^0.2.0"
},

@@ -90,4 +82,24 @@ "keywords": [

]
}
},
"related": {
"list": [
"braces",
"extglob",
"expand-brackets",
"fill-range",
"expand-range",
"gulp-micromatch",
"parse-glob",
"is-glob"
]
},
"reflinks": [
"braces",
"expand-brackets",
"extglob",
"minimatch",
"multimatch",
"verb"
]
}
}

@@ -1,36 +0,82 @@

# micromatch [![NPM version](https://badge.fury.io/js/micromatch.svg)](http://badge.fury.io/js/micromatch) [![Build Status](https://travis-ci.org/jonschlinkert/micromatch.svg)](https://travis-ci.org/jonschlinkert/micromatch)
# micromatch [![NPM version](https://badge.fury.io/js/micromatch.svg)](http://badge.fury.io/js/micromatch) [![Build Status](https://travis-ci.org/jonschlinkert/micromatch.svg)](https://travis-ci.org/jonschlinkert/micromatch)
> Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. Just use `micromatch.isMatch()` instead of `minimatch()`, or use `micromatch()` instead of `multimatch()`.
## Features
## Install
Micromatch is [10-55x faster](#benchmarks) than [minimatch], resulting from a combination of caching, tokenization, parsing, runtime compilation and regex optimization strategies.
Install with [npm](https://www.npmjs.com/)
- [Drop-in replacement][switch] for [minimatch] and [multimatch]
- Built-in support for multiple glob patterns, like `['foo/*.js', '!bar.js']`
- Better support for the Bash 4.3 specification, and less buggy
- Extensive [unit tests](./test) (approx. 1,300 tests). Minimatch fails many of the tests.
```sh
$ npm i micromatch --save
```
**Supports**
## Table of contents
Mainstream glob features:
<!-- toc -->
+ [Brace Expansion][braces] (`foo/bar-{1..5}.md`, `one/{two,three}/four.md`)
+ Typical glob patterns, like `**/*`, `a/b/*.js`, or `['foo/*.js', '!bar.js']`
* [Features](#features)
* [Usage](#usage)
* [Switch from minimatch](#switch-from-minimatch)
* [Methods](#methods)
- [.isMatch](#ismatch)
- [.contains](#contains)
- [.matcher](#matcher)
- [.filter](#filter)
- [.any](#any)
- [.expand](#expand)
- [.makeRe](#makere)
* [Options](#options)
- [options.unixify](#optionsunixify)
- [options.dot](#optionsdot)
- [options.unescape](#optionsunescape)
- [options.nodupes](#optionsnodupes)
- [options.matchBase](#optionsmatchbase)
- [options.nobraces](#optionsnobraces)
- [options.nobrackets](#optionsnobrackets)
- [options.noextglob](#optionsnoextglob)
- [options.nocase](#optionsnocase)
- [options.nonull](#optionsnonull)
- [options.cache](#optionscache)
* [Other features](#other-features)
- [Extended globbing](#extended-globbing)
+ [extglobs](#extglobs)
+ [brace expansion](#brace-expansion)
+ [regex character classes](#regex-character-classes)
+ [regex groups](#regex-groups)
+ [POSIX bracket expressions](#posix-bracket-expressions)
* [Notes](#notes)
* [Benchmarks](#benchmarks)
* [Run tests](#run-tests)
* [Contributing](#contributing)
* [Related](#related)
* [Author](#author)
* [License](#license)
Extended globbing features:
_(Table of contents generated by [verb](https://github.com/assemble/verb))_
+ Logical `OR` (`foo/bar/(abc|xyz).js`)
+ Regex character classes (`foo/bar/baz-[1-5].js`)
+ POSIX bracket expressions (`**/[[:alpha:][:digit:]]/`)
+ extglobs (`**/+(x|y)`, `!(a|b)`, etc)
<!-- tocstop -->
You can combine these to create whatever matching patterns you need.
## Features
## Install with [npm](npmjs.org)
Micromatch is [10-55x faster](#benchmarks) than [minimatch](https://github.com/isaacs/minimatch#readme), resulting from a combination of caching, tokenization, parsing, runtime compilation and regex optimization strategies.
```bash
npm i micromatch --save
```
* [Drop-in replacement](#switch-from-minimatch) for [minimatch](https://github.com/isaacs/minimatch#readme) and [multimatch](https://github.com/sindresorhus/multimatch)
* Built-in support for multiple glob patterns, like `['foo/*.js', '!bar.js']`
* Better support for the Bash 4.3 specification, and less buggy
* Extensive [unit tests](./test) (approx. 1,300 tests). Minimatch fails many of the tests.
**Mainstream glob features:**
* [Brace Expansion](https://github.com/jonschlinkert/braces) (`foo/bar-{1..5}.md`, `one/{two,three}/four.md`)
* Typical glob patterns, like `**/*`, `a/b/*.js`, or `['foo/*.js', '!bar.js']`
**Extended globbing features:**
* Logical `OR` (`foo/bar/(abc|xyz).js`)
* Regex character classes (`foo/bar/baz-[1-5].js`)
* POSIX [bracket expressions](https://github.com/jonschlinkert/expand-brackets) (`**/[[:alpha:][:digit:]]/`)
* [extglobs](https://github.com/jonschlinkert/extglob) (`**/+(x|y)`, `!(a|b)`, etc)
You can combine these to create whatever matching patterns you need.
## Usage

@@ -61,2 +107,7 @@

Behavior;
* when the pattern is a string, [minimatch](https://github.com/isaacs/minimatch#readme) behavior is used, so patterns are **inclusive by default**.
* when an array of patterns is passed, [multimatch](https://github.com/sindresorhus/multimatch) behavior is used, so patterns are **exclusive by default**
```js

@@ -86,5 +137,4 @@ mm(['a.js', 'b.md', 'c.txt'], '!*.{js,txt}');

Use `.isMatch()` to get the same result:
With micromatch, `.isMatch()` to get the same result:
```js

@@ -96,5 +146,4 @@ var mm = require('micromatch');

This implementation difference is necessary since the main `micromatch()` method supports matching on multiple globs, with behavior similar to [multimatch].
This implementation difference is necessary since the main `micromatch()` method supports matching on multiple globs, with behavior similar to [multimatch](https://github.com/sindresorhus/multimatch).
## Methods

@@ -114,3 +163,2 @@

**Example**

@@ -150,5 +198,5 @@

- `glob/string`
- `regex`
- `function`
* `glob/string`
* `regex`
* `function`

@@ -170,7 +218,7 @@ **Example**

Returns a function that can be passed to `Array#filter()`.
Returns a function that can be passed to `Array#filter()`.
**Params**
- `patterns` **{String|Array}**:
* `patterns` **{String|Array}**:

@@ -201,5 +249,4 @@ **Examples**

_(Internally this function generates the matching function by using the [matcher] method. You can use the [matcher] method directly to create your own filter function)_
_(Internally this function generates the matching function by using the [matcher](#matcher) method. You can use the [matcher](#matcher) method directly to create your own filter function)_
### .any

@@ -215,7 +262,6 @@

- filepath `{String}`: The file path to test.
- patterns `{String|Array}`: One or more glob patterns
- options: `{Object}`: options to pass to the `.matcher()` method.
* filepath `{String}`: The file path to test.
* patterns `{String|Array}`: One or more glob patterns
* options: `{Object}`: options to pass to the `.matcher()` method.
**Example**

@@ -234,3 +280,2 @@

### .expand

@@ -279,7 +324,13 @@

All options should work the same way as [minimatch].
### options.unixify
Normalize slashes in file paths and glob patterns to forward slashes.
Type: `{Boolean}`
Default: `undefined` on non-windows, `true` on windows.
### options.dot
Match dotfiles.
Match dotfiles. Same behavior as [minimatch](https://github.com/isaacs/minimatch#readme).

@@ -290,6 +341,40 @@ Type: `{Boolean}`

### options.unescape
Unescape slashes in glob patterns. Use cautiously, especially on windows.
Type: `{Boolean}`
Default: `undefined`
**Example**
```js
mm.isMatch('abc', '\\a\\b\\c', {unescape: true});
//=> true
```
### options.nodupes
Remove duplicate elements from the result array.
Type: `{Boolean}`
Default: `undefined`
**Example**
Example of using the `unescape` and `nodupes` options together:
```js
mm.match(['abc', '\\a\\b\\c'], '\\a\\b\\c', {unescape: true});
//=> ['abc', 'abc']
mm.match(['abc', '\\a\\b\\c'], '\\a\\b\\c', {unescape: true, nodupes: true});
//=> ['abc']
```
### options.matchBase
Allow glob patterns without slashes to match a file path based on its basename.
Allow glob patterns without slashes to match a file path based on its basename. . Same behavior as [minimatch](https://github.com/isaacs/minimatch#readme).

@@ -312,12 +397,33 @@ Type: `{Boolean}`

Don't expand braces in glob patterns.
Don't expand braces in glob patterns. Same behavior as [minimatch](https://github.com/isaacs/minimatch#readme) `nobrace`.
Type: `{Boolean}`
Default: `false`
Default: `undefined`
See [braces](https://github.com/jonschlinkert/braces) for more information about extended brace expansion.
### options.nobrackets
Don't expand POSIX bracket expressions.
Type: `{Boolean}`
Default: `undefined`
See [expand-brackets](https://github.com/jonschlinkert/expand-brackets) for more information about extended bracket expressions.
### options.noextglob
Don't expand extended globs.
Type: `{Boolean}`
Default: `undefined`
See [extglob](https://github.com/jonschlinkert/extglob) for more information about extended globs.
### options.nocase
Use a case-insensitive regex for matching files.
Use a case-insensitive regex for matching files. Same behavior as [minimatch](https://github.com/isaacs/minimatch#readme).

@@ -328,6 +434,5 @@ Type: `{Boolean}`

### options.nonull
If `true`, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty array.
If `true`, when no matches are found the actual (array-ified) glob pattern is returned instead of an empty array. Same behavior as [minimatch](https://github.com/isaacs/minimatch#readme).

@@ -338,6 +443,5 @@ Type: `{Boolean}`

### options.cache
Cache the platform (e.g. `win32`) to prevent this from being looked up for every fil.
Cache the platform (e.g. `win32`) to prevent this from being looked up for every filepath.

@@ -348,3 +452,2 @@ Type: `{Boolean}`

## Other features

@@ -356,4 +459,6 @@

Extended globbing as described by the bash man page:
#### extglobs
Extended globbing, as described by the bash man page:
| **pattern** | **regex equivalent** | **description** |

@@ -369,5 +474,8 @@ | --- | --- | --- |

Powered by [extglob](https://github.com/jonschlinkert/extglob). Visit that library for the full range of options or to report extglob related issues.
### Brace Expansion
See [extglob](https://github.com/jonschlinkert/extglob) for more information about extended globs.
#### brace expansion
In simple cases, brace expansion appears to work the same way as the logical `OR` operator. For example, `(a|b)` will achieve the same result as `{a,b}`.

@@ -377,11 +485,9 @@

- range expansion: `a{1..3}b/*.js` expands to: `['a1b/*.js', 'a2b/*.js', 'a3b/*.js']`
- nesting: `a{c,{d,e}}b/*.js` expands to: `['acb/*.js', 'adb/*.js', 'aeb/*.js']`
* range expansion: `a{1..3}b/*.js` expands to: `['a1b/*.js', 'a2b/*.js', 'a3b/*.js']`
* nesting: `a{c,{d,e}}b/*.js` expands to: `['acb/*.js', 'adb/*.js', 'aeb/*.js']`
Visit [braces](https://github.com/jonschlinkert/braces) to ask questions and create an issue related to brace-expansion, or to see the full range of features and options related to brace expansion.
Learn about [brace expansion][braces], or visit [braces][braces] to ask questions and create an issue related to brace-expansion, or to see the full range of features and options related to brace expansion.
#### regex character classes
### Regex character classes
With the exception of brace expansion (`{a,b}`, `{1..5}`, etc), most of the special characters convert directly to regex, so you can expect them to follow the same rules and produce the same results as regex.

@@ -391,19 +497,30 @@

- `[ac].js`: matches both `a` and `c`, returning `['a.js', 'c.js']`
- `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`
- `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`
- `a/[A-Z].js`: matches and uppercase letter, returning `['a/E.md']`
* `[ac].js`: matches both `a` and `c`, returning `['a.js', 'c.js']`
* `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`
* `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`
* `a/[A-Z].js`: matches and uppercase letter, returning `['a/E.md']`
Learn about [regex character classes][character-classes].
Learn about [regex character classes](http://www.regular-expressions.info/charclass.html).
### Regex groups
#### regex groups
Given `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:
- `(a|c).js`: would match either `a` or `c`, returning `['a.js', 'c.js']`
- `(b|d).js`: would match either `b` or `d`, returning `['b.js', 'd.js']`
- `(b|[A-Z]).js`: would match either `b` or an uppercase letter, returning `['b.js', 'E.js']`
* `(a|c).js`: would match either `a` or `c`, returning `['a.js', 'c.js']`
* `(b|d).js`: would match either `b` or `d`, returning `['b.js', 'd.js']`
* `(b|[A-Z]).js`: would match either `b` or an uppercase letter, returning `['b.js', 'E.js']`
As with regex, parenthese can be nested, so patterns like `((a|b)|c)/b` will work. But it might be easier to achieve your goal using brace expansion.
#### POSIX bracket expressions
**Example**
```js
mm.isMatch('a1', '[[:alpha:][:digit:]]');
//=> true
```
See [expand-brackets](https://github.com/jonschlinkert/expand-brackets) for more information about extended bracket expressions.
## Notes

@@ -413,3 +530,2 @@

## Benchmarks

@@ -420,106 +536,102 @@

```bash
npm run benchmark
node benchmark
```
As of March 27, 2015:
As of July 24, 2015:
```bash
#1: basename-braces
micromatch x 27,734 ops/sec ±0.75% (93 runs sampled)
minimatch x 3,409 ops/sec ±0.77% (97 runs sampled)
micromatch x 28,335 ops/sec ±0.49% (96 runs sampled)
minimatch x 3,496 ops/sec ±0.76% (98 runs sampled)
#2: basename
micromatch x 26,727 ops/sec ±0.81% (97 runs sampled)
minimatch x 4,122 ops/sec ±0.77% (97 runs sampled)
micromatch x 28,602 ops/sec ±0.46% (96 runs sampled)
minimatch x 4,389 ops/sec ±0.38% (98 runs sampled)
#3: braces-no-glob
micromatch x 324,367 ops/sec ±0.62% (95 runs sampled)
minimatch x 29,682 ops/sec ±0.71% (94 runs sampled)
micromatch x 405,445 ops/sec ±0.64% (91 runs sampled)
minimatch x 31,078 ops/sec ±0.45% (95 runs sampled)
#4: braces
micromatch x 63,430 ops/sec ±1.14% (95 runs sampled)
minimatch x 2,749 ops/sec ±0.77% (97 runs sampled)
micromatch x 81,977 ops/sec ±0.36% (99 runs sampled)
minimatch x 2,986 ops/sec ±0.41% (100 runs sampled)
#5: immediate
micromatch x 21,842 ops/sec ±0.66% (98 runs sampled)
minimatch x 3,638 ops/sec ±0.66% (97 runs sampled)
micromatch x 20,753 ops/sec ±0.36% (101 runs sampled)
minimatch x 4,233 ops/sec ±0.34% (100 runs sampled)
#6: large
micromatch x 802 ops/sec ±0.58% (96 runs sampled)
minimatch x 15.72 ops/sec ±1.25% (42 runs sampled)
micromatch x 755 ops/sec ±0.53% (97 runs sampled)
minimatch x 17.06 ops/sec ±0.25% (46 runs sampled)
#7: long
micromatch x 8,061 ops/sec ±0.69% (96 runs sampled)
minimatch x 560 ops/sec ±0.71% (90 runs sampled)
micromatch x 7,009 ops/sec ±0.33% (100 runs sampled)
minimatch x 592 ops/sec ±0.39% (96 runs sampled)
#8: mid
micromatch x 67,972 ops/sec ±0.78% (93 runs sampled)
minimatch x 1,745 ops/sec ±0.87% (96 runs sampled)
micromatch x 60,071 ops/sec ±0.48% (97 runs sampled)
minimatch x 1,853 ops/sec ±0.72% (99 runs sampled)
#9: multi-patterns
micromatch x 25,136 ops/sec ±0.87% (95 runs sampled)
minimatch x 1,986 ops/sec ±1.03% (95 runs sampled)
micromatch x 24,308 ops/sec ±0.67% (98 runs sampled)
minimatch x 2,169 ops/sec ±0.62% (96 runs sampled)
#10: no-glob
micromatch x 1,062,274 ops/sec ±0.90% (94 runs sampled)
minimatch x 53,150 ops/sec ±0.85% (96 runs sampled)
micromatch x 552,116 ops/sec ±0.35% (96 runs sampled)
minimatch x 55,957 ops/sec ±0.32% (94 runs sampled)
#11: range
micromatch x 270,918 ops/sec ±0.75% (97 runs sampled)
minimatch x 13,548 ops/sec ±0.85% (96 runs sampled)
micromatch x 321,030 ops/sec ±0.62% (95 runs sampled)
minimatch x 14,247 ops/sec ±0.59% (100 runs sampled)
#12: shallow
micromatch x 198,022 ops/sec ±0.80% (97 runs sampled)
minimatch x 20,093 ops/sec ±0.62% (95 runs sampled)
micromatch x 253,455 ops/sec ±0.52% (99 runs sampled)
minimatch x 21,169 ops/sec ±0.54% (97 runs sampled)
#13: short
micromatch x 440,230 ops/sec ±0.84% (97 runs sampled)
minimatch x 58,116 ops/sec ±0.74% (92 runs sampled)
micromatch x 661,874 ops/sec ±0.42% (96 runs sampled)
minimatch x 60,228 ops/sec ±0.45% (97 runs sampled)
```
## Run tests
Install dev dependencies:
```bash
npm i -d && npm test
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/micromatch/issues)
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/micromatch/issues/new)
Please be sure to run the benchmarks before/after any code changes to judge the impact before you do a PR. thanks!
## Related
* [braces](https://github.com/jonschlinkert/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces specification.
* [fill-range](https://github.com/jonschlinkert/fill-range): Fill in a range of numbers or letters, optionally passing an increment or multiplier to use.
* [expand-range](https://github.com/jonschlinkert/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks. Used by micromatch.
* [parse-glob](https://github.com/jonschlinkert/parse-glob): Parse a glob pattern into an object of tokens.
* [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a glob pattern.
## Related
* [braces](https://github.com/jonschlinkert/braces): Fastest brace expansion for node.js, with the most complete… [more](https://github.com/jonschlinkert/braces)
* [extglob](https://github.com/jonschlinkert/extglob): Convert extended globs to regex-compatible strings. Add (almost) the… [more](https://github.com/jonschlinkert/extglob)
* [expand-brackets](https://github.com/jonschlinkert/expand-brackets): Expand POSIX bracket expressions (character classes) in glob patterns.
* [expand-range](https://github.com/jonschlinkert/expand-range): Fast, bash-like range expansion. Expand a range of numbers… [more](https://github.com/jonschlinkert/expand-range)
* [fill-range](https://github.com/jonschlinkert/fill-range): Fill in a range of numbers or letters, optionally… [more](https://github.com/jonschlinkert/fill-range)
* [gulp-micromatch](https://github.com/tunnckoCore/gulp-micromatch#readme): micromatch as gulp plugin. Filtering vinyl files with glob… [more](https://github.com/tunnckoCore/gulp-micromatch#readme)
* [is-glob](https://github.com/jonschlinkert/is-glob): Returns `true` if the given string looks like a… [more](https://github.com/jonschlinkert/is-glob)
* [parse-glob](https://github.com/jonschlinkert/parse-glob): Parse a glob pattern into an object of tokens.
## Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2014-2015 Jon Schlinkert
Released under the MIT license
Copyright © 2014-2015 [Jon Schlinkert](https://github.com/jonschlinkert)
Released under the MIT license.
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 27, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on July 24, 2015._
[switch]: #switch-from-minimatch
[multimatch]: https://github.com/sindresorhus/multimatch
[minimatch]: https://github.com/isaacs/minimatch
[brace expansion]: https://github.com/jonschlinkert/braces
[braces]: https://github.com/jonschlinkert/braces
[bracket expressions]: https://github.com/jonschlinkert/expand-brackets
[character-classes]: http://www.regular-expressions.info/charclass.html
[expand]: https://github.com/jonschlinkert/micromatch#expand
[extended]: http://mywiki.wooledge.org/BashGuide/Patterns#Extended_Globs
[extglobs]: https://github.com/jonschlinkert/extglob
<!-- deps:mocha browserify -->
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc