Diff Reference
↔️ Deep diffing utility.
Usage
📦 Node
Install @lou.codes/diff
as a dependency:
Import it and use it:
🦕 Deno
Import @lou.codes/diff
using the npm:
prefix, and use it directly:
🌎 Browser
Import @lou.codes/diff
using esm.sh, and use it directly:
Useful links
- 📝 Documentation: TypeDoc generated documentation.
- ⏳ Changelog: List of changes between versions.
- ✅ Tests Coverage: Coveralls page with tests coverage.
Difference
CreateDifference<Right>
Object that represents a creation difference (a new value or property).
Example
Type declaration
Member | Type | Description |
---|---|---|
right | Right | New value. |
Type parameters
Type parameter | Value | Description |
---|---|---|
Right | unknown | Type of the new value. |
DeleteDifference<Left>
Object that represents a deletion difference (a value or property was removed).
Example
Type declaration
Member | Type | Description |
---|---|---|
left | Left | Original value. |
Type parameters
Type parameter | Value | Description |
---|---|---|
Left | unknown | Type of the removed value. |
Difference<Kind>
Object that represents a difference between two values.
Example
Type parameters
Type parameter | Description |
---|---|
Kind extends DifferenceKind | Type of diff. |
Type declaration
Member | Type | Description |
---|---|---|
kind | Kind | Type of diff. |
path | ReadOnlyArray <PropertyKey > | Path of diff property. |
DifferenceKind
Kinds of differences (create, delete or update).
Example
UpdateDifference<Left, Right>
Object that represents an update difference (a value or property changed).
Example
Type declaration
Member | Type | Description |
---|---|---|
left | Left | Original value. |
right | Right | New value. |
Type parameters
Type parameter | Value | Description |
---|---|---|
Left | unknown | Type of the new value. |
Right | unknown | Type of the original value. |
compare()
Function to compare a left
and a right
value.
Parameters
Parameter | Type | Description |
---|---|---|
values | object | Values to compare. |
values.left ? | unknown | Left value to compare. |
values.right ? | unknown | Right value to compare. |
Returns
Generator
<CreateDifference
| DeleteDifference
|
UpdateDifference
,
any
, unknown
>
Remarks
This does a deep comparison and yields the differences found with a descriptive object.
Example
See
Other
CREATE
Create difference kind.
DELETE
Delete difference kind.
UPDATE
Update difference kind.