JSPM

  • Created
  • Published
  • Downloads 115501759
  • Score
    100M100P100Q239054F
  • License

Glob matching for javascript/node.js. A faster alternative to minimatch (10-20x faster on avg), with all the features you're used to using in your Grunt and gulp tasks.

Package Exports

  • micromatch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (micromatch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

micromatch NPM version

Glob matching for javascript/node.js. A faster and more stable alternative to minimatch (bencharks show micromatch is 10-40x faster on avg).

  • 10-20x faster than minimatch (benchmarks) on average
  • Focus on core Bash 4.3 specification features that are actually used (or can be used) in node.js
  • Supports passing glob patterns as a string or array
  • Extensive unit tests

Features

Supports

All the mainstream glob features you're used to using in your gulp and Grunt tasks:

  • Brace Expansion (foo/bar-{1..5}.md, one/{two,three}/four.md)
  • Globstar matching (**/*, a/b/*.js, etc)
  • Logical OR (foo/bar/(abc|xyz).js)
  • Regex character classes (foo/bar/baz-[1-5].js)

You can combine these features to achieve whatever matching patterns you need.

Does not support

  • Extended glob matching. This might be supported in the future, either in core or as an extension, but it's hard to justify the cost in terms of speed and complexity for features that are rarely used.

Install with npm

npm i micromatch --save

Usage

Works exactly the same as minimatch.

var micromatch = require('micromatch');

micromatch(['a.js', 'b.md', 'c.txt'], '*.{js,txt}');
//=> ['a.js', 'c.txt']

Negation patterns:

micromatch(['a.js', 'b.md', 'c.txt'], '!*.{js,txt}');
//=> ['b.md']

micromatch(['a.md', 'b.js', 'c.txt', 'd.json'], ['*.*', '!*.{js,txt}']);
//=> ['a.md', 'd.json']

Special characters

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.

Square brackets

Given ['a.js', 'b.js', 'c.js', 'd.js', 'E.js']:

  • [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.

Parentheses

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']

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.

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}.

Here are some powerful features unique to brace expansion:

  • range expansion: a{1..3}b/*.js expands to: ['a1b/*.js', 'a2b/*.js', 'a3b/*.js']

Learn about brace expansion, or visit 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.

.matchRe

Generate a regular expression for matching file paths based on the given pattern:

micromatch.makeRe('a/?/c.md');
//=> /^a\/.\/c\.md$/

Benchmarks

Run the benchmarks

node benchmark/

image

Run tests

Install dev dependencies

npm i -d && mocha

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Please be sure to run the benchmarks before/after any code changes to judge the impact before you do a PR. thanks!

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert
Released under the MIT license


This file was generated by verb on December 28, 2014.