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 2.0.1 to 2.1.0

9

History.md
2.1.0 / 2015-02-10
==================
* if `e.detail.serialize` is set and the event is cancelled, still use the `e.detail.serialize` value
* attempting to get 100% test code coverage
* package: allow any "zuul" v1
* test: add HTML5 Doctype test, for 100% test code coverage!
* test: remove `console.log()` call
2.0.1 / 2015-02-03

@@ -3,0 +12,0 @@ ==================

81

index.js

@@ -73,44 +73,43 @@

var target = eventTarget || node;
if (target.dispatchEvent(e)) {
var cancelled = !target.dispatchEvent(e);
// `e.detail.serialize` can be set to a:
// String - returned directly
// Node - goes through serializer logic instead of `node`
// Anything else - get Stringified first, and then returned directly
var s = e.detail.serialize;
if (s != null) {
if ('string' === typeof s) {
rtn = s;
} else if ('number' === typeof s.nodeType) {
// make it go through the serialization logic
rtn = serialize(s, context, null, target);
} else {
rtn = String(s);
}
// `e.detail.serialize` can be set to a:
// String - returned directly
// Node - goes through serializer logic instead of `node`
// Anything else - get Stringified first, and then returned directly
var s = e.detail.serialize;
if (s != null) {
if ('string' === typeof s) {
rtn = s;
} else if ('number' === typeof s.nodeType) {
// make it go through the serialization logic
rtn = serialize(s, context, null, target);
} else {
// default serialization logic
switch (nodeType) {
case 1 /* element */:
rtn = exports.serializeElement(node, context, eventTarget);
break;
case 2 /* attribute */:
rtn = exports.serializeAttribute(node);
break;
case 3 /* text */:
rtn = exports.serializeText(node);
break;
case 8 /* comment */:
rtn = exports.serializeComment(node);
break;
case 9 /* document */:
rtn = exports.serializeDocument(node, context, eventTarget);
break;
case 10 /* doctype */:
rtn = exports.serializeDoctype(node);
break;
case 11 /* document fragment */:
rtn = exports.serializeDocumentFragment(node, context, eventTarget);
break;
}
rtn = String(s);
}
} else if (!cancelled) {
// default serialization logic
switch (nodeType) {
case 1 /* element */:
rtn = exports.serializeElement(node, context, eventTarget);
break;
case 2 /* attribute */:
rtn = exports.serializeAttribute(node);
break;
case 3 /* text */:
rtn = exports.serializeText(node);
break;
case 8 /* comment */:
rtn = exports.serializeComment(node);
break;
case 9 /* document */:
rtn = exports.serializeDocument(node, context, eventTarget);
break;
case 10 /* doctype */:
rtn = exports.serializeDoctype(node);
break;
case 11 /* document fragment */:
rtn = exports.serializeDocumentFragment(node, context, eventTarget);
break;
}
}

@@ -199,11 +198,15 @@

var r = '<!DOCTYPE ' + node.name;
if (node.publicId) {
r += ' PUBLIC "' + node.publicId + '"';
}
if (!node.publicId && node.systemId) {
r += ' SYSTEM';
}
if (node.systemId) {
r += ' "' + node.systemId + '"';
}
r += '>';

@@ -210,0 +213,0 @@ return r;

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

@@ -32,4 +32,4 @@ "main": "index.js",

"devDependencies": {
"zuul": "~1.16.3"
"zuul": "1"
}
}

@@ -93,2 +93,25 @@

it('should serialize a Doctype node with systemId', function () {
node = document.implementation.createDocumentType(
'root-element',
'',
'http://www.w3.org/1999/xhtml'
);
document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'root-element', node);
assert.equal('<!DOCTYPE root-element SYSTEM "http://www.w3.org/1999/xhtml">', serialize(node));
});
it('should serialize an HTML5 Doctype node', function () {
node = document.implementation.createDocumentType(
'html',
'',
''
);
document.implementation.createDocument('http://www.w3.org/1999/xhtml', 'node', node);
assert.equal('<!DOCTYPE html>', serialize(node));
});
it('should serialize a DocumentFragment node', function () {

@@ -175,2 +198,17 @@ node = document.createDocumentFragment();

it('should render a Node when set as `e.detail.serialize` and event is cancelled', function () {
node = document.createTextNode('whaaaaa!!!!!!');
var count = 0;
node.addEventListener('serialize', function (e) {
count++;
if (count === 1) {
e.preventDefault();
e.detail.serialize = document.createTextNode('foo');
}
});
assert.equal(0, count);
assert.equal('foo', serialize(node));
assert.equal(2, count);
});
it('should have `context` set on the event', function () {

@@ -294,4 +332,2 @@ node = document.createTextNode('');

count++;
console.log(e.serializeTarget);
if (e.serializeTarget.nodeValue === 'foo') {

@@ -298,0 +334,0 @@ var el = document.createElement('p');

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