Socket
Socket
Sign inDemoInstall

diff

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

87

diff.js

@@ -5,3 +5,3 @@ /* See LICENSE file for terms of use */

* Text diff implementation.
*
*
* This library supports the following APIS:

@@ -11,5 +11,5 @@ * JsDiff.diffChars: Character by character diff

* JsDiff.diffLines: Line based diff
*
*
* JsDiff.diffCss: Diff targeted at CSS content
*
*
* These methods are based on the implementation proposed in

@@ -20,2 +20,3 @@ * "An O(ND) Difference Algorithm and its Variations" (Myers, 1986).

var JsDiff = (function() {
/*jshint maxparams: 5*/
function clonePath(path) {

@@ -35,6 +36,6 @@ return { newPos: path.newPos, components: path.components.slice(0) };

var n = s;
n = n.replace(/&/g, "&");
n = n.replace(/</g, "&lt;");
n = n.replace(/>/g, "&gt;");
n = n.replace(/"/g, "&quot;");
n = n.replace(/&/g, '&amp;');
n = n.replace(/</g, '&lt;');
n = n.replace(/>/g, '&gt;');
n = n.replace(/"/g, '&quot;');

@@ -44,9 +45,9 @@ return n;

var fbDiff = function(ignoreWhitespace) {
var Diff = function(ignoreWhitespace) {
this.ignoreWhitespace = ignoreWhitespace;
};
fbDiff.prototype = {
Diff.prototype = {
diff: function(oldString, newString) {
// Handle the identity case (this is due to unrolling editLength == 0
if (newString == oldString) {
if (newString === oldString) {
return [{ value: newString }];

@@ -146,3 +147,3 @@ }

} else {
return left == right;
return left === right;
}

@@ -158,5 +159,5 @@ },

var CharDiff = new fbDiff();
var CharDiff = new Diff();
var WordDiff = new fbDiff(true);
var WordDiff = new Diff(true);
WordDiff.tokenize = function(value) {

@@ -166,3 +167,3 @@ return removeEmpty(value.split(/(\s+|\b)/));

var CssDiff = new fbDiff(true);
var CssDiff = new Diff(true);
CssDiff.tokenize = function(value) {

@@ -172,3 +173,3 @@ return removeEmpty(value.split(/([{}:;,]|\s+)/));

var LineDiff = new fbDiff();
var LineDiff = new Diff();
LineDiff.tokenize = function(value) {

@@ -179,2 +180,4 @@ return value.split(/^/m);

return {
Diff: Diff,
diffChars: function(oldStr, newStr) { return CharDiff.diff(oldStr, newStr); },

@@ -189,6 +192,6 @@ diffWords: function(oldStr, newStr) { return WordDiff.diff(oldStr, newStr); },

ret.push("Index: " + fileName);
ret.push("===================================================================");
ret.push("--- " + fileName + (typeof oldHeader === "undefined" ? "" : "\t" + oldHeader));
ret.push("+++ " + fileName + (typeof newHeader === "undefined" ? "" : "\t" + newHeader));
ret.push('Index: ' + fileName);
ret.push('===================================================================');
ret.push('--- ' + fileName + (typeof oldHeader === 'undefined' ? '' : '\t' + oldHeader));
ret.push('+++ ' + fileName + (typeof newHeader === 'undefined' ? '' : '\t' + newHeader));

@@ -199,3 +202,3 @@ var diff = LineDiff.diff(oldStr, newStr);

}
diff.push({value: "", lines: []}); // Append an empty value to make cleanup easier
diff.push({value: '', lines: []}); // Append an empty value to make cleanup easier

@@ -220,3 +223,3 @@ function contextLines(lines) {

var current = diff[i],
lines = current.lines || current.value.replace(/\n$/, "").split("\n");
lines = current.lines || current.value.replace(/\n$/, '').split('\n');
current.lines = lines;

@@ -236,3 +239,3 @@

}
curRange.push.apply(curRange, lines.map(function(entry) { return (current.added?"+":"-") + entry; }));
curRange.push.apply(curRange, lines.map(function(entry) { return (current.added?'+':'-') + entry; }));
eofNL(curRange, i, current);

@@ -255,5 +258,5 @@

ret.push(
"@@ -" + oldRangeStart + "," + (oldLine-oldRangeStart+contextSize)
+ " +" + newRangeStart + "," + (newLine-newRangeStart+contextSize)
+ " @@");
'@@ -' + oldRangeStart + ',' + (oldLine-oldRangeStart+contextSize)
+ ' +' + newRangeStart + ',' + (newLine-newRangeStart+contextSize)
+ ' @@');
ret.push.apply(ret, curRange);

@@ -277,3 +280,3 @@ ret.push.apply(ret, contextLines(lines.slice(0, contextSize)));

applyPatch: function(oldStr, uniDiff) {
var diffstr = uniDiff.split("\n");
var diffstr = uniDiff.split('\n');
var diff = [];

@@ -283,4 +286,4 @@ var remEOFNL = false,

for (var i = (diffstr[0][0]=="I"?4:0); i < diffstr.length; i++) {
if(diffstr[i][0] == "@") {
for (var i = (diffstr[0][0]==='I'?4:0); i < diffstr.length; i++) {
if(diffstr[i][0] === '@') {
var meh = diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);

@@ -294,13 +297,13 @@ diff.unshift({

});
} else if(diffstr[i][0] == '+') {
} else if(diffstr[i][0] === '+') {
diff[0].newlines.push(diffstr[i].substr(1));
} else if(diffstr[i][0] == '-') {
} else if(diffstr[i][0] === '-') {
diff[0].oldlines.push(diffstr[i].substr(1));
} else if(diffstr[i][0] == ' ') {
} else if(diffstr[i][0] === ' ') {
diff[0].newlines.push(diffstr[i].substr(1));
diff[0].oldlines.push(diffstr[i].substr(1));
} else if(diffstr[i][0] == '\\') {
if (diffstr[i-1][0] == '+') {
} else if(diffstr[i][0] === '\\') {
if (diffstr[i-1][0] === '+') {
remEOFNL = true;
} else if(diffstr[i-1][0] == '-') {
} else if(diffstr[i-1][0] === '-') {
addEOFNL = true;

@@ -311,7 +314,7 @@ }

var str = oldStr.split("\n");
var str = oldStr.split('\n');
for (var i = diff.length - 1; i >= 0; i--) {
var d = diff[i];
for (var j = 0; j < d.oldlength; j++) {
if(str[d.start-1+j] != d.oldlines[j]) {
if(str[d.start-1+j] !== d.oldlines[j]) {
return false;

@@ -338,5 +341,5 @@ }

if (change.added) {
ret.push("<ins>");
ret.push('<ins>');
} else if (change.removed) {
ret.push("<del>");
ret.push('<del>');
}

@@ -347,8 +350,8 @@

if (change.added) {
ret.push("</ins>");
ret.push('</ins>');
} else if (change.removed) {
ret.push("</del>");
ret.push('</del>');
}
}
return ret.join("");
return ret.join('');
},

@@ -368,4 +371,4 @@

if (typeof module !== "undefined") {
if (typeof module !== 'undefined') {
module.exports = JsDiff;
}
{
"name": "diff",
"version": "1.0.4",
"version": "1.0.5",
"description": "A javascript text diff implementation.",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc