You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
501 B
21 lines
501 B
const pick = (obj, ...keys) =>
|
|
keys
|
|
.flat()
|
|
.filter(key => Object.prototype.hasOwnProperty.call(obj, key))
|
|
.reduce((acc, key) => {
|
|
acc[key] = obj[key];
|
|
return acc;
|
|
}, {});
|
|
|
|
const omit = (obj, ...keysToOmit) => {
|
|
const keysToOmitSet = new Set(keysToOmit.flat());
|
|
return Object.getOwnPropertyNames(obj)
|
|
.filter(key => !keysToOmitSet.has(key))
|
|
.reduce((acc, key) => {
|
|
acc[key] = obj[key];
|
|
return acc;
|
|
}, {});
|
|
};
|
|
|
|
module.exports = { pick, omit };
|