-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.js
More file actions
39 lines (27 loc) · 807 Bytes
/
util.js
File metadata and controls
39 lines (27 loc) · 807 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
29
30
31
32
33
34
35
36
37
38
39
var proxyaddr = require('proxy-addr');
var util = {};
util.defineMember = function(obj, name) {
var nameSplit = name.split('.');
var i;
var exists = obj;
for (i = 0; i < nameSplit.length - 1; i++) {
if (!exists.hasOwnProperty(nameSplit[i]) || typeof exists[nameSplit[i]] !== 'object') {
exists[nameSplit[i]] = {};
}
exists = exists[nameSplit[i]]
}
};
util.compileTrust = function(val) {
if (typeof val === 'function') return val;
if (val === true) {
return function() { return true };
}
if (typeof val === 'number') {
return function(a, i) { return i < val };
}
if (typeof val === 'string') {
val = val.split(/ *, */);
}
return proxyaddr.compile(val || []);
};
module.exports = util;