@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
32 lines (31 loc) • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.filterProps = filterProps;
var _push = _interopRequireDefault(require("core-js-pure/stable/instance/push.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function filterProps(props, remove = null, allowed = null) {
if (Array.isArray(remove)) {
remove = Object.fromEntries(remove.map(key => [key, true]));
}
if (Array.isArray(allowed)) {
allowed = Object.fromEntries(allowed.map(key => [key, true]));
}
const isArray = Array.isArray(props);
return Object.entries(props).reduce((acc, [k, v]) => {
var _remove, _allowed;
if (isArray) {
k = v;
}
if ((typeof remove === 'function' ? !remove(k) : typeof ((_remove = remove) === null || _remove === void 0 ? void 0 : _remove[k]) === 'undefined') || (typeof allowed === 'function' ? allowed(k) : typeof ((_allowed = allowed) === null || _allowed === void 0 ? void 0 : _allowed[k]) !== 'undefined')) {
if (isArray) {
(0, _push.default)(acc).call(acc, v);
} else {
acc[k] = v;
}
}
return acc;
}, isArray ? [] : {});
}
//# sourceMappingURL=filterProps.js.map