push
travis-ci
375 of 376 relevant lines covered (99.73%)
64.65 hits per line
1 |
"use strict";
|
|
2 |
|
|
3 |
var isPlainObject = exports.isPlainObject = function (o) { |
1✔ |
4 |
if (o === null) { |
460✔ |
5 |
return false; |
1✔ |
6 |
} |
|
7 |
if (o instanceof Date) { |
459✔ |
8 |
return false; |
1✔ |
9 |
} |
|
10 |
return (['object'].indexOf(typeof o) !== -1); |
458✔ |
11 |
}; |
|
12 |
|
|
13 |
exports.deepForEach = function deepForEach(obj, fns) { |
1✔ |
14 |
var inobj = obj;
|
584✔ |
15 |
fns = fns || {}; |
584✔ |
16 |
|
|
17 |
if (fns.pre) {
|
584✔ |
18 |
obj = fns.pre(obj); |
584✔ |
19 |
} |
|
20 |
|
|
21 |
var ret;
|
584✔ |
22 |
if (obj === null) { |
584✔ |
23 |
ret = null;
|
11✔ |
24 |
} else if (Array.isArray(obj)) { |
573✔ |
25 |
ret = obj.map(function (elt) {
|
116✔ |
26 |
return deepForEach(elt, fns);
|
234✔ |
27 |
}); |
|
28 |
} else if (isPlainObject(obj)) { |
457✔ |
29 |
ret = {}; |
144✔ |
30 |
Object.keys(obj).forEach(function (k) {
|
144✔ |
31 |
ret[k] = deepForEach(obj[k], fns); |
318✔ |
32 |
}); |
|
33 |
} else {
|
|
34 |
ret = obj; |
313✔ |
35 |
} |
|
36 |
|
|
37 |
if (fns.post) {
|
584✔ |
38 |
ret = fns.post(inobj, ret); |
240✔ |
39 |
} |
|
40 |
return ret;
|
584✔ |
41 |
}; |
|
42 |
|
|
43 |
exports.exists = function (obj) { |
1✔ |
44 |
return obj !== undefined && obj !== null; |
6✔ |
45 |
}; |