module-composer
Version:
Bring order to chaos. Level up your JS application architecture with Module Composer, a tiny but powerful module composition utility based on functional dependency injection.
15 lines (10 loc) • 475 B
JavaScript
const isPlainObject = require('./is-plain-object');
const matchPaths = (obj, cb, depth, currentDepth = 0, currentPath = []) => {
return Object.entries(obj).flatMap(([key, val]) => {
const path = [...currentPath, key];
const res1 = !isPlainObject(val) && cb(key) ? [path] : [];
const res2 = isPlainObject(val) ? matchPaths(val, cb, depth, currentDepth + 1, path) : [];
return [...res1, ...res2];
});
};
module.exports = matchPaths;