
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
myers-diff
Advanced tools
A JavaScript test differentiation implementation based on An O(ND) Difference Algorithm and Its Variations (1986). It is a lightweight, low-level, no-frills library that can be used to build bulkier viewers.
$ npm install myers-diff
With basic usage:
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:
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:
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;
}
}
myers
Compare lhs text to rhs text. Changes are compared from left to right such that items are deleted from left or added to right.
lhs <string> - The left-hand side text to compare.rhs <string> - The right-hand side text to compare.options <object> - Diff options.
<Change[]> - Returns an array of Change.An object that describes a change occurrence between the left-hand text and right-hand text.
lhs <LeftPart>- Describes the left-hand change.rhs <RightPart> - Describes the right-hand change.Describes a left-hand change occurrence.
at <number> - The part item identifier. When comparing lines, it is the n-th line; when comparing words, it is the n-th word; when comparing chars, it is the n-th char.del <number> - The number of parts deleted from the left. When comparing lines, it is the number of lines deleted; when comparing words, it is the number of words deleted; when comparing chars, it is the number of chars deleted.pos <number> - The zero-based character position of the part from the original text.text <string> - The text that was changed.length <number> - The number of characters.Describes a right-hand change occurrence.
at <number> - The part item identifier. When comparing lines, it is the n-th line; when comparing words, it is the n-th word; when comparing chars, it is the n-th char.add <number> - The number of parts added from the right. When comparing lines, it is the number of lines added; when comparing words, it is the number of words added; when comparing chars, it is the number of chars added.pos <number> - The zero-based character position of the part from the original text.text <string> - The text that was changed.length <number> - The number of characters.Formatting functions.
Formats an array of Change in GNU Normal Format.
changes <Change[]> - An array of changes from myers.diff.<string> The diff text.Examines the LeftPart or RightPart part to determine if was changed. It is possible for a Change to only affect one side or the other, or both. If changed, it returns true, otherwise, it returns false.
FAQs
Implementation of the longest common subsequence (diff) algorithm.
The npm package myers-diff receives a total of 13,177 weekly downloads. As such, myers-diff popularity was classified as popular.
We found that myers-diff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.