1.1.1 • Published 6 years ago
@swimyoung/dom-serialization v1.1.1
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));