# @semibran/patch

> efficient patch operation for matching HTML elements to vnodes

Latest version **2.0.1** (published 2021-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @semibran/patch
pnpm add @semibran/patch
yarn add @semibran/patch
bun add @semibran/patch
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-01-08 |
| First published | 2018-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | semibran |
| Maintainers | semibran |
| Keywords | patch, morph, html, dom, virtual-dom |

## Links

- npm: https://www.npmjs.com/package/@semibran/patch
- Repository: https://github.com/semibran/patch
- Homepage: https://github.com/semibran/patch#readme
- Issues: https://github.com/semibran/patch/issues
- npm.io page: https://npm.io/package/@semibran/patch

## 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

- 2.0.1 (latest) — 2021-01-08
- 2.0.0 — 2021-01-04
- 1.0.0 — 2018-03-02

## README

# patch
> efficient patch operation for matching HTML elements to vnodes

```js
let element = document.createElement('h1')
element.innerText = 'hello world'
document.body.appendChild(element)

patch(element, {
  tag: 'h1',
  props: {},
  content: ['goodbye world']
})
```

## usage
[![npm badge]][npm package]

### `result = patch(elem, node)`
Alters `elem` to match `node` and returns `result`.

* `elem`: the `HTMLElement` to be patched
* `node`: a virtual node of the structure `{ tag, props, content }` against which `elem` is compared

Note that if `elem.tagName` and `node.tag` are different, `result` will be a brand new element. This behavior is caused by a property of the `HTMLElement` interface that prevents an element's tag from being changed once it is created. If there is a chance of the tag name being altered during runtime, make sure to update your element reference to match `result`; otherwise, any changes you make to the new element will not be reflected onscreen.

[npm package]:                       https://npmjs.com/package/@semibran/patch
[npm badge]:                         https://nodei.co/npm/@semibran/patch.png?mini

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