respond-framework
Version:
create as fast you think
24 lines (22 loc) • 627 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const findClosestAncestorWith = (key, branch, respond) => {
const {
top,
focusedBranch: fb
} = respond;
const b = fb ? branch ? fb + '.' + branch : fb : branch;
if (!b) return top; // top
let mod = top;
return b // 'admin.foo.bar'
.split('.') // ['admin', 'foo', 'bar]
.slice(0, -1) // ['admin', 'foo']
.map(k => mod = mod[k]) // [admin, foo]
.reverse() // [foo, admin]
.find(b => b[key]) // admin.db
?? top; // admin ?? top
};
var _default = exports.default = findClosestAncestorWith;