pax_global_header00006660000000000000000000000064125160154560014517gustar00rootroot0000000000000052 comment=253d2ad42f644ed18557f561312a7f8426daca84 anymatch-1.3.0/000077500000000000000000000000001251601545600133245ustar00rootroot00000000000000anymatch-1.3.0/.gitignore000066400000000000000000000000561251601545600153150ustar00rootroot00000000000000node_modules .DS_Store npm-debug.log coverage anymatch-1.3.0/.travis.yml000066400000000000000000000001071251601545600154330ustar00rootroot00000000000000language: node_js node_js: - "iojs" - "0.12" - "0.11" - "0.10" anymatch-1.3.0/LICENSE000066400000000000000000000013531251601545600143330ustar00rootroot00000000000000The ISC License Copyright (c) 2014 Elan Shanker Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. anymatch-1.3.0/README.md000066400000000000000000000074541251601545600146150ustar00rootroot00000000000000anymatch [![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) ====== 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. [![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/) Usage ----- ```sh npm install anymatch --save ``` #### anymatch (matchers, testString, [returnIndex], [startIndex], [endIndex]) * __matchers__: (_Array|String|RegExp|Function_) String to be directly matched, string with glob patterns, regular expression test, function that takes the testString as an argument and returns a truthy value if it should be matched, or an array of any number and mix of these types. * __testString__: (_String|Array_) The string to test against the matchers. If passed as an array, the first element of the array will be used as the `testString` for non-function matchers, while the entire array will be applied as the arguments for function matchers. * __returnIndex__: (_Boolean [optional]_) If true, return the array index of the first matcher that that testString matched, or -1 if no match, instead of a boolean result. * __startIndex, endIndex__: (_Integer [optional]_) Can be used to define a subset out of the array of provided matchers to test against. Can be useful with bound matcher functions (see below). When used with `returnIndex = true` preserves original indexing. Behaves the same as `Array.prototype.slice` (i.e. includes array members up to, but not including endIndex). ```js var anymatch = require('anymatch'); var matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, function (string) { return string.indexOf('bar') !== -1 && string.length > 10 } ]; anymatch(matchers, 'path/to/file.js'); // true anymatch(matchers, 'path/anyjs/baz.js'); // true anymatch(matchers, 'path/to/foo.js'); // true anymatch(matchers, 'path/to/bar.js'); // true anymatch(matchers, 'bar.js'); // false // returnIndex = true anymatch(matchers, 'foo.js', true); // 2 anymatch(matchers, 'path/anyjs/foo.js', true); // 1 // skip matchers 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 ``` #### anymatch (matchers) You can also pass in only your matcher(s) to get a curried function that has already been bound to the provided matching criteria. This can be used as an `Array.prototype.filter` callback. ```js var matcher = anymatch(matchers); matcher('path/to/file.js'); // true matcher('path/anyjs/baz.js', true); // 1 matcher('path/anyjs/baz.js', true, 2); // -1 ['foo.js', 'bar.js'].filter(matcher); // ['foo.js'] ``` Change Log ---------- [See release notes page on GitHub](https://github.com/es128/anymatch/releases) 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 reported directly to the [micromatch issue tracker](https://github.com/jonschlinkert/micromatch/issues). License ------- [ISC](https://raw.github.com/es128/anymatch/master/LICENSE) anymatch-1.3.0/index.js000066400000000000000000000036561251601545600150030ustar00rootroot00000000000000'use strict'; var arrify = require('arrify'); var micromatch = require('micromatch'); var path = require('path'); var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) { criteria = arrify(criteria); value = arrify(value); if (arguments.length === 1) { return anymatch.bind(null, criteria.map(function(criterion) { return typeof criterion === 'string' && criterion[0] !== '!' ? micromatch.matcher(criterion) : criterion; })); } startIndex = startIndex || 0; var string = value[0]; var altString; var matched = false; var matchIndex = -1; function testCriteria (criterion, index) { var result; switch (toString.call(criterion)) { case '[object String]': result = string === criterion || altString && altString === criterion; result = result || micromatch.isMatch(string, criterion); break; case '[object RegExp]': result = criterion.test(string) || altString && criterion.test(altString); break; case '[object Function]': result = criterion.apply(null, value); break; default: result = false; } if (result) { matchIndex = index + startIndex; } return result; } var crit = criteria; var negGlobs = crit.reduce(function(arr, criterion, index) { if (typeof criterion === 'string' && criterion[0] === '!') { if (crit === criteria) { // make a copy before modifying crit = crit.slice(); } crit[index] = null; arr.push(criterion.substr(1)); } return arr; }, []); if (!negGlobs.length || !micromatch.any(string, negGlobs)) { if (path.sep === '\\' && typeof string === 'string') { altString = string.split('\\').join('/'); altString = altString === string ? null : altString; } matched = crit.slice(startIndex, endIndex).some(testCriteria); } return returnIndex === true ? matchIndex : matched; }; module.exports = anymatch; anymatch-1.3.0/package.json000066400000000000000000000017031251601545600156130ustar00rootroot00000000000000{ "name": "anymatch", "version": "1.3.0", "description": "Matches strings against configurable strings, globs, regular expressions, and/or functions", "files": [ "index.js" ], "author": { "name": "Elan Shanker", "url": "http://github.com/es128" }, "license": "ISC", "homepage": "https://github.com/es128/anymatch", "repository": { "type": "git", "url": "https://github.com/es128/anymatch" }, "bugs": { "url": "https://github.com/es128/anymatch/issues" }, "keywords": [ "match", "any", "string", "file", "fs", "list", "glob", "regex", "regexp", "regular", "expression", "function" ], "scripts": { "test": "istanbul cover _mocha && cat ./coverage/lcov.info | coveralls" }, "dependencies": { "arrify": "^1.0.0", "micromatch": "^2.1.5" }, "devDependencies": { "coveralls": "^2.11.2", "istanbul": "^0.3.13", "mocha": "^2.2.4" } } anymatch-1.3.0/readme-examples.js000066400000000000000000000044371251601545600167430ustar00rootroot00000000000000var inspect = require('util').inspect; var i = function (val) {return inspect(val, {colors: true})}; var anymatch = require('./'); console.log("var anymatch = require('anymatch');\n"); var matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, function (string) { return string.indexOf('bar') !== -1 && string.length > 10; } ]; console.log('var matchers =', i(matchers).replace('[Function]', matchers[3].toString() + '\n'), ';\n'); console.log("anymatch(matchers, 'path/to/file.js');", " =>", i(anymatch(matchers, 'path/to/file.js') )); // true console.log("anymatch(matchers, 'path/anyjs/baz.js');", " =>", i(anymatch(matchers, 'path/anyjs/baz.js') )); // true console.log("anymatch(matchers, 'path/to/foo.js');", " =>", i(anymatch(matchers, 'path/to/foo.js') )); // true console.log("anymatch(matchers, 'path/to/bar.js');", " =>", i(anymatch(matchers, 'path/to/bar.js') )); // true console.log("anymatch(matchers, 'bar.js');", " =>", i(anymatch(matchers, 'bar.js') )); // false // returnIndex = true console.log( '\n// returnIndex = true' ); console.log("anymatch(matchers, 'foo.js', true);", " =>", i(anymatch(matchers, 'foo.js', true) )); // 2 console.log("anymatch(matchers, 'path/anyjs/foo.js', true);", " =>", i(anymatch(matchers, 'path/anyjs/foo.js', true) )); // 1 // skip matchers console.log( '\n// skip matchers' ); console.log("anymatch(matchers, 'path/to/file.js', false, 1);", " =>", i(anymatch(matchers, 'path/to/file.js', false, 1) )); // false console.log("anymatch(matchers, 'path/anyjs/foo.js', true, 2, 3);", " =>", i(anymatch(matchers, 'path/anyjs/foo.js', true, 2, 3) )); // 2 console.log("anymatch(matchers, 'path/to/bar.js', true, 0, 3);", " =>", i(anymatch(matchers, 'path/to/bar.js', true, 0, 3) )); // -1 var matcher = anymatch(matchers); console.log( '\nvar matcher = anymatch(matchers);' ); console.log("matcher('path/to/file.js');", " =>", i(matcher('path/to/file.js') )); // true console.log("matcher('path/anyjs/baz.js', true);", " =>", i(matcher('path/anyjs/baz.js', true) )); // 1 console.log("matcher('path/anyjs/baz.js', true, 2);", " =>", i(matcher('path/anyjs/baz.js', true, 2) )); // -1 console.log("['foo.js', 'bar.js'].filter(matcher);", " =>", i(['foo.js', 'bar.js'].filter(matcher) )); // ['foo.js'] anymatch-1.3.0/test.js000066400000000000000000000165161251601545600146520ustar00rootroot00000000000000'use strict'; var anymatch = require('./'); var assert = require('assert'); var path = require('path'); describe('anymatch', function() { var matchers = [ 'path/to/file.js', 'path/anyjs/**/*.js', /foo.js$/, function(string) { return string.indexOf('bar') !== -1 && string.length > 10; } ]; it('should resolve string matchers', function() { assert.equal(true, anymatch(matchers, 'path/to/file.js')); assert.equal(true, anymatch(matchers[0], 'path/to/file.js')); assert.equal(false, anymatch(matchers[0], 'bar.js')); }); it('should resolve glob matchers', function() { assert.equal(true, anymatch(matchers, 'path/anyjs/baz.js')); assert.equal(true, anymatch(matchers[1], 'path/anyjs/baz.js')); assert.equal(false, anymatch(matchers[1], 'bar.js')); }); it('should resolve regexp matchers', function() { assert.equal(true, anymatch(matchers, 'path/to/foo.js')); assert.equal(true, anymatch(matchers[2], 'path/to/foo.js')); assert.equal(false, anymatch(matchers[2], 'bar.js')); }); it('should resolve function matchers', function() { assert.equal(true, anymatch(matchers, 'path/to/bar.js')); assert.equal(true, anymatch(matchers[3], 'path/to/bar.js')); assert.equal(false, anymatch(matchers[3], 'bar.js')); }); it('should return false for unmatched strings', function() { assert.equal(false, anymatch(matchers, 'bar.js')); }); it('should ignore improperly typed matchers', function() { var emptyObj = {}; assert.equal(false, anymatch(emptyObj, emptyObj)); assert.equal(false, anymatch(Infinity, Infinity)); }); describe('with returnIndex = true', function() { it('should return the array index of first positive matcher', function() { var result = anymatch(matchers, 'foo.js', true); assert.equal(result, 2); }); it('should return 0 if provided non-array matcher', function() { var result = anymatch(matchers[2], 'foo.js', true); assert.equal(result, 0); }); it('should return -1 if no match', function() { var result = anymatch(matchers, 'bar.js', true); assert.equal(result, -1); }); }); describe('curried matching function', function() { var matchFn = anymatch(matchers); it('should resolve matchers', function() { assert.equal(true, matchFn('path/to/file.js')); assert.equal(true, matchFn('path/anyjs/baz.js')); assert.equal(true, matchFn('path/to/foo.js')); assert.equal(true, matchFn('path/to/bar.js')); assert.equal(false, matchFn('bar.js')); }); it('should be usable as an Array.prototype.filter callback', function() { var arr = [ 'path/to/file.js', 'path/anyjs/baz.js', 'path/to/foo.js', 'path/to/bar.js', 'bar.js', 'foo.js' ]; var expected = arr.slice(); expected.splice(arr.indexOf('bar.js'), 1); assert.deepEqual(arr.filter(matchFn), expected); }); it('should bind individual criterion', function() { assert(anymatch(matchers[0])('path/to/file.js')); assert(!anymatch(matchers[0])('path/to/other.js')); assert(anymatch(matchers[1])('path/anyjs/baz.js')); assert(!anymatch(matchers[1])('path/to/baz.js')); assert(anymatch(matchers[2])('path/to/foo.js')); assert(!anymatch(matchers[2])('path/to/foo.js.bak')); assert(anymatch(matchers[3])('path/to/bar.js')); assert(!anymatch(matchers[3])('bar.js')); }); }); describe('using matcher subsets', function() { it('should skip matchers before the startIndex', function() { assert(anymatch(matchers, 'path/to/file.js', false)); assert(!anymatch(matchers, 'path/to/file.js', false, 1)); }); it('should skip matchers after and including the endIndex', function() { assert(anymatch(matchers, 'path/to/bars.js', false)); assert(!anymatch(matchers, 'path/to/bars.js', false, 0, 3)); assert(!anymatch(matchers, 'foo.js', false, 0, 1)); }); }); describe('extra args', function() { it('should allow string to be passed as first member of an array', function() { assert(anymatch(matchers, ['path/to/bar.js'])); }); it('should pass extra args to function matchers', function() { matchers.push(function(string, arg1, arg2) { return arg1 || arg2; }); assert(!anymatch(matchers, 'bar.js'), 1); assert(!anymatch(matchers, ['bar.js', 0]), 2); assert(anymatch(matchers, ['bar.js', true]), 3); assert(anymatch(matchers, ['bar.js', 0, true]), 4); // with returnIndex assert.equal(anymatch(matchers, ['bar.js', 1], true), 4, 5); // curried versions var matchFn1 = anymatch(matchers); var matchFn2 = anymatch(matchers[4]); assert(!matchFn1(['bar.js', 0]), 6); assert(!matchFn2(['bar.js', 0]), 7); assert(matchFn1(['bar.js', true]), 8); assert(matchFn2(['bar.js', true]), 9); assert(matchFn1(['bar.js', 0, true]), 10); assert(matchFn2(['bar.js', 0, true]), 11); // curried with returnIndex assert.equal(matchFn1(['bar.js', 1], true), 4, 12); assert.equal(matchFn2(['bar.js', 1], true), 0, 13); assert.equal(matchFn1(['bar.js', 0], true), -1, 14); assert.equal(matchFn2(['bar.js', 0], true), -1, 15); matchers.pop(); }); }); describe('glob negation', function() { after(matchers.splice.bind(matchers, 4, 2)); it('should respect negated globs included in a matcher array', function() { assert(anymatch(matchers, 'path/anyjs/no/no.js'), 'matches existing glob'); matchers.push('!path/anyjs/no/*.js'); assert(!anymatch(matchers, 'path/anyjs/no/no.js'), 'should be negated'); assert(!anymatch(matchers)('path/anyjs/no/no.js'), 'should be negated (curried)'); }); it('should not break returnIndex option', function() { assert.equal(anymatch(matchers, 'path/anyjs/yes.js', true), 1); assert.equal(anymatch(matchers)('path/anyjs/yes.js', true), 1); assert.equal(anymatch(matchers, 'path/anyjs/no/no.js', true), -1); assert.equal(anymatch(matchers)('path/anyjs/no/no.js', true), -1); }); it('should allow negated globs to negate non-glob matchers', function() { assert.equal(anymatch(matchers, 'path/to/bar.js', true), 3); matchers.push('!path/to/bar.*'); assert(!anymatch(matchers, 'path/to/bar.js')); }); }); describe('windows paths', function() { var origSep = path.sep; before(function() { path.sep = '\\'; }); after(function() { path.sep = origSep; }); it('should resolve backslashes against string matchers', function() { assert(anymatch(matchers, 'path\\to\\file.js')); assert(anymatch(matchers)('path\\to\\file.js')); }); it('should resolve backslashes against glob matchers', function() { assert(anymatch(matchers, 'path\\anyjs\\file.js')); assert(anymatch(matchers)('path\\anyjs\\file.js')); }); it('should resolve backslashes against regex matchers', function() { assert(anymatch(/path\/to\/file\.js/, 'path\\to\\file.js')); assert(anymatch(/path\/to\/file\.js/)('path\\to\\file.js')); }); it('should still correctly handle forward-slash paths', function() { assert(anymatch(matchers, 'path/to/file.js')); assert(anymatch(matchers)('path/to/file.js')); assert(!anymatch(matchers, 'path/no/no.js')); assert(!anymatch(matchers)('path/no/no.js')); }); }); });