-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathgetFindDeep.js
56 lines (48 loc) · 1.3 KB
/
getFindDeep.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
52
53
54
55
56
'use strict';
var getEachDeep = require('./getEachDeep.js');
function getFindDeep(_) {
var eachDeep = getEachDeep(_);
function findDeep(obj, predicate, options) {
predicate = _.iteratee(predicate);
if (!options) {
options = {};
} else {
options = _.cloneDeep(options);
if (options.leafsOnly !== undefined) {
options.leavesOnly = options.leafsOnly;
}
}
options = _.merge(
{
checkCircular: false,
leavesOnly: options.childrenPath === undefined,
pathFormat: 'string',
},
options
);
var eachDeepOptions = {
pathFormat: options.pathFormat,
checkCircular: options.checkCircular,
ownPropertiesOnly: options.ownPropertiesOnly,
childrenPath: options.childrenPath,
includeRoot: options.includeRoot,
rootIsChildren: options.rootIsChildren,
callbackAfterIterate: false,
leavesOnly: options.leavesOnly,
};
var res;
eachDeep(
obj,
function (value, key, parent, context) {
if (predicate(value, key, parent, context)) {
res = { value: value, key: key, parent: parent, context: context };
return context['break']();
}
},
eachDeepOptions
);
return res;
}
return findDeep;
}
module.exports = getFindDeep;