# swapdom

> Fast & tiny DOM swapper.

Latest version **1.2.1** (published 2024-03-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install swapdom
pnpm add swapdom
yarn add swapdom
bun add swapdom
```

## 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.1 |
| Published | 2024-03-11 |
| First published | 2022-01-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 44.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Dmitry Iv |
| Maintainers | dy |
| Keywords | domdiff, domswap, dom, swap, snabbdom, heckel, morphdom |

## Links

- npm: https://www.npmjs.com/package/swapdom
- Repository: https://github.com/spectjs/swapdom
- Homepage: https://github.com/spectjs/swapdom#readme
- Issues: https://github.com/spectjs/swapdom/issues
- npm.io page: https://npm.io/package/swapdom

## 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.1 (latest) — 2024-03-11
- 1.2.0 — 2024-03-10
- 1.1.1 — 2022-01-15
- 1.1.0 — 2022-01-14
- 1.0.0 — 2022-01-14

## README

# swapdom [![test](https://github.com/spectjs/swapdom/actions/workflows/test.yml/badge.svg)](https://github.com/spectjs/swapdom/actions/workflows/test.yml) [![npm version](https://img.shields.io/npm/v/swapdom)](http://npmjs.org/swapdom)

> Fast & tiny DOM swapper.

```js
import swap from 'swapdom'

swap(parentNode, oldNodes, newNodes, endNode)
```

`deflate.js` strategy is smaller (248b), but a bit slower on some cases and doesn't support live collections.<br/>
`inflate.js` strategy is bigger (318b), but faster and supports live collections.

Provide custom mutators as:
```js
swap.same = (a,b) => a?.isSameNode(b)
swap.replace = (a,b, parent) => a.replaceWith(b)
swap.insert = (a,b, parent) => a ? a.before(b) : parent.append(b)
swap.remove = (a, parent) => a.remove()
```

See [benchmark](https://github.com/luwes/js-diff-benchmark) (it's called _spect_ there).

## Alternatives

* [list-difference objects](https://github.com/paldepind/list-difference/blob/master/index.js)
* [list-difference maps](https://github.com/luwes/js-diff-benchmark/blob/master/libs/list-difference.js)

<p align="center">ॐ</p>

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