# dom-serialization

> Serialize the DOM

Latest version **1.2.0** (published 2021-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install dom-serialization
pnpm add dom-serialization
yarn add dom-serialization
bun add dom-serialization
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2021-04-05 |
| First published | 2019-03-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Youngjin Jang |
| Maintainers | swimyoung |
| Keywords | dom, serialization |

## Links

- npm: https://www.npmjs.com/package/dom-serialization
- Repository: https://github.com/swimyoung/dom-serialization
- Homepage: https://github.com/swimyoung/dom-serialization#readme
- Issues: https://github.com/swimyoung/dom-serialization/issues
- npm.io page: https://npm.io/package/dom-serialization

## Dependencies (1)

- [dom-node-type](https://npm.io/package/dom-node-type.md) 1.1.1

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2021-04-05
- 1.1.1 — 2020-06-18
- 1.1.0 — 2019-12-17
- 1.0.2 — 2019-07-27
- 1.0.1 — 2019-06-23
- 1.0.0 — 2019-03-30

## README

# DOM Serialization

Serialize the DOM

Q. Why don't you use innerHTML?

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

```txt
            span
          /       \
  text node       text node
```

dom-serialization serialize the DOM with keeping tree structure. So you can keep tree structure when you deserialize from serialized string.

## Getting started

```sh
npm install dom-serialization
```

```js
import { serialize, deserialize } from 'dom-serialization';

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

const code = serialize(dom);
console.log(deserialize(code));
```

---
_Source: https://npm.io/package/dom-serialization · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
