3 var arrify = require('arrify');
4 var micromatch = require('micromatch');
5 var path = require('path');
7 var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
8 criteria = arrify(criteria);
10 if (arguments.length === 1) {
11 return anymatch.bind(null, criteria.map(function(criterion) {
12 return typeof criterion === 'string' && criterion[0] !== '!' ?
13 micromatch.matcher(criterion) : criterion;
16 startIndex = startIndex || 0;
17 var string = value[0];
21 function testCriteria (criterion, index) {
23 switch (toString.call(criterion)) {
24 case '[object String]':
25 result = string === criterion || altString && altString === criterion;
26 result = result || micromatch.isMatch(string, criterion);
28 case '[object RegExp]':
29 result = criterion.test(string) || altString && criterion.test(altString);
31 case '[object Function]':
32 result = criterion.apply(null, value);
38 matchIndex = index + startIndex;
43 var negGlobs = crit.reduce(function(arr, criterion, index) {
44 if (typeof criterion === 'string' && criterion[0] === '!') {
45 if (crit === criteria) {
46 // make a copy before modifying
50 arr.push(criterion.substr(1));
54 if (!negGlobs.length || !micromatch.any(string, negGlobs)) {
55 if (path.sep === '\\' && typeof string === 'string') {
56 altString = string.split('\\').join('/');
57 altString = altString === string ? null : altString;
59 matched = crit.slice(startIndex, endIndex).some(testCriteria);
61 return returnIndex === true ? matchIndex : matched;
64 module.exports = anymatch;