split helpers and utilities
This commit is contained in:
20
packages/core/src/utilities/deleteProps.ts
Normal file
20
packages/core/src/utilities/deleteProps.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Remove a property or an array of properties from an object
|
||||
* @param obj Object
|
||||
* @param key Key to remove
|
||||
*/
|
||||
export default function deleteProps(obj: { [key: string ]: any }, propOrProps: string | string[]) {
|
||||
const props = typeof propOrProps === 'string'
|
||||
? [propOrProps]
|
||||
: propOrProps
|
||||
|
||||
return Object
|
||||
.keys(obj)
|
||||
.reduce((newObj: { [key: string ]: any }, prop) => {
|
||||
if (!props.includes(prop)) {
|
||||
newObj[prop] = obj[prop]
|
||||
}
|
||||
|
||||
return newObj
|
||||
}, {})
|
||||
}
|
||||
Reference in New Issue
Block a user