Socket
Socket
Sign inDemoInstall

micromatch

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromatch - npm Package Compare versions

Comparing version 1.6.2 to 2.0.0

44

index.js

@@ -121,27 +121,33 @@ /*!

/**
* Filter files with the given pattern.
* Returns a function that takes a glob pattern or array of glob patterns
* to be used with `Array#filter()`. (Internally this function generates
* the matching function using the [matcher] method).
*
* @param {String|Array} `pattern`
* @param {Array} `files`
* @param {Options} `opts`
* @return {Array}
* ```js
* var fn = mm.filter('[a-c]');
* ['a', 'b', 'c', 'd', 'e'].filter(fn);
* //=> ['a', 'b', 'c']
* ```
*
* @param {String|Array} `patterns` Can be a glob or array of globs.
* @param {Options} `opts` Options to pass to the [matcher] method.
* @return {Function} Filter function to be passed to `Array#filter()`.
*/
function filter(pattern, opts) {
if (typeof pattern !== 'string') {
throw new TypeError(msg('filter', 'pattern', 'a string'));
function filter(patterns, opts) {
if (!Array.isArray(patterns) && typeof patterns !== 'string') {
throw new TypeError(msg('filter', 'patterns', 'a string or array'));
}
var fn = matcher(pattern, opts);
return function (files) {
if (!Array.isArray(files)) {
return fn(files);
}
patterns = utils.arrayify(patterns);
return function (fp) {
if (fp == null) return [];
var len = patterns.length, i = 0;
var res = true;
var res = files.slice();
var len = files.length;
while (len--) {
if (!fn(files[len])) {
res.splice(len, 1);
while (i < len) {
var fn = matcher(patterns[i++], opts);
if (!fn(fp)) {
res = false;
break;
}

@@ -148,0 +154,0 @@ }

{
"name": "micromatch",
"description": "Glob matching for javascript/node.js. A faster alternative to minimatch (10-45x faster on avg), with all the features you're used to using in your Grunt and gulp tasks.",
"version": "1.6.2",
"version": "2.0.0",
"homepage": "https://github.com/jonschlinkert/micromatch",

@@ -6,0 +6,0 @@ "author": {

@@ -168,15 +168,35 @@ # 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)

Returns a function for filtering files that match the given pattern.
Returns a function that can be passed to `Array#filter()`.
**Example**
**Params**
Both of the following signatures work:
- `patterns` **{String|Array}**:
**Examples**
Single glob:
```js
var fn = mm.filter('*.md', {dot: true});
['a.js', 'b.txt', 'c.md', '.verb.md'].filter(fn);
//=> ['c.md', '.verb.md']
var fn = mm.filter('*.md');
['a.js', 'b.txt', 'c.md'].filter(fn);
//=> ['c.md']
var fn = mm.filter('[a-c]');
['a', 'b', 'c', 'd', 'e'].filter(fn);
//=> ['a', 'b', 'c']
```
Array of glob patterns:
```js
var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
var fn = mm.filter(['{1..10}', '![7-9]', '!{3..4}']);
arr.filter(fn);
//=> [1, 2, 5, 6, 10]
```
_(Internally this function generates the matching function using the [matcher] method. You can use the [matcher] method directly to create your own filter function)_
### .any

@@ -183,0 +203,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc