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

dom-serialize

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-serialize - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

7

History.md
1.2.1 / 2015-02-03
==================
* fix one-time callback functions on NodeLists / Arrays
* README: fix weird spacing
* README: add "inspect" example to readme
1.2.0 / 2015-02-02

@@ -3,0 +10,0 @@ ==================

18

index.js

@@ -45,7 +45,2 @@

if ('function' === typeof fn) {
// one-time "serialize" event listener
node.addEventListener('serialize', fn, false);
}
var rtn;

@@ -56,5 +51,10 @@ var nodeType = node.nodeType;

// assume it's a NodeList or Array of Nodes
rtn = exports.serializeNodeList(node, context);
rtn = exports.serializeNodeList(node, context, fn);
} else {
if ('function' === typeof fn) {
// one-time "serialize" event listener
node.addEventListener('serialize', fn, false);
}
// emit a custom "serialize" event on `node`, in case there

@@ -113,6 +113,6 @@ // are event listeners for custom serialization of this node

}
}
if ('function' === typeof fn) {
node.removeEventListener('serialize', fn, false);
if ('function' === typeof fn) {
node.removeEventListener('serialize', fn, false);
}
}

@@ -119,0 +119,0 @@

{
"name": "dom-serialize",
"version": "1.2.0",
"version": "1.2.1",
"description": "Serializes any DOM node into a String",

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

@@ -41,5 +41,6 @@ dom-serialize

// works with Text nodes
node= document.createTextNode('foo & <bar>');
node = document.createTextNode('foo & <bar>');
console.log(serialize(node));
// works with DOM elements

@@ -51,2 +52,3 @@ node = document.createElement('body');

// custom "serialize" event

@@ -57,2 +59,14 @@ node.firstChild.addEventListener('serialize', function (event) {

console.log(serialize(node));
// you can also just pass a function in for a one-time serializer
console.log(serialize(node, function (event) {
if (event.target === node.firstChild) {
// for the first child, output an ellipsis to summarize "content"
event.detail.serialze = '…';
} else if (event.target !== node) {
// any other child
event.preventDefault();
}
}));
```

@@ -64,2 +78,3 @@

<body>pwn</body>
<body>…</body>
```

@@ -230,4 +230,25 @@

it('should support one-time callback function on NodeLists', function () {
node = document.createElement('div');
node.appendChild(document.createElement('strong'));
node.appendChild(document.createTextNode('foo'));
node.appendChild(document.createElement('em'));
node.appendChild(document.createTextNode('bar'));
var count = 0;
function callback (e) {
count++;
e.detail.serialize = count;
}
assert.equal(0, count);
assert.equal('1234', serialize(node.childNodes, callback));
assert.equal(4, count);
assert.equal('<strong></strong>foo<em></em>bar', serialize(node.childNodes));
assert.equal(4, count);
});
});
});
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