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
48 lines (45 loc) • 1.32 kB
JavaScript
import getIterate from './private/getIterate.js';
export default 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,
options,
obj,
});
return obj;
}
return eachDeep;
}