A JavaScript library for get and apply diffs for JSON data values.
npm install js-differ
type Path = (string | number)[]
type CheckFunction = (from: any, to: any, path: Path) => boolean;
type GetCustomParamsFunction = (from: any, to: any, path: Path, getDiff: (from: any, to: any, path: Path) => Diff) => any;
type CustomHandlerFunction = (value: any, customParams: any, path: Path, apply: (value: any, diff: Diff, path: Path) => any) => any;
Returns structure of diff to pass in applyDiff functon.
Param | Type | Required | Description |
---|---|---|---|
from | any | + | Initial value. |
to | any | + | Result value. |
options | object | - | More info here. |
Returns new value by applying diff to initial value.
Param | Type | Required | Description |
---|---|---|---|
value | any | + | Initial value. |
diff | object | + | Result of getDiff function. |
options | object | - | More info here. |
Option | Type | Default Value | Description |
---|---|---|---|
isEqual | CheckFunction | isEqualDefault | You can customize isEqual function. Priority 0 . |
isRemove | CheckFunction | isRemoveDefault | You can customize isRemove function. Priority 1 . |
isReplace | CheckFunction | isReplaceDefault | You can customize isReplace function. Priority 2 . |
isCustom | CheckFunction | - | You can specify your custom behaviour of diff. If you implement this function you must implement getCustomParams too. Also implement customHandler function of Apply Diff Options |
getCustomParams | GetCustomParamsFunction | - | Custom params getter. |
customDiffPriority | number | 3 | Priority of isCustom check (by default is after repalce). Available values are 0, 1, 2, 3, 4 |
Option | Type | Required | Description |
---|---|---|---|
customHandler | CustomHandlerFunction | - | If isCustom was implemented in Get Diff Options you should implement this funciton. customParams is a result of getCustomParams |