Skip to content

Commit 821be72

Browse files
committed
chore: documentation fixes and additions
1 parent 8b7d9d9 commit 821be72

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ for instance
114114
const lhs = { foo: 'bar', biz: { foo: 'baz' } };
115115
const rhs = { foo: 'bar', biz: { foo: 'buzz' } };
116116

117-
hrDiff(lhs, rhs, { prefilter: ['foo'] });
117+
const { diff } = new HumanDiff({ prefilter: ['foo'] });
118+
119+
diff(lhs, rhs);
118120
```
119121

120122
You would still see the diffs for `biz.foo` but you would ignore the diff for `foo`.
@@ -143,6 +145,8 @@ const prefilter = (path, key) => path[0] === 'foo' && key === 'bar';
143145

144146
## A Note On Arrays
145147

148+
> \*\*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.
149+
146150
`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.
147151

148152
```js
@@ -164,6 +168,17 @@ Consider the above arrays and their differences. A typical array diff would beha
164168

165169
This is much more understandable to a human brain. We've simply inserted a number at an index.
166170

171+
## Diff Memory
172+
173+
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.
174+
175+
```js
176+
const diffEngine = new HumanDiff();
177+
diffEngine.diff(lhs, rhs);
178+
179+
diffEngine.sentences; // -> same as the output of the last diff
180+
```
181+
167182
## Contributors
168183

169184
| Name | Website |

0 commit comments

Comments
 (0)