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.2.2 to 1.3.0

46

diff.js

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

(function(global, undefined) {
var JsDiff = (function() {

@@ -178,3 +179,3 @@ /*jshint maxparams: 5*/

// Performs the length of edit iteration. Is a bit fugly as this has to support the
// Performs the length of edit iteration. Is a bit fugly as this has to support the
// sync and async mode which is never fun. Loops over execEditLength until a value

@@ -261,14 +262,30 @@ // is produced.

var LineDiff = new Diff();
LineDiff.tokenize = function(value) {
var TrimmedLineDiff = new Diff();
TrimmedLineDiff.ignoreTrim = true;
LineDiff.tokenize = TrimmedLineDiff.tokenize = function(value) {
var retLines = [],
lines = value.split(/^/m);
for(var i = 0; i < lines.length; i++) {
var line = lines[i],
lastLine = lines[i - 1];
lastLine = lines[i - 1],
lastLineLastChar = lastLine ? lastLine[lastLine.length - 1] : '';
// Merge lines that may contain windows new lines
if (line === '\n' && lastLine && lastLine[lastLine.length - 1] === '\r') {
retLines[retLines.length - 1] += '\n';
if (line === '\n' && (lastLineLastChar === '\r' || lastLineLastChar === '\n')) {
if (this.ignoreTrim || lastLineLastChar === '\n'){
//to avoid merging to \n\n, remove \n and add \r\n.
retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0,-1) + '\r\n';
} else {
retLines[retLines.length - 1] += '\n';
}
} else if (line) {
if (this.ignoreTrim) {
line = line.trim();
//add a newline unless this is the last line.
if (i < lines.length - 1) {
line += '\n';
}
}
retLines.push(line);

@@ -281,2 +298,3 @@ }

var SentenceDiff = new Diff();

@@ -351,2 +369,4 @@ SentenceDiff.tokenize = function (value) {

diffLines: function(oldStr, newStr, callback) { return LineDiff.diff(oldStr, newStr, callback); },
diffTrimmedLines: function(oldStr, newStr, callback) { return TrimmedLineDiff.diff(oldStr, newStr, callback); },
diffSentences: function(oldStr, newStr, callback) { return SentenceDiff.diff(oldStr, newStr, callback); },

@@ -455,3 +475,3 @@

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

@@ -465,13 +485,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] === '\\') {
} 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;

@@ -486,3 +506,3 @@ }

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;

@@ -489,0 +509,0 @@ }

{
"name": "diff",
"version": "1.2.2",
"version": "1.3.0",
"description": "A javascript text diff implementation.",

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

@@ -36,2 +36,6 @@ # jsdiff

* `JsDiff.diffTrimmedLines(oldStr, newStr[, callback])` - diffs two blocks of text, comparing line by line, ignoring leading and trailing whitespace.
Returns a list of change objects (See below).
* `JsDiff.diffSentences(oldStr, newStr[, callback])` - diffs two blocks of text, comparing sentence by sentence.

@@ -170,2 +174,1 @@

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/kpdecker/jsdiff/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
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