Sha256: d7a5706a4fffa5651daa5e2b9c7a8af53fd720fa061754ebd864d080a134c74a

Contents?: true

Size: 1.92 KB

Versions: 25

Compression:

Stored size: 1.92 KB

Contents

'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;

Version data entries

25 entries across 25 versions & 7 rubygems

Version Path
affiliator-0.2.1 node_modules/anymatch/index.js
lanes-0.8.0 node_modules/anymatch/index.js
brwy_rails-0.0.6 test/dummy/node_modules/anymatch/index.js
brwy_rails-0.0.5 test/dummy/node_modules/anymatch/index.js
blackboard-3.1.9 lib/site_template/node_modules/anymatch/index.js
brwy_rails-0.0.4 test/dummy/node_modules/anymatch/index.js
brwy_rails-0.0.3 test/dummy/node_modules/anymatch/index.js
brwy_rails-0.0.2 test/dummy/node_modules/anymatch/index.js
brwy_rails-0.0.1 test/dummy/node_modules/anymatch/index.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/anymatch/index.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/anymatch/index.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/anymatch/index.js
hooch-0.4.2 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/index.js
hooch-0.4.1 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/index.js
hooch-0.4.0 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/index.js
gulp_assets-1.0.0.pre.5 template/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/anymatch/index.js
gulp_assets-1.0.0.pre.4 template/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/anymatch/index.js
gulp_assets-1.0.0.pre.3 template/node_modules/webpack/node_modules/watchpack/node_modules/chokidar/node_modules/anymatch/index.js
hooch-0.3.0 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/index.js
hooch-0.2.1 jasmine/node_modules/karma/node_modules/chokidar/node_modules/anymatch/index.js