Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / anymatch / index.js
1 'use strict';
2
3 var arrify = require('arrify');
4 var micromatch = require('micromatch');
5 var path = require('path');
6
7 var anymatch = function(criteria, value, returnIndex, startIndex, endIndex) {
8   criteria = arrify(criteria);
9   value = arrify(value);
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;
14     }));
15   }
16   startIndex = startIndex || 0;
17   var string = value[0];
18   var altString;
19   var matched = false;
20   var matchIndex = -1;
21   function testCriteria (criterion, index) {
22     var result;
23     switch (toString.call(criterion)) {
24     case '[object String]':
25       result = string === criterion || altString && altString === criterion;
26       result = result || micromatch.isMatch(string, criterion);
27       break;
28     case '[object RegExp]':
29       result = criterion.test(string) || altString && criterion.test(altString);
30       break;
31     case '[object Function]':
32       result = criterion.apply(null, value);
33       break;
34     default:
35       result = false;
36     }
37     if (result) {
38       matchIndex = index + startIndex;
39     }
40     return result;
41   }
42   var crit = criteria;
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
47         crit = crit.slice();
48       }
49       crit[index] = null;
50       arr.push(criterion.substr(1));
51     }
52     return arr;
53   }, []);
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;
58     }
59     matched = crit.slice(startIndex, endIndex).some(testCriteria);
60   }
61   return returnIndex === true ? matchIndex : matched;
62 };
63
64 module.exports = anymatch;