Commit 390f1bf3 authored by Utkarsh Gupta's avatar Utkarsh Gupta

New upstream version 2.0.0

parent 5569cfcb
sudo: false
language: node_js
node_js:
- "iojs"
- "0.12"
- "0.11"
- "0.10"
- node
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
anymatch [![Build Status](https://travis-ci.org/es128/anymatch.svg?branch=master)](https://travis-ci.org/es128/anymatch) [![Coverage Status](https://img.shields.io/coveralls/es128/anymatch.svg?branch=master)](https://coveralls.io/r/es128/anymatch?branch=master)
anymatch [![Build Status](https://travis-ci.org/micromatch/anymatch.svg?branch=master)](https://travis-ci.org/micromatch/anymatch) [![Coverage Status](https://img.shields.io/coveralls/micromatch/anymatch.svg?branch=master)](https://coveralls.io/r/micromatch/anymatch?branch=master)
======
Javascript module to match a string against a regular expression, glob, string,
or function that takes the string as an argument and returns a truthy or falsy
value. The matcher can also be an array of any or all of these. Useful for
allowing a very flexible user-defined config to define things like file paths.
__Note: This module has Bash-parity, please be aware that Windows-style backslashes are not supported as separators. See https://github.com/micromatch/micromatch#backslashes for more information.__
[![NPM](https://nodei.co/npm/anymatch.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/anymatch/)
[![NPM](https://nodei.co/npm-dl/anymatch.png?height=3&months=9)](https://nodei.co/npm-dl/anymatch/)
......@@ -38,7 +40,7 @@ var anymatch = require('anymatch');
var matchers = [
'path/to/file.js',
'path/anyjs/**/*.js',
/foo.js$/,
/foo\.js$/,
function (string) {
return string.indexOf('bar') !== -1 && string.length > 10
}
......@@ -58,6 +60,13 @@ anymatch(matchers, 'path/anyjs/foo.js', true); // 1
anymatch(matchers, 'path/to/file.js', false, 1); // false
anymatch(matchers, 'path/anyjs/foo.js', true, 2, 3); // 2
anymatch(matchers, 'path/to/bar.js', true, 0, 3); // -1
// using globs to match directories and their children
anymatch('node_modules', 'node_modules'); // true
anymatch('node_modules', 'node_modules/somelib/index.js'); // false
anymatch('node_modules/**', 'node_modules/somelib/index.js'); // true
anymatch('node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // false
anymatch('**/node_modules/**', '/absolute/path/to/node_modules/somelib/index.js'); // true
```
#### anymatch (matchers)
......@@ -77,15 +86,14 @@ matcher('path/anyjs/baz.js', true, 2); // -1
Change Log
----------
[See release notes page on GitHub](https://github.com/es128/anymatch/releases)
[See release notes page on GitHub](https://github.com/micromatch/anymatch/releases)
NOTE: As of v2.0.0, [micromatch](https://github.com/jonschlinkert/micromatch) moves away from minimatch-parity and inline with Bash. This includes handling backslashes differently (see https://github.com/micromatch/micromatch#backslashes for more information).
NOTE: As of v1.2.0, anymatch uses [micromatch](https://github.com/jonschlinkert/micromatch)
for glob pattern matching. The glob matching behavior should be functionally
equivalent to the commonly used [minimatch](https://github.com/isaacs/minimatch)
library (aside from some fixed bugs and greater performance), so a major
version bump wasn't merited. Issues with glob pattern matching should be
for glob pattern matching. Issues with glob pattern matching should be
reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues).
License
-------
[ISC](https://raw.github.com/es128/anymatch/master/LICENSE)
[ISC](https://raw.github.com/micromatch/anymatch/master/LICENSE)
'use strict';
var arrify = require('arrify');
var micromatch = require('micromatch');
var path = require('path');
var normalize = require('normalize-path');
var path = require('path'); // required for tests.
var arrify = function(a) { return a == null ? [] : (Array.isArray(a) ? a : [a]); };
var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
criteria = arrify(criteria);
......@@ -15,12 +16,12 @@ var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
}
startIndex = startIndex || 0;
var string = value[0];
var altString;
var altString, altValue;
var matched = false;
var matchIndex = -1;
function testCriteria (criterion, index) {
function testCriteria(criterion, index) {
var result;
switch (toString.call(criterion)) {
switch (Object.prototype.toString.call(criterion)) {
case '[object String]':
result = string === criterion || altString && altString === criterion;
result = result || micromatch.isMatch(string, criterion);
......@@ -30,6 +31,7 @@ var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
break;
case '[object Function]':
result = criterion.apply(null, value);
result = result || altValue && criterion.apply(null, altValue);
break;
default:
result = false;
......@@ -53,8 +55,9 @@ var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
}, []);
if (!negGlobs.length || !micromatch.any(string, negGlobs)) {
if (path.sep === '\\' && typeof string === 'string') {
altString = string.split('\\').join('/');
altString = normalize(string);
altString = altString === string ? null : altString;
if (altString) altValue = [altString].concat(value.slice(1));
}
matched = crit.slice(startIndex, endIndex).some(testCriteria);
}
......
{
"name": "anymatch",
"version": "1.3.0",
"version": "2.0.0",
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions",
"files": [
"index.js"
......@@ -10,13 +10,13 @@
"url": "http://github.com/es128"
},
"license": "ISC",
"homepage": "https://github.com/es128/anymatch",
"homepage": "https://github.com/micromatch/anymatch",
"repository": {
"type": "git",
"url": "https://github.com/es128/anymatch"
"url": "https://github.com/micromatch/anymatch"
},
"bugs": {
"url": "https://github.com/es128/anymatch/issues"
"url": "https://github.com/micromatch/anymatch/issues"
},
"keywords": [
"match",
......@@ -36,12 +36,12 @@
"test": "istanbul cover _mocha && cat ./coverage/lcov.info | coveralls"
},
"dependencies": {
"arrify": "^1.0.0",
"micromatch": "^2.1.5"
"micromatch": "^3.1.4",
"normalize-path": "^2.1.1"
},
"devDependencies": {
"coveralls": "^2.11.2",
"istanbul": "^0.3.13",
"mocha": "^2.2.4"
"coveralls": "^2.7.0",
"istanbul": "^0.4.5",
"mocha": "^3.0.0"
}
}
......@@ -10,7 +10,7 @@ describe('anymatch', function() {
'path/anyjs/**/*.js',
/foo.js$/,
function(string) {
return string.indexOf('bar') !== -1 && string.length > 10;
return string.indexOf('/bar') !== -1 && string.length > 10;
}
];
it('should resolve string matchers', function() {
......@@ -176,6 +176,10 @@ describe('anymatch', function() {
assert(anymatch(/path\/to\/file\.js/, 'path\\to\\file.js'));
assert(anymatch(/path\/to\/file\.js/)('path\\to\\file.js'));
});
it('should resolve backslashes against function matchers', function() {
assert(anymatch(matchers, 'path\\to\\bar.js'));
assert(anymatch(matchers)('path\\to\\bar.js'));
});
it('should still correctly handle forward-slash paths', function() {
assert(anymatch(matchers, 'path/to/file.js'));
assert(anymatch(matchers)('path/to/file.js'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment