kpdecker/jsdiff — pull request #22 by papandreou (2013-09-11 20:59:48+00:00)
Title: Added variant of WordDiff that doesn't ignore whitespace differences

Right now mocha uses the `DiffWords` algorithm to back its string diffs feature: http://tjholowaychuk.com/post/18574009869/mocha-string-diffs

However, the fact that `DiffWords` ignores whitespace differences makes it extremely hard to debug problems with differences in eg. line endings:

```javascript
require('diff').diffWords('foo\nbar', 'foo\r\nbar');
[ { value: 'foo\r\nbar',
added: undefined,
removed: undefined } ]
```

... because that makes the test framework render the text without any added/removed text highlighted.

`DiffChar` doesn't suffer from this problem, but for long texts it's very hard to make sense of a char-based diff, so there's a use case for a mode that diffs word-by-word, but doesn't ignore whitespace differences. Turns out that was extremely easy to achieve, so this PR gives you:

```javascript
> require('diff').diffWordsWithSpace('foo\nbar', 'foo\r\nbar');
[ { value: 'foo',
added: undefined,
removed: undefined },
{ value: '\r\n',
added: true,
removed: undefined },
{ value: '\n',
added: undefined,
removed: true },
{ value: 'bar',
added: undefined,
removed: undefined } ]
```

Seems like vows has the same issue: https://github.com/cloudhead/vows/issues/281