dmsnell / diff-match-patch

Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.
Apache License 2.0
23 stars 5 forks source link

Javascript: Add iterable instance to Diff for destructuring. #9

Closed dmsnell closed 4 months ago

dmsnell commented 4 months ago

Resolves Google/diff-match-patch#39

It can be useful to extract Diff elements using destructuring assignment. For example:

const a = dmp.diff_main('abc', 'ab123c', false);
const [eq, str] = a[0];

Because the Diff object is not an array, however, this is not possible, even though it acts like an array.

In this patch a new Symbol.iterator method is added to the Diff class so that this pattern can be used.

Props: @JackuB, @GrosSacASac, @TheSpyder

TheSpyder commented 4 months ago

oh I was about to add this to my PR 😂 thank you 👍

dmsnell commented 4 months ago

oh I was about to add this to my PR 😂 thank you 👍

we were talking back and forth and I figured that instead of asking you to do so I might as well just push it out. what's the point of having a fork if you don't push through your own work? 🙃