Use jsondiffpatch.create(options) to customize diffing behavior, including array detection, text diffing, and property filtering.
import * as jsondiffpatch from 'jsondiffpatch';
import { diff_match_patch } from '@dmsnell/diff-match-patch';
const jsondiffpatchInstance = jsondiffpatch.create({
// used to match objects when diffing arrays
objectHash: function (obj) {
return obj._id || obj.id;
},
arrays: {
// detect items moved inside the array (default: true)
detectMove: true,
// include the value of moved items in deltas (default: false)
includeValueOnMove: false,
},
textDiff: {
// required if using text diffs
diffMatchPatch: diff_match_patch,
// minimum string length to use text diff algorithm (default: 60)
minLength: 60,
},
// ignore specific properties (e.g., volatile data)
propertyFilter: function (name, context) {
return name.slice(0, 1) !== '$';
},
// if true, values in the delta are cloned to prevent references to original objects
cloneDiffValues: false,
// if true, 'old' values are omitted from the delta to reduce size
omitRemovedValues: false,
});