Documentation / base / diff
Function: diff()
diff(
base,target):DiffPatch
Defined in: libs/base/src/diff.ts:143
Compute a patch that transforms base into target.
This function emits a sequence of operations needed to convert the input value base into target. The resulting DiffPatch can be applied with applyPatch.
Semantics:
- Primitives: emits a single
setif values differ. - Objects: recurses into keys; emits
setfor additions/updates anddelfor removals. - Arrays: emits an
arroperation containing element-wiseset,ins, anddel.
Notes:
- Comparison for primitives uses strict equality (
===) viashallowEqual. - Complex nested changes within arrays are represented either as:
- element-wise
setwhen types differ or primitives differ, or - nested operations pushed to the top-level with extended paths when elements are arrays/objects.
- element-wise
- This is not a minimum-edit-distance diff; it's a straightforward positional diff.
Parameters
base
The source value.
target
The desired target value.
Returns
A DiffPatch that converts base into target.