0.0.1 • Published 6 years ago

dom-serial v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

domSerial

Serialization of dom. You can encode dom and decode.

Q. Why don't you use innerHTML?

: when you use innerHTML you lose tree structure if there are adjacent text nodes.

            span
          /       \
  text node       text node

domSerial encodes dom with keeping tree structure. So when you decode you can keep tree structure.

Getting started

npm install dom-serial

ES Module

import { encode, decode } from 'dom-serial';

const dom = document.createElement('div');
dom.appendChild(document.createTextNode('hello'));
dom.appendChild(document.createTextNode('world'));

const code = encode(dom);
console.log(decode(code));

UMD

<script src="node_modules/dom-text/dist/domSerial.js"></script>

<script>
  const dom = document.createElement('div');
  dom.appendChild(document.createTextNode('hello'));
  dom.appendChild(document.createTextNode('world'));

  const code = domSerial.encode(dom);
  console.log(domSerial.decode(code));
</script>
0.0.1

6 years ago

0.0.0

6 years ago