manifold/common/util/object.ts
Marshall Polaris b8b1c0d056
Add tsconfig, more linting to common package (#324)
* Add tsconfig.json for common

* Prefer `const` over `let` over `var`

* Kill dead code

* Fix some trivial Typescript issues

* Turn on Typescript linting in common except for no-explicit-any

* Correctly specify tsconfig dir name in functions eslintrc
2022-05-25 17:12:36 -07:00

26 lines
541 B
TypeScript

import { union } from 'lodash'
export const removeUndefinedProps = <T>(obj: T): T => {
const newObj: any = {}
for (const key of Object.keys(obj)) {
if ((obj as any)[key] !== undefined) newObj[key] = (obj as any)[key]
}
return newObj
}
export const addObjects = <T extends { [key: string]: number }>(
obj1: T,
obj2: T
) => {
const keys = union(Object.keys(obj1), Object.keys(obj2))
const newObj = {} as any
for (const key of keys) {
newObj[key] = (obj1[key] ?? 0) + (obj2[key] ?? 0)
}
return newObj as T
}