@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
25 lines • 1.01 kB
JavaScript
import _pushInstanceProperty from "core-js-pure/stable/instance/push.js";
export 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) {
_pushInstanceProperty(acc).call(acc, v);
} else {
acc[k] = v;
}
}
return acc;
}, isArray ? [] : {});
}
//# sourceMappingURL=filterProps.js.map