index.js 616 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var minimatch = require('minimatch');
  3. var arrayUnion = require('array-union');
  4. var arrayDiffer = require('array-differ');
  5. var arrify = require('arrify');
  6. module.exports = function (list, patterns, options) {
  7. list = arrify(list);
  8. patterns = arrify(patterns);
  9. if (list.length === 0 || patterns.length === 0) {
  10. return [];
  11. }
  12. options = options || {};
  13. return patterns.reduce(function (ret, pattern) {
  14. var process = arrayUnion;
  15. if (pattern[0] === '!') {
  16. pattern = pattern.slice(1);
  17. process = arrayDiffer;
  18. }
  19. return process(ret, minimatch.match(list, pattern, options));
  20. }, []);
  21. };