# myers-diff
**Repository Path**: mirrors_wickedest/myers-diff
## Basic Information
- **Project Name**: myers-diff
- **Description**: A javascript test differentiation implementation based on An O(ND) Difference Algorithm and Its Variations (1986).
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 0
- **Created**: 2020-08-19
- **Last Updated**: 2025-06-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# myers-diff
A JavaScript test differentiation implementation based on [An O(ND) Difference Algorithm and Its Variations (1986)](www.xmailserver.org/diff2.pdf). It is a lightweight, low-level, no-frills library that can be used to build bulkier viewers.
## Installation
```bash
$ npm install myers-diff
```
## Getting started
With basic usage:
```js
const myers = require('myers-diff');
const lhs = 'the quick red fox jumped\nover the hairy dog';
const rhs = 'the quick brown fox jumped\nover the lazy dog';
const 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
```
With all options:
```js
const myers = require('myers-diff');
const lhs = 'the quick red fox jumped\nover the hairy dog';
const rhs = 'the quick brown fox jumped\nover the lazy dog';
const diff = myers.diff(lhs, rhs, {
compare: 'lines',
ignoreWhitespace: false,
ignoreCase: false,
ignoreAccents: false
});
```
For building visual editors:
```js
const { diff, changed } = require('myers-diff');
const lhs = 'the quick red fox jumped\nover the hairy dog';
const rhs = 'the quick brown fox jumped\nover the lazy dog';
const changes = diff(lhs, rhs);
for (const change of changes) {
if (changed(change.lhs)) {
// deleted
const { pos, text, del, length } = change.lhs;
}
if (changed(change.rhs)) {
// added
const { pos, text, add, length } = change.rhs;
}
}
```
## API
- `myers`
- [`myers.diff(lhs, rhs, [options])`](#diff)
- [`myers.formats`](#formats)
- [`GnuNormalFormat`](#formats-gnunormalformat)
- [`myers.changed(part)`](#changed)
- Types
- [`Change`](#change)
- [`LeftPart`](#leftpart)
- [`RightPart`](#rightpart)
### myers.diff(lhs, rhs, [options])
Compare `lhs` text to `rhs` text. `lhs` and `rhs` can also be an arbitrary array if `compare` is set to `'chars'`. Changes are compared from left to right such that items are deleted from left or added to right.
- `lhs` [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) - The left-hand side text to compare.
- `rhs` [``](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) - The right-hand side text to compare.
- `options` [`