-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.js
More file actions
28 lines (22 loc) · 608 Bytes
/
index.js
File metadata and controls
28 lines (22 loc) · 608 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {minimatch} from 'minimatch';
import arrayUnion from 'array-union';
import arrayDiffer from 'array-differ';
export default function multimatch(list, patterns, options = {}) {
list = [list].flat();
patterns = [patterns].flat();
if (list.length === 0 || patterns.length === 0) {
return [];
}
let result = [];
for (const item of list) {
for (let pattern of patterns) {
let process = arrayUnion;
if (pattern[0] === '!') {
pattern = pattern.slice(1);
process = arrayDiffer;
}
result = process(result, minimatch.match([item], pattern, options));
}
}
return result;
}