Skip to content

@jayoncode/object-diff API


@jayoncode/object-diff API

Classes

ObjectDiffError

Defined in: errors/index.ts:15

Extends

  • Error

Extended by

Constructors

Constructor
ts
new ObjectDiffError(
   message: string, 
   code: ObjectDiffErrorCode, 
   options: ObjectDiffErrorOptions): ObjectDiffError;

Defined in: errors/index.ts:19

Parameters
ParameterType
messagestring
codeObjectDiffErrorCode
optionsObjectDiffErrorOptions
Returns

ObjectDiffError

Overrides
ts
Error.constructor

Properties

PropertyModifierTypeDefined in
codereadonlyObjectDiffErrorCodeerrors/index.ts:16
detailsreadonlyundefined | Readonly<PlainObject>errors/index.ts:17

CircularReferenceError

Defined in: errors/index.ts:31

Extends

Constructors

Constructor
ts
new CircularReferenceError(message: string, options: ObjectDiffErrorOptions): CircularReferenceError;

Defined in: errors/index.ts:32

Parameters
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns

CircularReferenceError

Overrides

ObjectDiffError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
codereadonlyObjectDiffErrorCodeObjectDiffError.codeerrors/index.ts:16
detailsreadonlyundefined | Readonly<PlainObject>ObjectDiffError.detailserrors/index.ts:17

MaxDepthExceededError

Defined in: errors/index.ts:38

Extends

Constructors

Constructor
ts
new MaxDepthExceededError(message: string, options: ObjectDiffErrorOptions): MaxDepthExceededError;

Defined in: errors/index.ts:39

Parameters
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns

MaxDepthExceededError

Overrides

ObjectDiffError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
codereadonlyObjectDiffErrorCodeObjectDiffError.codeerrors/index.ts:16
detailsreadonlyundefined | Readonly<PlainObject>ObjectDiffError.detailserrors/index.ts:17

InvalidPatchError

Defined in: errors/index.ts:45

Extends

Constructors

Constructor
ts
new InvalidPatchError(message: string, options: ObjectDiffErrorOptions): InvalidPatchError;

Defined in: errors/index.ts:46

Parameters
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns

InvalidPatchError

Overrides

ObjectDiffError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
codereadonlyObjectDiffErrorCodeObjectDiffError.codeerrors/index.ts:16
detailsreadonlyundefined | Readonly<PlainObject>ObjectDiffError.detailserrors/index.ts:17

PatchApplyError

Defined in: errors/index.ts:52

Extends

Constructors

Constructor
ts
new PatchApplyError(message: string, options: ObjectDiffErrorOptions): PatchApplyError;

Defined in: errors/index.ts:53

Parameters
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns

PatchApplyError

Overrides

ObjectDiffError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
codereadonlyObjectDiffErrorCodeObjectDiffError.codeerrors/index.ts:16
detailsreadonlyundefined | Readonly<PlainObject>ObjectDiffError.detailserrors/index.ts:17

UnsupportedTypeError

Defined in: errors/index.ts:59

Extends

Constructors

Constructor
ts
new UnsupportedTypeError(message: string, options: ObjectDiffErrorOptions): UnsupportedTypeError;

Defined in: errors/index.ts:60

Parameters
ParameterType
messagestring
optionsObjectDiffErrorOptions
Returns

UnsupportedTypeError

Overrides

ObjectDiffError.constructor

Properties

PropertyModifierTypeInherited fromDefined in
codereadonlyObjectDiffErrorCodeObjectDiffError.codeerrors/index.ts:16
detailsreadonlyundefined | Readonly<PlainObject>ObjectDiffError.detailserrors/index.ts:17

Interfaces

DiffRecord

Defined in: types/index.ts:19

A single recorded change between two values.

Properties

PropertyModifierTypeDefined in
pathreadonlystringtypes/index.ts:20
typereadonlyDiffTypetypes/index.ts:21
previous?readonlyunknowntypes/index.ts:22
current?readonlyunknowntypes/index.ts:23

DiffMetadata

Defined in: types/index.ts:29

Metadata collected during a diff operation.

Properties

PropertyModifierTypeDefined in
durationMsreadonlynumbertypes/index.ts:30
changeCountreadonlynumbertypes/index.ts:31
addedCountreadonlynumbertypes/index.ts:32
removedCountreadonlynumbertypes/index.ts:33
changedCountreadonlynumbertypes/index.ts:34
unchangedCountreadonlynumbertypes/index.ts:35

DiffResult

Defined in: types/index.ts:41

Result of a diff operation.

Properties

PropertyModifierTypeDefined in
changesreadonlyreadonly DiffRecord[]types/index.ts:42
metadatareadonlyDiffMetadatatypes/index.ts:43

DiffOptions

Defined in: types/index.ts:59

Options for diff and filtered diff helpers.

Properties

PropertyModifierTypeDefined in
maxDepth?readonlynumbertypes/index.ts:60
includeUnchanged?readonlybooleantypes/index.ts:61
detectMoves?readonlybooleantypes/index.ts:62
circular?readonlyCircularReferenceStrategytypes/index.ts:63
customComparator?readonlyCustomComparatortypes/index.ts:64
treatUndefinedAsMissing?readonlybooleantypes/index.ts:65

CompareOptions

Defined in: types/index.ts:71

Options for deep equality comparison.

Properties

PropertyModifierTypeDefined in
maxDepth?readonlynumbertypes/index.ts:72
circular?readonlyCircularReferenceStrategytypes/index.ts:73
customComparator?readonlyCustomComparatortypes/index.ts:74

ResolvedDiffOptions

Defined in: types/index.ts:80

Normalized diff options used internally.

Properties

PropertyModifierTypeDefined in
maxDepthreadonlynumbertypes/index.ts:81
includeUnchangedreadonlybooleantypes/index.ts:82
detectMovesreadonlybooleantypes/index.ts:83
circularreadonlyCircularReferenceStrategytypes/index.ts:84
customComparatorreadonlyundefined | CustomComparatortypes/index.ts:85
treatUndefinedAsMissingreadonlybooleantypes/index.ts:86

ResolvedCompareOptions

Defined in: types/index.ts:92

Normalized compare options used internally.

Properties

PropertyModifierTypeDefined in
maxDepthreadonlynumbertypes/index.ts:93
circularreadonlyCircularReferenceStrategytypes/index.ts:94
customComparatorreadonlyundefined | CustomComparatortypes/index.ts:95

PatchOperation

Defined in: types/index.ts:106

A single JSON Patch style operation.

Properties

PropertyModifierTypeDefined in
opreadonlyPatchOperationTypetypes/index.ts:107
pathreadonlystringtypes/index.ts:108
value?readonlyunknowntypes/index.ts:109

PatchOptions

Defined in: types/index.ts:125

Options for patch generation.

Properties

PropertyModifierTypeDefined in
format?readonlyPatchFormattypes/index.ts:126

ApplyPatchOptions

Defined in: types/index.ts:132

Options for applying patches.

Properties

PropertyModifierTypeDefined in
mutable?readonlybooleantypes/index.ts:133

SerializeOptions

Defined in: types/index.ts:144

Options for serialization.

Properties

PropertyModifierTypeDefined in
title?readonlystringtypes/index.ts:145

Type Aliases

DiffType

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

Defined in: types/index.ts:4

Supported change kinds emitted by the difference engine.


PathSegment

ts
type PathSegment = string | number;

Defined in: types/index.ts:9

Path segment used for nested value addressing.


Path

ts
type Path = readonly PathSegment[];

Defined in: types/index.ts:14

Canonical path representation for a nested value.


CircularReferenceStrategy

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

Defined in: types/index.ts:49

How circular references are handled during traversal.


CustomComparator()

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

Defined in: types/index.ts:54

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

Parameters

ParameterType
aunknown
bunknown
pathPath

Returns

boolean | undefined


PatchOperationType

ts
type PatchOperationType = "add" | "remove" | "replace";

Defined in: types/index.ts:101

JSON Patch operation kinds supported in v1.


Patch

ts
type Patch = readonly PatchOperation[];

Defined in: types/index.ts:115

A patch is an ordered list of operations.


PatchFormat

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

Defined in: types/index.ts:120

Patch generation format.


SerializeFormat

ts
type SerializeFormat = "json" | "pretty" | "markdown" | "table";

Defined in: types/index.ts:139

Supported serializer output formats.


ValueKind

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

Defined in: types/index.ts:151

Internal value kind for traversal dispatch.


ComparisonOutcome

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

Defined in: types/index.ts:157

Result of comparing two values at a path.

Functions

compare()

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

Defined in: compare/compare.ts:9

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;

Defined in: compare/difference/diff.ts:191

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;

Defined in: compare/difference/diff.ts:198

Fast boolean check for whether two values differ.

Parameters

ParameterType
aunknown
bunknown
options?DiffOptions

Returns

boolean


added()

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

Defined in: compare/difference/diff.ts:234

Parameters

ParameterType
aunknown
bunknown
options?DiffOptions

Returns

DiffRecord[]


removed()

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

Defined in: compare/difference/diff.ts:238

Parameters

ParameterType
aunknown
bunknown
options?DiffOptions

Returns

DiffRecord[]


updated()

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

Defined in: compare/difference/diff.ts:242

Parameters

ParameterType
aunknown
bunknown
options?DiffOptions

Returns

DiffRecord[]


unchanged()

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

Defined in: compare/difference/diff.ts:246

Parameters

ParameterType
aunknown
bunknown
options?DiffOptions

Returns

DiffRecord[]


patch()

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

Defined in: patch/index.ts:62

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;

Defined in: patch/index.ts:204

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


revertPatch()

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

Defined in: patch/index.ts:225

Revert a previously applied patch.

Type Parameters

Type Parameter
T

Parameters

ParameterType
targetT
patchOperationsPatch
options?ApplyPatchOptions

Returns

T


serialize()

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

Defined in: serialize/index.ts:56

Serialize a diff result to a supported output format.

Parameters

ParameterType
diffDiffResult
formatSerializeFormat
options?SerializeOptions

Returns

string

JOC is a JayOnCode monorepo of @jayoncode/* packages. Docs sync from source via TypeDoc and sync scripts.