tiptap/packages/core/src/utilities/deleteProps.ts

23 lines
525 B
TypeScript
Raw Normal View History

2020-12-01 16:20:25 +08:00
import { AnyObject } from '../types'
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-01-28 16:50:17 +08:00
export default function deleteProps(obj: AnyObject, propOrProps: string | string[]): AnyObject {
2020-11-18 22:18:30 +08:00
const props = typeof propOrProps === 'string'
? [propOrProps]
: propOrProps
return Object
.keys(obj)
2020-12-01 16:20:25 +08:00
.reduce((newObj: AnyObject, prop) => {
2020-11-18 22:18:30 +08:00
if (!props.includes(prop)) {
newObj[prop] = obj[prop]
}
return newObj
}, {})
}