forked from smikes/fez
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.js
More file actions
48 lines (41 loc) · 1.37 KB
/
match.js
File metadata and controls
48 lines (41 loc) · 1.37 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var ProxyFile = require("./proxy-file.js").ProxyFile,
ProxyFileList = require("./proxy-file.js").ProxyFileList;
function Match(fn, setStage, resetStage, initialGlobs) {
this.fn = fn;
this.setStage = setStage;
this.resetStage = resetStage;
this.initialGlobs = initialGlobs;
}
Match.prototype.not = function(globs) {
var fn = this.fn;
return new Match(function(file) {
return fn(file) && !any(toArray(globs).map(function(glob) {
minimatch(file, glob);
}));
}, this.setStage, this.resetStage, this.initialGlobs);
};
Match.prototype.each = function(fn) {
var proxy = new ProxyFile(),
stage = { input: this.fn, rules: [], tasks: [], proxy: proxy, operations: [], initialGlobs: this.initialGlobs };
this.setStage(stage);
fn(proxy);
this.resetStage();
return stage;
};
Match.prototype.one = function(fn) {
var proxy = new ProxyFile(),
stage = { input: this.fn, rules: [], tasks: [], proxy: proxy, one: true, matched: false, operations: [], initialGlobs: this.initialGlobs };
this.setStage(stage);
fn(proxy);
this.resetStage();
return stage;
};
Match.prototype.all = function(fn) {
var proxy = new ProxyFileList(),
stage = { input: this.fn, rules: [], multi: true, proxy: proxy, operations: [], initialGlobs: this.initialGlobs };
this.setStage(stage);
fn(proxy);
this.resetStage();
return stage;
};
module.exports = Match;