JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7347
  • Score
    100M100P100Q144143F
  • License Apache-2.0

Implementation of the longest common subsequence (diff) algorithm.

Package Exports

  • myers-diff

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (myers-diff) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

myers-diff

A javascript test differentiation implementation based on An O(ND) Difference Algorithm and Its Variations (1986). It is a lightweight, no-frills implementation.

Installation

npm install myers-diff

or bower install myers-diff

Example

const myers = require('myers-diff').default;

var lhs = 'the quick red fox jumped\nover the hairy dog',
    rhs = 'the quick brown fox jumped\nover the lazy dog',
    diff;

diff = myers.diff(lhs, rhs, {});

console.log(myers.formats.GnuNormalFormat(diff));
console.log(diff);
//
// 1,2c1,2
// < the quick red fox jumped
// < over the hairy dog
// ---
// > the quick brown fox jumped
// > over the lazy dog

API

myers.diff ( lhs, rhs, options )

Compare lhs text to rhs text and returns a list of Change items between them. The Change item is defined as:

Change: {
    lhs: {
        at: line_number,    // zero-based index
        del: count          // >= 0,
        ctx: context        // diff Context
    },
    rhs: {
        at: line_number,    // zero-based index
        add: count          // >= 0,
        ctx: context        // diff Context
    }
}

The options are defined as follows:

options: {
    compare: 'lines',           // lines|words|chars
    ignoreWhitespace: false,    // ignores white space
    splitLinesRegex: '\n',      // the regex to use when splitting lines
    splitWordsRegex: '[ ]{1}',  // the regex to use when splitting words
    splitCharsRegex: ''         // the regex to use when splitting chars
}

Interpreting a Change item is as follows:

del add description
0 >0 added count to rhs
>0 0 deleted count from lhs
>0 >0 changed count lines

Context.getLine ( n )

Gets the value of line at zer-based index n.