Import
What it does
DiffUtils provides static methods for comparing objects and arrays, generating structured diff results, and applying or reverting patches. It supports deep and shallow comparison, array-level diffing, diff merging, and human-readable formatting.
Methods
deepDiff(a, b)
Recursively compares two values and returns an array of DiffResult entries describing every difference at any depth.
shallowDiff(a, b)
Compares two objects at the top level only (no recursion into nested objects).
arrayDiff(a, b)
Compares two arrays and returns an ArrayDiffResult.
patch(original, diffs)
Applies an array of DiffResult entries to original, returning the patched value.
unpatch(patched, diffs)
Reverts a patch, restoring the value to its pre-diff state.
mergeDiffs(diffs1, diffs2)
Merges two diff arrays into a single consolidated diff.
hasDifferences(a, b)
Returns true if the two values differ (deep comparison). A fast boolean check when you don’t need the full diff.
diffSummary(diffs)
Returns aggregate counts from a diff array.
Returns a human-readable string representation of the diff array — useful for logging or debugging.
Types
DiffResult
ArrayDiffResult
Examples
Detect and log config changes
Undo / redo with patch and unpatch
Use hasDifferences for quick boolean checks. It short-circuits on the first difference and is faster than computing the full diff.
shallowDiff only compares top-level properties. Nested objects are compared by reference, not by value. Use deepDiff when you need full structural comparison.