js-differ
A JavaScript library for get and apply diffs for JSON data values.
Installation
npm install js-differ
API
Types
; ; ;
Methods
getDiff(from, to, options)
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. |
applyDiff(value, diff, options)
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. |
isEqualDefault(from, to, path)
isRemoveDefault(from, to, path)
isReplaceDefault(from, to, path)
Options
Get Diff Options
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 |
Apply Diff Options
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 |