2020-11-18 22:18:30 +08:00
|
|
|
/**
|
|
|
|
* Remove a property or an array of properties from an object
|
|
|
|
* @param obj Object
|
|
|
|
* @param key Key to remove
|
|
|
|
*/
|
2021-04-21 15:43:31 +08:00
|
|
|
export default function deleteProps(obj: Record<string, any>, propOrProps: string | string[]): Record<string, any> {
|
2020-11-18 22:18:30 +08:00
|
|
|
const props = typeof propOrProps === 'string'
|
|
|
|
? [propOrProps]
|
|
|
|
: propOrProps
|
|
|
|
|
|
|
|
return Object
|
|
|
|
.keys(obj)
|
2021-04-21 15:43:31 +08:00
|
|
|
.reduce((newObj: Record<string, any>, prop) => {
|
2020-11-18 22:18:30 +08:00
|
|
|
if (!props.includes(prop)) {
|
|
|
|
newObj[prop] = obj[prop]
|
|
|
|
}
|
|
|
|
|
|
|
|
return newObj
|
|
|
|
}, {})
|
|
|
|
}
|