-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
20 lines (18 loc) · 657 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* Returns a shallow copy of the object omitting keys from an array of paths.
* A lightweight, compatible version of _.omit.
*
* Useful for components that need some props to be passed to children.
*
* @param {Object} object - Original object
* @param {Array<String>} paths - Keys to omit from the object
* @return {Object} - Shallow copy without specified keys
*/
export const omit = (object, paths) =>
Object.keys(object)
.reduce((result, key) => {
if (!paths.includes(key)) {
result[key] = object[key] // eslint-disable-line no-param-reassign
}
return result
}, {})