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
53 lines (46 loc) • 1.27 kB
JavaScript
import getEachDeep from './getEachDeep.js';
export default function getFindDeep(_) {
const 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
);
const eachDeepOptions = {
pathFormat: options.pathFormat,
checkCircular: options.checkCircular,
ownPropertiesOnly: options.ownPropertiesOnly,
childrenPath: options.childrenPath,
includeRoot: options.includeRoot,
rootIsChildren: options.rootIsChildren,
callbackAfterIterate: false,
leavesOnly: options.leavesOnly,
};
let res;
eachDeep(
obj,
(value, key, parent, context) => {
if (predicate(value, key, parent, context)) {
res = { value, key, parent, context };
return context['break']();
}
},
eachDeepOptions
);
return res;
}
return findDeep;
}