-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
getPaths.js
46 lines (43 loc) · 1.16 KB
/
getPaths.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
'use strict';
var getEachDeep = require('./getEachDeep.js');
function getPaths(_) {
var eachDeep = getEachDeep(_);
function paths(obj, options) {
if (options && options.leafsOnly !== undefined) {
options.leavesOnly = options.leafsOnly;
}
options = _.merge(
{
checkCircular: false,
includeCircularPath: true,
leavesOnly: !options || options.childrenPath === undefined,
pathFormat: 'string',
},
options || {}
);
var eachDeepOptions = {
pathFormat: options.pathFormat,
checkCircular: options.checkCircular,
ownPropertiesOnly: options.ownPropertiesOnly,
includeRoot: options.includeRoot,
childrenPath: options.childrenPath,
rootIsChildren: options.rootIsChildren,
leavesOnly: options.leavesOnly,
};
var res = [];
eachDeep(
obj,
function (value, key, parent, context) {
if (!context.isCircular || options.includeCircularPath) {
if (context.path !== undefined) {
res.push(context.path);
}
}
},
eachDeepOptions
);
return res;
}
return paths;
}
module.exports = getPaths;