1.0.2 • Published 4 years ago

js-differ v1.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

js-differ

A JavaScript library for get and apply diffs for JSON data values.

Installation

npm install js-differ

API

Types

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;

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

OptionTypeDefault ValueDescription
isEqualCheckFunctionisEqualDefaultYou can customize isEqual function. Priority 0.
isRemoveCheckFunctionisRemoveDefaultYou can customize isRemove function. Priority 1.
isReplaceCheckFunctionisReplaceDefaultYou can customize isReplace function. Priority 2.
isCustomCheckFunction-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
getCustomParamsGetCustomParamsFunction-Custom params getter.
customDiffPrioritynumber3Priority of isCustom check (by default is after repalce). Available values are 0, 1, 2, 3, 4

Apply Diff Options

OptionTypeRequiredDescription
customHandlerCustomHandlerFunction-If isCustom was implemented in Get Diff Options you should implement this funciton. customParams is a result of getCustomParams
1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago