UNPKG

respond-framework

Version:
21 lines (20 loc) 820 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = sliceBranch; exports.stripBranchWithUnknownFallback = exports.strip = exports.prepend = void 0; function sliceBranch(obj, branch) { if (!branch || !obj) return obj; const modules = branch.split('.'); return modules.reduce((slice, k) => slice[k], obj); } const strip = (a, b) => // 'admin', 'admin.foo' or 'admin', 'admin' a ? b.replace(new RegExp(`^${a}\.?`), '') : b; // 'foo' '' exports.strip = strip; const prepend = (a = '', b = '') => a ? b ? `${a}.${b}` : a : b; exports.prepend = prepend; const stripBranchWithUnknownFallback = (a, b) => a ? b.indexOf(a) === 0 // a is ancestor of b ? strip(a, b) : 'unknown.' + b : b; exports.stripBranchWithUnknownFallback = stripBranchWithUnknownFallback;