human-object-diff
Advanced tools
Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "human-object-diff", | ||
"description": "Human Readable Difference Between Two Objects", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "Spencer Snyder <sasnyde2@gmail.com> (http://spencersnyder.io/)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -60,9 +60,10 @@ # human-object-diff | ||
| Option | type | Default | Description | | ||
| ------------ | ----------- | ---------------------------------- | ----------------------------------------------------------------------------------------------- | | ||
| objectName | String | 'Obj' | This is the object name when presented in the path. ie... "Obj.foo" ignored if hidePath is true | | ||
| prefilter | Array\|Func | | see [prefiltering](#prefiltering) | | ||
| dateFormat | String | 'MM/dd/yyyy hh:mm a' | dateFns format string see [below](#support-for-dates) | | ||
| ignoreArrays | Bool | false | If array differences aren't needed. Set to true and skip processing | | ||
| templates | Object | see [templates](#custom-templates) | Completely customize the output. | | ||
| Option | type | Default | Description | | ||
| -------------- | ---------------- | ---------------------------------- | ----------------------------------------------------------------------------------------------- | | ||
| objectName | String | 'Obj' | This is the object name when presented in the path. ie... "Obj.foo" ignored if hidePath is true | | ||
| prefilter | \[String\]\|Func | | see [prefiltering](#prefiltering) | | ||
| dateFormat | String | 'MM/dd/yyyy hh:mm a' | dateFns format string see [below](#support-for-dates) | | ||
| ignoreArrays | Bool | false | If array differences aren't needed. Set to true and skip processing | | ||
| templates | Object | see [templates](#custom-templates) | Completely customize the output. | | ||
| sensitivePaths | \[String\] | | Paths that will use the sensitive field templates if they are defined | | ||
@@ -100,5 +101,5 @@ ### Custom Templates | ||
You can define each sentence in templates to be whatever you'd like them to be and you can use the following codes that will be replaced by their diff values in the final output. | ||
You can define each sentence in the templates to be whatever you'd like. The following tokens can be used to replace their diff values in the final output. | ||
The available values you can plug in to your sentences are `FIELD`, `DOTPATH`,`NEWVALUE`,`OLDVALUE`, `INDEX`, `POSITION`. Position is just index+1. Be aware that not all sentence types will have values for each token. For instance non array changes will not have a position or an index. | ||
The available tokens that can plug in to your sentence templates are `FIELD`, `DOTPATH`,`NEWVALUE`,`OLDVALUE`, `INDEX`, `POSITION`. Position is just index+1. Be aware that not all sentence types will have values for each token. For instance, non-array changes will not have a position or an index. | ||
@@ -119,3 +120,5 @@ ### Support for Dates | ||
hrDiff(lhs, rhs, { prefilter: ['foo'] }); | ||
const { diff } = new HumanDiff({ prefilter: ['foo'] }); | ||
diff(lhs, rhs); | ||
``` | ||
@@ -149,2 +152,4 @@ | ||
> \*\*There are known bug related to arrays of objects. We plan to release different array processing algorithms in the future that can handle more complex objects. As of the latest version it is reccomended to only diff between flat arrays of strings and numbers. Otherwise there isn't guarantee of accuracy or if diffs won't be duplicated in some ways. | ||
`human-object-diff` parses arrays in an opinionated way. It does it's best to resolve Arrays into groups of insertions and removals. Typical diff libraries look at arrays on an element by element basis and emit a difference for every changes element. While this is benefical for many programatic tasks, humans typically don't look at arrays in the same way. `human-object-diff` attempts to reduce array changes to a number of insertions, removals, and edits. An example can better describe the difference. | ||
@@ -171,2 +176,13 @@ | ||
## Diff Memory | ||
The diff engine object created when `new HumanDiff()` is invoked contains a `sentences` property which you can use to recall the last diff that was computed. | ||
```js | ||
const diffEngine = new HumanDiff(); | ||
diffEngine.diff(lhs, rhs); | ||
diffEngine.sentences; // -> same as the output of the last diff | ||
``` | ||
## Contributors | ||
@@ -173,0 +189,0 @@ |
31109
197