Skip to content

@jayoncode/object-diff API


@jayoncode/object-diff API ​

Classes ​

ObjectDiffError ​

Extends ​

  • Error

Extended by ​

Constructors ​

Constructor ​
ts
new ObjectDiffError(
   message: string, 
   code: ObjectDiffErrorCode, 
   options?: ObjectDiffErrorOptions): ObjectDiffError;
Parameters ​
ParameterType
messagestring
codeObjectDiffErrorCode
optionsObjectDiffErrorOptions
Returns ​

ObjectDiffError

Overrides ​
ts
Error.constructor

Properties ​

PropertyModifierType
codereadonlyObjectDiffErrorCode
detailsreadonlyReadonly<PlainObject> | undefined

CircularReferenceError ​

Extends ​

Constructors ​

Constructor ​
ts
new CircularReferenceError(message: string, options?: ObjectDiffErrorOptions): CircularReferenceError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

CircularReferenceError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

MaxDepthExceededError ​

Extends ​

Constructors ​

Constructor ​
ts
new MaxDepthExceededError(message: string, options?: ObjectDiffErrorOptions): MaxDepthExceededError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

MaxDepthExceededError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

InvalidPatchError ​

Extends ​

Constructors ​

Constructor ​
ts
new InvalidPatchError(message: string, options?: ObjectDiffErrorOptions): InvalidPatchError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

InvalidPatchError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

PatchApplyError ​

Extends ​

Constructors ​

Constructor ​
ts
new PatchApplyError(message: string, options?: ObjectDiffErrorOptions): PatchApplyError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

PatchApplyError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

UnsupportedTypeError ​

Extends ​

Constructors ​

Constructor ​
ts
new UnsupportedTypeError(message: string, options?: ObjectDiffErrorOptions): UnsupportedTypeError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

UnsupportedTypeError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

NotImplementedError ​

Extends ​

Constructors ​

Constructor ​
ts
new NotImplementedError(message: string, options?: ObjectDiffErrorOptions): NotImplementedError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

NotImplementedError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

InvalidOptionsError ​

Extends ​

Constructors ​

Constructor ​
ts
new InvalidOptionsError(message: string, options?: ObjectDiffErrorOptions): InvalidOptionsError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

InvalidOptionsError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

PluginError ​

Extends ​

Constructors ​

Constructor ​
ts
new PluginError(message: string, options?: ObjectDiffErrorOptions): PluginError;
Parameters ​
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns ​

PluginError

Overrides ​

ObjectDiffError.constructor

Properties ​

PropertyModifierTypeInherited from
codereadonlyObjectDiffErrorCodeObjectDiffError.code
detailsreadonlyReadonly<PlainObject> | undefinedObjectDiffError.details

Interfaces ​

DiffRecord ​

A single recorded change between two values.

Properties ​

PropertyModifierTypeDescription
pathreadonlystring-
typereadonlyDiffType-
previous?readonlyunknown-
current?readonlyunknown-
from?readonlystringSource display path when type is moved.

DiffMetadata ​

Metadata collected during a diff operation.

Properties ​

PropertyModifierType
durationMsreadonlynumber
changeCountreadonlynumber
addedCountreadonlynumber
removedCountreadonlynumber
changedCountreadonlynumber
unchangedCountreadonlynumber
movedCountreadonlynumber

DiffResult ​

Result of a diff operation.

Properties ​

PropertyModifierType
changesreadonlyreadonly DiffRecord[]
metadatareadonlyDiffMetadata

DiffOptions ​

Options for diff and filtered diff helpers.

Properties ​

PropertyModifierTypeDescription
maxDepth?readonlynumber-
includeUnchanged?readonlyboolean-
detectMoves?readonlybooleanWhen true, pair equal removed+added values into moved records (and JSON Patch move ops).
circular?readonlyCircularReferenceStrategy-
customComparator?readonlyCustomComparator-
treatUndefinedAsMissing?readonlyboolean-
identityKey?readonlyIdentityKeyMatch array elements by identity instead of index.
ignore?readonlyreadonly string[]Skip paths matching these patterns (*, ** supported).
include?readonlyreadonly string[]Only emit/visit paths matching these patterns (ancestors still visited).

CompareOptions ​

Options for deep equality comparison.

Properties ​

PropertyModifierType
maxDepth?readonlynumber
circular?readonlyCircularReferenceStrategy
customComparator?readonlyCustomComparator

ResolvedDiffOptions ​

Normalized diff options used internally.

Properties ​

PropertyModifierType
maxDepthreadonlynumber
includeUnchangedreadonlyboolean
detectMovesreadonlyboolean
circularreadonlyCircularReferenceStrategy
customComparatorreadonlyCustomComparator | undefined
treatUndefinedAsMissingreadonlyboolean
identityKeyreadonlyIdentityKey | undefined
ignorereadonlyreadonly string[] | undefined
includereadonlyreadonly string[] | undefined

ResolvedCompareOptions ​

Normalized compare options used internally.

Properties ​

PropertyModifierType
maxDepthreadonlynumber
circularreadonlyCircularReferenceStrategy
customComparatorreadonlyCustomComparator | undefined

PatchOperation ​

A single JSON Patch style operation.

Properties ​

PropertyModifierType
opreadonlyPatchOperationType
pathreadonlystring
from?readonlystring
value?readonlyunknown

PatchOptions ​

Options for patch generation.

Properties ​

PropertyModifierTypeDescription
format?readonlyPatchFormat-
optimize?readonlybooleanCoalesce sequential replaces and drop no-op-friendly noise. Default false.

ApplyPatchOptions ​

Options for applying patches.

Properties ​

PropertyModifierTypeDescription
mutable?readonlyboolean-
validate?readonlybooleanValidate operations before apply. Default true.

ApplyPatchWithInverseResult ​

Result of applying a patch while recording a faithful inverse.

Type Parameters ​

Type Parameter
T

Properties ​

PropertyModifierType
valuereadonlyT
inversereadonlyPatch

SerializeOptions ​

Options for serialization.

Properties ​

PropertyModifierTypeDescription
title?readonlystring-
color?readonlybooleanWhen false, console format omits ANSI colors. Default true.

FormatterPlugin ​

Optional custom formatter registered via createSerializer (no import side effects).

Properties ​

PropertyModifierType
namereadonlystring

Methods ​

format() ​
ts
format(result: DiffResult, options?: SerializeOptions): string;
Parameters ​
ParameterType
resultDiffResult
options?SerializeOptions
Returns ​

string

Type Aliases ​

DiffType ​

ts
type DiffType = "added" | "removed" | "changed" | "unchanged" | "moved";

Supported change kinds emitted by the difference engine.


PathSegment ​

ts
type PathSegment = string | number;

Path segment used for nested value addressing.


Path ​

ts
type Path = readonly PathSegment[];

Canonical path representation for a nested value.


CircularReferenceStrategy ​

ts
type CircularReferenceStrategy = "error" | "skip";

How circular references are handled during traversal.


CustomComparator ​

ts
type CustomComparator = (a: unknown, b: unknown, path: Path) => boolean | undefined;

Custom comparator hook. Return true if equal, false if unequal, undefined to use default.

Parameters ​

ParameterType
aunknown
bunknown
pathPath

Returns ​

boolean | undefined


IdentityKey ​

ts
type IdentityKey = 
  | string
  | ((item: unknown, path: Path) => string | number | undefined);

Identity key for array element matching (Phase 2). String form reads a property; function form returns an id or undefined (positional leftover).


PatchOperationType ​

ts
type PatchOperationType = "add" | "remove" | "replace" | "move" | "copy" | "test";

JSON Patch operation kinds (RFC 6902).


Patch ​

ts
type Patch = readonly PatchOperation[];

A patch is an ordered list of operations.


PatchFormat ​

ts
type PatchFormat = "json-patch" | "merge";

Patch generation format.


SerializeFormat ​

ts
type SerializeFormat = "json" | "pretty" | "markdown" | "table" | "html" | "console" | "human";

Supported serializer output formats.


ValueKind ​

ts
type ValueKind = 
  | "primitive"
  | "array"
  | "object"
  | "date"
  | "regexp"
  | "map"
  | "set"
  | "typed-array"
  | "function";

Internal value kind for traversal dispatch.


ComparisonOutcome ​

ts
type ComparisonOutcome = "equal" | "unequal" | "type-mismatch";

Result of comparing two values at a path.

Functions ​

compare() ​

ts
function compare(
   a: unknown, 
   b: unknown, 
   options?: CompareOptions): boolean;

Deep equality comparison for structured values.

Parameters ​

ParameterType
aunknown
bunknown
options?CompareOptions

Returns ​

boolean


diff() ​

ts
function diff(
   a: unknown, 
   b: unknown, 
   options?: DiffOptions): DiffResult;

Compare two values and return structured change records.

Parameters ​

ParameterType
aunknown
bunknown
options?DiffOptions

Returns ​

DiffResult


hasChanges() ​

ts
function hasChanges(
   a: unknown, 
   b: unknown, 
   options?: DiffOptions): boolean;

Fast boolean check for whether two values differ. Early-exits on the first allowed change; does not allocate a DiffResult.

Parameters ​

ParameterType
aunknown
bunknown
options?DiffOptions

Returns ​

boolean


added() ​

ts
function added(
   a: unknown, 
   b: unknown, 
   options?: DiffOptions): DiffRecord[];

Parameters ​

ParameterType
aunknown
bunknown
options?DiffOptions

Returns ​

DiffRecord[]


removed() ​

ts
function removed(
   a: unknown, 
   b: unknown, 
   options?: DiffOptions): DiffRecord[];

Parameters ​

ParameterType
aunknown
bunknown
options?DiffOptions

Returns ​

DiffRecord[]


updated() ​

ts
function updated(
   a: unknown, 
   b: unknown, 
   options?: DiffOptions): DiffRecord[];

Parameters ​

ParameterType
aunknown
bunknown
options?DiffOptions

Returns ​

DiffRecord[]


unchanged() ​

ts
function unchanged(
   a: unknown, 
   b: unknown, 
   options?: DiffOptions): DiffRecord[];

Parameters ​

ParameterType
aunknown
bunknown
options?DiffOptions

Returns ​

DiffRecord[]


patch() ​

ts
function patch(diffResult: DiffResult, options?: PatchOptions): Patch;

Generate a patch from a diff result.

Parameters ​

ParameterType
diffResultDiffResult
options?PatchOptions

Returns ​

Patch


applyPatch() ​

ts
function applyPatch<T>(
   target: T, 
   patchOperations: Patch, 
   options?: ApplyPatchOptions): T;

Apply a patch to a target value. Returns a new value by default.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
targetT
patchOperationsPatch
options?ApplyPatchOptions

Returns ​

T


applyPatchWithInverse() ​

ts
function applyPatchWithInverse<T>(
   target: T, 
   patchOperations: Patch, 
options?: ApplyPatchOptions): ApplyPatchWithInverseResult<T>;

Apply a patch and return a faithful inverse patch (previous values captured).

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
targetT
patchOperationsPatch
options?ApplyPatchOptions

Returns ​

ApplyPatchWithInverseResult<T>


revertPatch() ​

ts
function revertPatch<T>(
   target: T, 
   patchOperations: Patch, 
   options?: ApplyPatchOptions): T;

Revert a previously applied patch. Prefer applyPatchWithInverse when you need faithful undo of replaces/removes. This helper inverts ops structurally; remove→add uses undefined unless values were journaled.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterType
targetT
patchOperationsPatch
options?ApplyPatchOptions

Returns ​

T


optimizePatch() ​

ts
function optimizePatch(patchOperations: Patch): Patch;

Optimize a patch: coalesce sequential replaces on the same path (keep last). Does not reorder independent operations.

Parameters ​

ParameterType
patchOperationsPatch

Returns ​

Patch


validatePatch() ​

ts
function validatePatch(patchOperations: unknown): asserts patchOperations is Patch;

Validate a patch document. Throws InvalidPatchError on failure.

Parameters ​

ParameterType
patchOperationsunknown

Returns ​

asserts patchOperations is Patch


serialize() ​

ts
function serialize(
   diff: DiffResult, 
   format: SerializeFormat, 
   options?: SerializeOptions): string;

Serialize a diff result to a supported built-in output format. Works with zero plugins (no import side effects).

Parameters ​

ParameterType
diffDiffResult
formatSerializeFormat
options?SerializeOptions

Returns ​

string

An ecosystem of independent, headless TypeScript libraries engineered for modern web development. Every package includes interactive playgrounds and documentation that evolves alongside the code.