anymatch
Advanced tools
Comparing version 1.3.0 to 1.3.2
15
index.js
'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]); }; | ||
@@ -18,8 +19,8 @@ var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) { | ||
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]': | ||
@@ -34,2 +35,3 @@ result = string === criterion || altString && altString === criterion; | ||
result = criterion.apply(null, value); | ||
result = result || altValue && criterion.apply(null, altValue); | ||
break; | ||
@@ -58,4 +60,5 @@ default: | ||
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)); | ||
} | ||
@@ -62,0 +65,0 @@ matched = crit.slice(startIndex, endIndex).some(testCriteria); |
{ | ||
"name": "anymatch", | ||
"version": "1.3.0", | ||
"version": "1.3.2", | ||
"description": "Matches strings against configurable strings, globs, regular expressions, and/or functions", | ||
@@ -39,4 +39,4 @@ "files": [ | ||
"dependencies": { | ||
"arrify": "^1.0.0", | ||
"micromatch": "^2.1.5" | ||
"micromatch": "^2.1.5", | ||
"normalize-path": "^2.0.0" | ||
}, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
@@ -41,3 +41,3 @@ 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) | ||
'path/anyjs/**/*.js', | ||
/foo.js$/, | ||
/foo\.js$/, | ||
function (string) { | ||
@@ -62,2 +62,9 @@ return string.indexOf('bar') !== -1 && string.length > 10 | ||
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 | ||
``` | ||
@@ -64,0 +71,0 @@ |
8264
64
99
+ Addednormalize-path@^2.0.0
- Removedarrify@^1.0.0
- Removedarrify@1.0.1(transitive)