@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
23 lines • 757 B
JavaScript
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]) => {
if (isArray) {
k = v;
}
if ((typeof remove === 'function' ? !remove(k) : typeof remove?.[k] === 'undefined') || (typeof allowed === 'function' ? allowed(k) : typeof allowed?.[k] !== 'undefined')) {
if (isArray) {
acc.push(v);
} else {
acc[k] = v;
}
}
return acc;
}, isArray ? [] : {});
}
//# sourceMappingURL=filterProps.js.map