19 lines
449 B
TypeScript
Raw Permalink Normal View History

2024-11-05 10:09:18 +08:00
import { eq } from './_eq'
const objectProto = Object.prototype
const hasOwnProperty = objectProto.hasOwnProperty
export function assignValue<T extends object>(
object: T,
key: string | symbol,
value: any
) {
const objValue = object[key as keyof typeof object]
if (
!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
(value === undefined && !(key in object))
) {
object[key as keyof typeof object] = value
}
}