UNPKG

@winglet/json

Version:

TypeScript library for safe and efficient JSON data manipulation with RFC 6901 (JSON Pointer) and RFC 6902 (JSON Patch) compliance, featuring prototype pollution protection and immutable operations

18 lines (15 loc) 568 B
import { isPrimitiveType, isPlainObject } from '@winglet/common-utils/filter'; import { equals } from '@winglet/common-utils/object'; import { differenceObjectPatch } from './differenceObjectPatch.mjs'; const difference = (source, target) => { if (source === target) return undefined; if (isPrimitiveType(target)) return target; if (isPlainObject(source) && isPlainObject(target)) return differenceObjectPatch(source, target); if (equals(source, target)) return undefined; return target; }; export { difference };