@jayoncode/object-diff API
@jayoncode/object-diff API
Classes
ObjectDiffError
Defined in: errors/index.ts:15
Extends
Error
Extended by
Constructors
Constructor
new ObjectDiffError(
message: string,
code: ObjectDiffErrorCode,
options: ObjectDiffErrorOptions): ObjectDiffError;Defined in: errors/index.ts:19
Parameters
| Parameter | Type |
|---|---|
message | string |
code | ObjectDiffErrorCode |
options | ObjectDiffErrorOptions |
Returns
Overrides
Error.constructorProperties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
code | readonly | ObjectDiffErrorCode | errors/index.ts:16 |
details | readonly | undefined | Readonly<PlainObject> | errors/index.ts:17 |
CircularReferenceError
Defined in: errors/index.ts:31
Extends
Constructors
Constructor
new CircularReferenceError(message: string, options: ObjectDiffErrorOptions): CircularReferenceError;Defined in: errors/index.ts:32
Parameters
| Parameter | Type |
|---|---|
message | string |
options | ObjectDiffErrorOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
code | readonly | ObjectDiffErrorCode | ObjectDiffError.code | errors/index.ts:16 |
details | readonly | undefined | Readonly<PlainObject> | ObjectDiffError.details | errors/index.ts:17 |
MaxDepthExceededError
Defined in: errors/index.ts:38
Extends
Constructors
Constructor
new MaxDepthExceededError(message: string, options: ObjectDiffErrorOptions): MaxDepthExceededError;Defined in: errors/index.ts:39
Parameters
| Parameter | Type |
|---|---|
message | string |
options | ObjectDiffErrorOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
code | readonly | ObjectDiffErrorCode | ObjectDiffError.code | errors/index.ts:16 |
details | readonly | undefined | Readonly<PlainObject> | ObjectDiffError.details | errors/index.ts:17 |
InvalidPatchError
Defined in: errors/index.ts:45
Extends
Constructors
Constructor
new InvalidPatchError(message: string, options: ObjectDiffErrorOptions): InvalidPatchError;Defined in: errors/index.ts:46
Parameters
| Parameter | Type |
|---|---|
message | string |
options | ObjectDiffErrorOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
code | readonly | ObjectDiffErrorCode | ObjectDiffError.code | errors/index.ts:16 |
details | readonly | undefined | Readonly<PlainObject> | ObjectDiffError.details | errors/index.ts:17 |
PatchApplyError
Defined in: errors/index.ts:52
Extends
Constructors
Constructor
new PatchApplyError(message: string, options: ObjectDiffErrorOptions): PatchApplyError;Defined in: errors/index.ts:53
Parameters
| Parameter | Type |
|---|---|
message | string |
options | ObjectDiffErrorOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
code | readonly | ObjectDiffErrorCode | ObjectDiffError.code | errors/index.ts:16 |
details | readonly | undefined | Readonly<PlainObject> | ObjectDiffError.details | errors/index.ts:17 |
UnsupportedTypeError
Defined in: errors/index.ts:59
Extends
Constructors
Constructor
new UnsupportedTypeError(message: string, options: ObjectDiffErrorOptions): UnsupportedTypeError;Defined in: errors/index.ts:60
Parameters
| Parameter | Type |
|---|---|
message | string |
options | ObjectDiffErrorOptions |
Returns
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
code | readonly | ObjectDiffErrorCode | ObjectDiffError.code | errors/index.ts:16 |
details | readonly | undefined | Readonly<PlainObject> | ObjectDiffError.details | errors/index.ts:17 |
Interfaces
DiffRecord
Defined in: types/index.ts:19
A single recorded change between two values.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
path | readonly | string | types/index.ts:20 |
type | readonly | DiffType | types/index.ts:21 |
previous? | readonly | unknown | types/index.ts:22 |
current? | readonly | unknown | types/index.ts:23 |
DiffMetadata
Defined in: types/index.ts:29
Metadata collected during a diff operation.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
durationMs | readonly | number | types/index.ts:30 |
changeCount | readonly | number | types/index.ts:31 |
addedCount | readonly | number | types/index.ts:32 |
removedCount | readonly | number | types/index.ts:33 |
changedCount | readonly | number | types/index.ts:34 |
unchangedCount | readonly | number | types/index.ts:35 |
DiffResult
Defined in: types/index.ts:41
Result of a diff operation.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
changes | readonly | readonly DiffRecord[] | types/index.ts:42 |
metadata | readonly | DiffMetadata | types/index.ts:43 |
DiffOptions
Defined in: types/index.ts:59
Options for diff and filtered diff helpers.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
maxDepth? | readonly | number | types/index.ts:60 |
includeUnchanged? | readonly | boolean | types/index.ts:61 |
detectMoves? | readonly | boolean | types/index.ts:62 |
circular? | readonly | CircularReferenceStrategy | types/index.ts:63 |
customComparator? | readonly | CustomComparator | types/index.ts:64 |
treatUndefinedAsMissing? | readonly | boolean | types/index.ts:65 |
CompareOptions
Defined in: types/index.ts:71
Options for deep equality comparison.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
maxDepth? | readonly | number | types/index.ts:72 |
circular? | readonly | CircularReferenceStrategy | types/index.ts:73 |
customComparator? | readonly | CustomComparator | types/index.ts:74 |
ResolvedDiffOptions
Defined in: types/index.ts:80
Normalized diff options used internally.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
maxDepth | readonly | number | types/index.ts:81 |
includeUnchanged | readonly | boolean | types/index.ts:82 |
detectMoves | readonly | boolean | types/index.ts:83 |
circular | readonly | CircularReferenceStrategy | types/index.ts:84 |
customComparator | readonly | undefined | CustomComparator | types/index.ts:85 |
treatUndefinedAsMissing | readonly | boolean | types/index.ts:86 |
ResolvedCompareOptions
Defined in: types/index.ts:92
Normalized compare options used internally.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
maxDepth | readonly | number | types/index.ts:93 |
circular | readonly | CircularReferenceStrategy | types/index.ts:94 |
customComparator | readonly | undefined | CustomComparator | types/index.ts:95 |
PatchOperation
Defined in: types/index.ts:106
A single JSON Patch style operation.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
op | readonly | PatchOperationType | types/index.ts:107 |
path | readonly | string | types/index.ts:108 |
value? | readonly | unknown | types/index.ts:109 |
PatchOptions
Defined in: types/index.ts:125
Options for patch generation.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
format? | readonly | PatchFormat | types/index.ts:126 |
ApplyPatchOptions
Defined in: types/index.ts:132
Options for applying patches.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
mutable? | readonly | boolean | types/index.ts:133 |
SerializeOptions
Defined in: types/index.ts:144
Options for serialization.
Properties
| Property | Modifier | Type | Defined in |
|---|---|---|---|
title? | readonly | string | types/index.ts:145 |
Type Aliases
DiffType
type DiffType = "added" | "removed" | "changed" | "unchanged";Defined in: types/index.ts:4
Supported change kinds emitted by the difference engine.
PathSegment
type PathSegment = string | number;Defined in: types/index.ts:9
Path segment used for nested value addressing.
Path
type Path = readonly PathSegment[];Defined in: types/index.ts:14
Canonical path representation for a nested value.
CircularReferenceStrategy
type CircularReferenceStrategy = "error" | "skip";Defined in: types/index.ts:49
How circular references are handled during traversal.
CustomComparator()
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
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
path | Path |
Returns
boolean | undefined
PatchOperationType
type PatchOperationType = "add" | "remove" | "replace";Defined in: types/index.ts:101
JSON Patch operation kinds supported in v1.
Patch
type Patch = readonly PatchOperation[];Defined in: types/index.ts:115
A patch is an ordered list of operations.
PatchFormat
type PatchFormat = "json-patch" | "merge";Defined in: types/index.ts:120
Patch generation format.
SerializeFormat
type SerializeFormat = "json" | "pretty" | "markdown" | "table";Defined in: types/index.ts:139
Supported serializer output formats.
ValueKind
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
type ComparisonOutcome = "equal" | "unequal" | "type-mismatch";Defined in: types/index.ts:157
Result of comparing two values at a path.
Functions
compare()
function compare(
a: unknown,
b: unknown,
options?: CompareOptions): boolean;Defined in: compare/compare.ts:9
Deep equality comparison for structured values.
Parameters
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | CompareOptions |
Returns
boolean
diff()
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
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | DiffOptions |
Returns
hasChanges()
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
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | DiffOptions |
Returns
boolean
added()
function added(
a: unknown,
b: unknown,
options?: DiffOptions): DiffRecord[];Defined in: compare/difference/diff.ts:234
Parameters
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | DiffOptions |
Returns
removed()
function removed(
a: unknown,
b: unknown,
options?: DiffOptions): DiffRecord[];Defined in: compare/difference/diff.ts:238
Parameters
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | DiffOptions |
Returns
updated()
function updated(
a: unknown,
b: unknown,
options?: DiffOptions): DiffRecord[];Defined in: compare/difference/diff.ts:242
Parameters
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | DiffOptions |
Returns
unchanged()
function unchanged(
a: unknown,
b: unknown,
options?: DiffOptions): DiffRecord[];Defined in: compare/difference/diff.ts:246
Parameters
| Parameter | Type |
|---|---|
a | unknown |
b | unknown |
options? | DiffOptions |
Returns
patch()
function patch(diffResult: DiffResult, options?: PatchOptions): Patch;Defined in: patch/index.ts:62
Generate a patch from a diff result.
Parameters
| Parameter | Type |
|---|---|
diffResult | DiffResult |
options? | PatchOptions |
Returns
applyPatch()
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
| Parameter | Type |
|---|---|
target | T |
patchOperations | Patch |
options? | ApplyPatchOptions |
Returns
T
revertPatch()
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
| Parameter | Type |
|---|---|
target | T |
patchOperations | Patch |
options? | ApplyPatchOptions |
Returns
T
serialize()
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
| Parameter | Type |
|---|---|
diff | DiffResult |
format | SerializeFormat |
options? | SerializeOptions |
Returns
string
