1.1.1 • Published 6 years ago

@swimyoung/dom-serialization v1.1.1

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

DOM Serialization

Encode the DOM and decode from the encoded code.

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

domSerialization encodes the DOM with keeping tree structure. So when you decode you can keep tree structure.

Getting started

npm install @swimyoung/dom-serialization
import { encode, decode } from '@swimyoung/dom-serialization';

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

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

6 years ago

1.0.0

7 years ago