# udomdiff

> An essential diffing algorithm for µhtml

Latest version **1.1.2** (published 2024-11-27) · ISC license · 0 weekly downloads

## Install

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

## Health

**Score 40/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2024-11-27 |
| First published | 2020-02-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 162 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | domdiff, smaller, subset, uhtml |

## Links

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

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2024-11-27
- 1.1.1 — 2024-11-13
- 1.1.0 — 2020-04-15
- 1.0.11 — 2020-04-04
- 1.0.10 — 2020-03-30
- 1.0.9 — 2020-03-07
- 1.0.8 — 2020-03-04
- 1.0.7 — 2020-03-03
- 1.0.6 — 2020-03-02
- 1.0.5 — 2020-03-02
- 1.0.4 — 2020-03-02
- 1.0.3 — 2020-03-02
- 1.0.2 — 2020-03-02
- 1.0.1 — 2020-03-02
- 1.0.0 — 2020-03-01
- … 3 more at https://npm.io/package/udomdiff/versions

## README

# <em>µ</em>domdiff

[![Build Status](https://travis-ci.com/WebReflection/udomdiff.svg?branch=master)](https://travis-ci.com/WebReflection/udomdiff) [![Coverage Status](https://coveralls.io/repos/github/WebReflection/udomdiff/badge.svg?branch=master)](https://coveralls.io/github/WebReflection/udomdiff?branch=master)

![a different tree](./udomdiff-head.jpg)

<sup>**Social Media Photo by [Christopher Rusev](https://unsplash.com/@ralics) on [Unsplash](https://unsplash.com/)**</sup>

An essential diffing algorithm for [µhtml](https://github.com/WebReflection/uhtml#readme).


### Signature

```js
futureNodes = udomdiff(
  parentNode,           // where changes happen
  [...currentNodes],    // Array of current items/nodes
  [...futureNodes],     // Array of future items/nodes (returned)
  get(node, toDoWhat),  // a callback to retrieve the node
  before                // the anchored node to insertBefore
);
```

### What is `get` and how does it work?

You can find all info from [domdiff](https://github.com/WebReflection/domdiff#a-node-generic-info--node-callback-for-complex-data), as it's exactly the same concept:

  * `get(node, 1)` to retrieve the node that's being appended
  * `get(node, 0)` to get the node to use for an `insertBefore` operation
  * `get(node, -0)` to get the node to use for an `insertAfter` operation
  * `get(node, -1)` to retrieve the node that's being removed

If you don't care about any of those second arguments values, `const get = o => o;` is a valid get too.


### How to import it:

  * via **CDN**, as global variable: `https://unpkg.com/udomdiff`
  * via **ESM**, as external module: `import udomdiff from 'https://unpkg.com/udomdiff/esm/index.js'`
  * via **CJS**: `const udomdiff = require('udomdiff');` <sup><sub>( or `require('udomdiff/cjs')` )</sub></sup>
  * via bundlers/transpilers: `import udomdiff from 'udomdiff';` <sup><sub>( or `from 'udomdiff/esm'` )</sub></sup>

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