UNPKG

deepdash

Version:

➔ 𝐃eep standalone lib / 𝐋odash extension: ✓ eachDeep ✓ filterDeep ✓ mapDeep ✓ reduceDeep ✓ pickDeep ✓ omitDeep ✓ keysDeep ✓ index ✓ condenseDeep ⋮ Parents stack ⋮ Circular check ⋮ Leaves only mode ⋮ Children mode ⋮ cherry-pick ⋮ esm

43 lines (41 loc) 1.15 kB
import getEachDeep from './getEachDeep.js'; export default 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; }