/diff-compare

A line-by-line diffing tool that returns adjusted comparison texts

Primary LanguageJavaScriptOtherNOASSERTION

diff-compare

NPM NPM

Join the chat at https://gitter.im/therebelrobot/diff-compare js-standard-style Dependency Status semver changelog

A javascript library for diffing text and generating corrected and annotated text. This is a fork and derivative of ForbesLindesay/jsdifflib, which is in turn a fork of cemerick/jsdifflib

The main difference between this lib and ForbesLindesay/jsdifflib is jsdifflib returns an HTML node for direct embedding (a table no less), and this module just returns the adjusted text in a JS object. I was implementing a separate view system, so I just needed the data alone.

Installation

npm install diff-compare

Overview

diff-compare is a Javascript library that provides:

  1. a partial reimplementation of Python’s difflib module (specifically, the SequenceMatcher class)
  2. rather than a view generator, as the previous modules have made, this provides a corrected list of items, language agnostic

Example

var diff = require('diff-compare');

var adjustedText = diff.build({
  baseText: baseText,
  newText: newText
})

// {
//   base: [{
//       originalLine: 1,
//       value: 'abc',
//       type: 'delete'
//     }, {
//       originalLine: 2,
//       value: 'def',
//       type: 'equal'
//     }],
//   compare: [{
//       originalLine: null,
//       value: '',
//       type: 'delete'
//     }, {
//       originalLine: 1,
//       value: 'def',
//       type: 'equal'
//     }]
// }

Changelog

branch: master

Type Link Description

v1.0.2 | 2015-07-20

branch: release/v1.0.2

Type Link Description
Added e66bd85 Added badges and changelog to Readme

v1.0.1 | 2015-07-20

branch: release/v1.0.1

Type Link Description
Added 6aa50a7 Added badges
Changed 6aa50a7 Refactored build opts keys
Fixed a371e21 Code Climate CLI issue

v1.0.0 | 2015-07-14

branch: release/v1.0.0

Type Link Description
Added Initial Release - Converted HTML output to pure JS output

License

Dual License: BSD + ISC