Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-diff

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-diff - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

40

diff.js

@@ -85,2 +85,3 @@ /**

}
diffs = fix_emoji(diffs);
return diffs;

@@ -675,3 +676,42 @@ };

}
}
/*
* Check diff did not split surrogate pairs.
* Ex. [0, '\uD83D'], [-1, '\uDC36'], [1, '\uDC2F'] -> [-1, '\uD83D\uDC36'], [1, '\uD83D\uDC2F']
* '\uD83D\uDC36' === '🐶', '\uD83D\uDC2F' === '🐯'
*
* @param {Array} diffs Array of diff tuples
* @return {Array} Array of diff tuples
*/
function fix_emoji (diffs) {
var compact = false;
var starts_with_pair_end = function(str) {
return str.charCodeAt(0) >= 0xDC00 && str.charCodeAt(0) <= 0xDFFF;
}
var ends_with_pair_start = function(str) {
return str.charCodeAt(str.length-1) >= 0xD800 && str.charCodeAt(str.length-1) <= 0xDBFF;
}
for (var i = 2; i < diffs.length; i += 1) {
if (diffs[i-2][0] === DIFF_EQUAL && ends_with_pair_start(diffs[i-2][1]) &&
diffs[i-1][0] === DIFF_DELETE && starts_with_pair_end(diffs[i-1][1]) &&
diffs[i][0] === DIFF_INSERT && starts_with_pair_end(diffs[i][1])) {
compact = true;
diffs[i-1][1] = diffs[i-2][1].slice(-1) + diffs[i-1][1];
diffs[i][1] = diffs[i-2][1].slice(-1) + diffs[i][1];
diffs[i-2][1] = diffs[i-2][1].slice(0, -1);
}
}
if (!compact) {
return diffs;
}
var fixed_diffs = [];
for (var i = 0; i < diffs.length; i += 1) {
if (diffs[i][1].length > 0) {
fixed_diffs.push(diffs[i]);
}
}
return fixed_diffs;
}

@@ -678,0 +718,0 @@

2

package.json
{
"name": "fast-diff",
"version": "1.1.1",
"version": "1.1.2",
"description": "Fast Javascript text diff",

@@ -5,0 +5,0 @@ "author": "Jason Chen <jhchen7@gmail.com>",

@@ -52,2 +52,41 @@ var _ = require('lodash');

console.log('Running emoji tests');
(function() {
var result = diff('🐶', '🐯');
var expected = [
[diff.DELETE, '🐶'],
[diff.INSERT, '🐯'],
];
if (!_.isEqual(result, expected)) {
console.log(result, '!==', expected);
throw new Error('Emoji simple case test failed');
}
})();
(function() {
var result = diff('👨🏽', '👩🏽');
var expected = [
[diff.DELETE, '👨'],
[diff.INSERT, '👩'],
[diff.EQUAL, '🏽']
];
if (!_.isEqual(result, expected)) {
console.log(result, '!==', expected);
throw new Error('Emoji before case test failed');
}
})();
(function() {
var result = diff('👩🏼', '👩🏽');
var expected = [
[diff.EQUAL, '👩'],
[diff.DELETE, '🏼'],
[diff.INSERT, '🏽'],
];
if (!_.isEqual(result, expected)) {
console.log(result, '!==', expected);
throw new Error('Emoji after case test failed');
}
})();
console.log("Success!");
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