forked from smikes/fez
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy-file.js
More file actions
44 lines (34 loc) · 1.08 KB
/
proxy-file.js
File metadata and controls
44 lines (34 loc) · 1.08 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
function ProxyFile() { }
ProxyFile.prototype._setFile = function(lazy) {
this._lazy = lazy;
};
ProxyFile.prototype._inspect = function() {
if(this._lazy === undefined) throw new Error("Can't call inspect_() outside of a lazy function");
return this._lazy;
};
ProxyFile.prototype.map = function(fn) {
return function() {
return fn(this._inspect());
}.bind(this);
};
ProxyFile.prototype.mapName = function(fn) {
return function() {
return fn(this._inspect().getFilename());
}.bind(this);
};
ProxyFile.prototype.patsubst = function(pattern, replacement) {
return this.mapName(patsubst.bind(this, pattern, replacement));
};
function ProxyFileList() { }
ProxyFileList.prototype.names = function() {
return this._lazies.getFilenames();
};
exports.ProxyFile = ProxyFile;
exports.ProxyFileList = ProxyFileList;
function patsubst(pattern, replacement, string) {
var regex = new RegExp(pattern.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1").replace("%", "(.+)")),
result = regex.exec(string),
sub = result[1],
out = replacement.replace("%", sub);
return out;
}