declare const DELETED: 0; declare const ADDED: 1; declare const CHANGED: 2; /** Array-only: insert the value at the index, shifting later elements right. */ declare const INSERTED: 3; /** Array-only: remove the element at the index, shifting later elements left. */ declare const REMOVED: 4; type DiffType = typeof DELETED | typeof ADDED | typeof CHANGED | typeof INSERTED | typeof REMOVED; /** * Represents the result of a single difference detected between two objects. * * @example * { type: 2, path: ["foo", "bar"], value: 42 } */ type DiffResult = { /** * The type of change: `0` (Deleted), `1` (Added), `2` (Changed), * `3` (Inserted — array-only, splice in at index), `4` (Removed — * array-only, splice out at index). */ type: DiffType; /** * The path to the changed property, e.g. `["foo", "bar", 0]`. * * Object keys are strings, array and Set indexes are numbers, and Map * entries use the Map key itself — which can be a value of any type. */ path: Array; /** The new value (present for Added and Changed types). */ value?: unknown; }; type CompareFn = (a: object, b: object) => boolean | undefined; /** * Performs a deep difference between two objects. * * @param obj1 - The original object. * @param obj2 - The modified object. * @param fn - Optional custom comparator for specialized types. * @returns An array of differences between the two objects. * * @example * diff({a: 1}, {a: 5}) //=> [{type: 2, path: ['a'], value: 5}] */ declare function diff(obj1: unknown, obj2: unknown, fn?: CompareFn): Array; /** * Performs a deep difference between two objects using a custom comparator function. * * Return `true` from the comparator to mark objects as changed. * Return `false` to mark them as equal (skips deep comparison). * Return `undefined` to fall through to the default comparison. * * Note: the comparator is invoked only when both values are objects; * primitive values are always compared with built-in `Object.is` semantics. * * @param obj1 - The original object. * @param obj2 - The modified object. * @param fn - A custom comparator function. * @returns An array of differences. * * @example * diffWith({a: 1}, {a: 5}, (a, b) => {}) //=> [{type: 2, path: ['a'], value: 5}] */ declare function diffWith(obj1: unknown, obj2: unknown, fn: (a: object, b: object) => boolean | undefined): Array; /** * Applies an array of diff results onto the original object to produce the modified object. * * @param obj - The original object to patch. * @param patches - An array of diff results to apply. * @returns A new object with the patches applied. * * @example * const a = {a: 1, b: 2}; * const b = {a: 2, c: 3}; * const out = patch(a, diff(a, b)); * assert.deepStrictEqual(out, b); // ok */ declare function patch(obj: T, patches: Array): T; /** Encode a diff into a self-describing JSON string that survives transport. */ declare function serialize(patches: DiffResult[]): string; /** Decode a string produced by `serialize` back into a diff with live typed values. */ declare function deserialize(wire: string): DiffResult[]; /** * Serialize any JavaScript value to a self-describing, type-safe JSON string — * the general-purpose counterpart to `serialize` (which is diff-specific). Uses * the same codec, so it preserves every supported native type (`Date`, `Map`, * `Set`, `TypedArray`, `ArrayBuffer`, `DataView`, `Error`, `URL`, `BigInt`, * `Temporal`, `NaN`/`±Infinity`/`-0`, `undefined`, …) plus circular references * and shared identity among plain objects and arrays. Symbols, functions, and * class instances throw. */ declare function stringify(value: unknown): string; /** Parse a string produced by `stringify` back into the original value with live typed values. */ declare function parse(wire: string): T; export { ADDED, CHANGED, DELETED, type DiffResult, type DiffType, INSERTED, REMOVED, deserialize, diff, diffWith, parse, patch, serialize, stringify };