diff-view-lite
v0.1.0
Published
Human-readable JSON object diffing for audit-trail UIs — deep diff between two objects with dotted field paths, formatted for display.
Readme
diff-view-lite
Human-readable JSON object diffing for audit-trail UIs — deep diff between two objects, returned as flat field-level changes with dotted paths, ready to render as "who changed what."
Install
npm install diff-view-liteQuick start
import { diffObjects, formatChanges } from 'diff-view-lite';
const changes = diffObjects(previousRecord, updatedRecord);
console.log(formatChanges(changes));
// [ 'status: "draft" -> "published"', '+ reviewer: "alice"' ]Why arrays are atomic
Diffing arrays element-by-element (detecting insertions, deletions, reorders) is a much harder problem — LCS-based sequence diffing — and the result is often harder to read in an audit log than "tags changed from [...] to [...]" would be. diff-view-lite treats a changed array as a single field change rather than attempting an element-level diff, which keeps output predictable and matches what "reviewing an edit history" usually needs: did this field change, and to what.
API
diffObjects(from, to)— returns aFieldChange[]:{ type: 'added' | 'removed' | 'changed', path, value | from/to }formatChanges(changes)— human-readable lines per changehasChanges(changes)— convenience boolean check
Nested plain objects are diffed recursively with dotted paths (user.address.city); arrays and primitives are compared as whole values.
License
MIT
