-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgetEachDeep.js
51 lines (47 loc) · 1.35 KB
/
getEachDeep.js
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
49
50
51
'use strict';
var getIterate = require('./private/getIterate.js');
function getEachDeep(_) {
var iterate = getIterate(_);
function eachDeep(obj, callback, options) {
if (callback === undefined) { callback = _.identity; }
options = _.merge(
{
includeRoot: !Array.isArray(obj),
pathFormat: 'string',
checkCircular: false,
leavesOnly: false,
ownPropertiesOnly: true, //
},
options || {}
);
if (options.childrenPath !== undefined) {
if (!options.includeRoot && options.rootIsChildren === undefined) {
options.rootIsChildren = Array.isArray(obj);
}
if (
!_.isString(options.childrenPath) &&
!Array.isArray(options.childrenPath)
) {
throw Error('childrenPath can be string or array');
} else {
if (_.isString(options.childrenPath)) {
options.childrenPath = [options.childrenPath];
}
options.strChildrenPath = options.childrenPath;
options.childrenPath = [];
for (var i = options.strChildrenPath.length - 1; i >= 0; i--) {
options.childrenPath[i] = _.toPath(options.strChildrenPath[i]);
}
}
}
iterate({
value: obj,
callback: callback,
options: options,
obj: obj,
});
return obj;
}
return eachDeep;
}
module.exports = getEachDeep;