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

diff-dom

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diff-dom - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

2

bower.json
{
"name": "diff-dom",
"main": "diffDOM.js",
"version": "1.0.0",
"version": "1.1.0",
"homepage": "https://github.com/fiduswriter/diffDOM",

@@ -6,0 +6,0 @@ "authors": [

@@ -66,3 +66,55 @@ (function () {

var roughlyEqual = function roughlyEqual(e1, e2, preventRecursion) {
var elementDescriptors = function(el) {
var output = [];
if (el.nodeType == 1) {
output.push(el.tagName);
if (typeof(el.className) == 'string') {
output.push(el.tagName + '.' + el.className.replace(/ /g, '.'));
}
if (el.id) {
output.push(el.tagName + '#' + el.id);
}
}
return output;
}
var findUniqueDescriptors = function(li) {
var uniqueDescriptors = {};
var duplicateDescriptors = {};
for (var i = 0; i < li.length; i++) {
var node = li[i];
var descriptors = elementDescriptors(node);
for (var j = 0; j < descriptors.length; j++) {
var descriptor = descriptors[j];
var inUnique = descriptor in uniqueDescriptors;
var inDupes = descriptor in duplicateDescriptors;
if (!inUnique && !inDupes) {
uniqueDescriptors[descriptor] = true;
} else if (inUnique) {
delete uniqueDescriptors[descriptor];
duplicateDescriptors[descriptor] = true;
}
}
}
return uniqueDescriptors;
}
var uniqueInBoth = function(l1, l2) {
var l1Unique = findUniqueDescriptors(l1);
var l2Unique = findUniqueDescriptors(l2);
var inBoth = {};
var key;
for (key in l1Unique) {
if (l2Unique[key]) {
inBoth[key] = true;
}
}
return inBoth;
}
var roughlyEqual = function roughlyEqual(e1, e2, uniqueDescriptors, sameSiblings, preventRecursion) {
if (!e1 || !e2) return false;

@@ -78,4 +130,17 @@ if (e1.nodeType !== e2.nodeType) return false;

if (e1.nodeName !== e2.nodeName) return false;
if (e1.tagName === e2.tagName) {
if (e1.tagName in uniqueDescriptors) return true
if (e1.id && e1.id === e2.id) {
var idDescriptor = e1.tagName + '#' + e1.id;
if (idDescriptor in uniqueDescriptors) return true;
}
if (e1.className && e1.className === e2.className) {
var classDescriptor = e1.tagName + '.' + e1.className.replace(/ /g, '.');
if (classDescriptor in uniqueDescriptors) return true;
}
if (sameSiblings) return true;
}
if (e1.childNodes.length !== e2.childNodes.length) return false;
var thesame = true;
var childUniqueDescriptors = uniqueInBoth(e1.childNodes, e2.childNodes);
for (var i = e1.childNodes.length - 1; i >= 0; i--) {

@@ -87,3 +152,3 @@ if (preventRecursion) {

// was not set, we must explicitly force it to true for child iterations.
thesame = thesame && roughlyEqual(e1.childNodes[i], e2.childNodes[i], true);
thesame = thesame && roughlyEqual(e1.childNodes[i], e2.childNodes[i], childUniqueDescriptors, true, true);
}

@@ -213,10 +278,37 @@ }

var matches = [],
a, i, j;
a, i, j, k, l;
for (a = 0; a < len1 + 1; a++) {
matches[a] = [];
}
var uniqueDescriptors = uniqueInBoth(c1, c2);
// If all of the elements are the same tag, id and class, then we can
// consider them roughly the same even if they have a different number of
// children. This will reduce removing and re-adding similar elements.
var subsetsSame = len1 == len2;
if (subsetsSame) {
for (k = 0; k < len1; k++) {
var c1Desc = elementDescriptors(c1[k]);
var c2Desc = elementDescriptors(c2[k]);
if (c1Desc.length != c2Desc.length) {
subsetsSame = false;
break;
}
for (l = 0; l < c1Desc.length; l++) {
if (c1Desc[l] != c2Desc[l]) {
subsetsSame = false;
break;
}
}
if (!subsetsSame) {
break;
}
}
}
// fill the matches with distance values
for (i = 0; i < len1; i++) {
for (j = 0; j < len2; j++) {
if (!marked1[i] && !marked2[j] && roughlyEqual(c1[i], c2[j])) {
if (!marked1[i] && !marked2[j] && roughlyEqual(c1[i], c2[j], uniqueDescriptors, subsetsSame)) {
matches[i + 1][j + 1] = (matches[i][j] ? matches[i][j] + 1 : 1);

@@ -223,0 +315,0 @@ if (matches[i + 1][j + 1] > lcsSize) {

{
"name": "diff-dom",
"version": "1.0.0",
"version": "1.1.0",
"description": "A diff for DOM elements, as client-side JavaScript code. Gets all modifications, insertions and removals between two DOM fragments.",

@@ -5,0 +5,0 @@ "main": "diffDOM.js",

@@ -26,3 +26,3 @@ # diffDOM - A JavaScript diffing algorithm for DOM elements

```
var diffDOM = require("diffDOM");
var diffDOM = require("diff-dom");
```

@@ -29,0 +29,0 @@

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