dom-serialize

WebJar for dom-serialize

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

dom-serialize
Last Version

Last Version

2.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

dom-serialize
WebJar for dom-serialize
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/webmodules/dom-serialize

Download dom-serialize

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/dom-serialize/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>dom-serialize</artifactId>
    <version>2.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/dom-serialize/
implementation 'org.webjars.npm:dom-serialize:2.2.1'
// https://jarcasting.com/artifacts/org.webjars.npm/dom-serialize/
implementation ("org.webjars.npm:dom-serialize:2.2.1")
'org.webjars.npm:dom-serialize:jar:2.2.1'
<dependency org="org.webjars.npm" name="dom-serialize" rev="2.2.1">
  <artifact name="dom-serialize" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='dom-serialize', version='2.2.1')
)
libraryDependencies += "org.webjars.npm" % "dom-serialize" % "2.2.1"
[org.webjars.npm/dom-serialize "2.2.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.webjars.npm : custom-event jar [1.0.0,1.1)
org.webjars.npm : ent jar [2.2.0,2.3)
org.webjars.npm : extend jar [3.0.0,4)
org.webjars.npm : void-elements jar [2.0.0,3)

Project Modules

There are no modules declared in this project.

dom-serialize

Serializes any DOM node into a String

Sauce Test Status

Build Status

It's like outerHTML, but it works with:

  • DOM elements
  • Text nodes
  • Attributes
  • Comment nodes
  • Documents
  • DocumentFragments
  • Doctypes
  • NodeLists / Arrays

For custom serialization logic, a "serialize" event is dispatched on every Node which event listeners can override the default behavior on by setting the event.detail.serialize property to a String or other Node.

The "serialize" event bubbles, so it could be a good idea to utilize event delegation on a known root node that will be serialized. Check the event.serializeTarget property to check which Node is currently being serialized.

Installation

$ npm install dom-serialize

Example

var serialize = require('dom-serialize');
var node;

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


// works with DOM elements
node = document.createElement('body');
node.appendChild(document.createElement('strong'));
node.firstChild.appendChild(document.createTextNode('hello'));
console.log(serialize(node));


// custom "serialize" event
node.firstChild.addEventListener('serialize', function (event) {
  event.detail.serialize = 'pwn';
}, false);
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.serializeTarget === node.firstChild) {
    // for the first child, output an ellipsis to summarize "content"
    event.detail.serialze = '…';
  } else if (event.serializeTarget !== node) {
    // any other child
    event.preventDefault();
  }
}));
foo &amp; &lt;bar&gt;
<body><strong>hello</strong></body>
<body>pwn</body>
<body>…</body>
org.webjars.npm

webmodules

ES6 modules for web usage – on NPM

Versions

Version
2.2.1
2.2.0