# domm

> Template literal tags for creating DOM nodes.

Latest version **0.0.3** (published 2017-12-02) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2017-12-02 |
| First published | 2017-12-02 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Daniel Levett |
| Maintainers | dlevs |

## Links

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

## Dependencies (1)

- [better-typeof](https://npm.io/package/better-typeof.md) ^2.0.0

## Recent versions

- 0.0.3 (latest) — 2017-12-02
- 0.0.2 — 2017-12-02
- 0.0.1 — 2017-12-02

## README

## What
Domm is a small library to create safe HTML and DOM nodes using ES6 template literals.

## Why
It's lightweight and relies on native JS functionality. For anything non-trivial, this doesn't compete with a real template language like [pug](https://www.npmjs.com/package/pug), or a library like [react](https://www.npmjs.com/package/react).

## Installation
```bash
npm install --save domm
```

## Usage
### Basic
```javascript
const D = require('domm');

D.html`<h1>Hello World!</h1>`;
// => '<h1>Hello World!</h1>'

D.dom`<h1>Hello World!</h1>`;
// => new instance of <HTMLHeadingElement>

D.dom`
    <a href="/">Home</a>
    <a href="/about">About</a>
`;
// => new instance of <NodeList> containing 2 links
```

### Variable interpolation
```javascript
// String
const headingText = 'Houses';

// Object
const headingAttrs = { class: 'heading-main' };

// Array
const names = ['Lannister', 'Stark', 'Tyrell'];

// Element
const backLink = document.querySelector('.js-link-back');

D.html`
    <div>
        <h1 ${headingAttrs}>${headingText}</h1>
        <ul>
            ${names.map(names => D.html`<li>${name}</li>`)}
        </ul>
        ${backLink}
    </div>
`;
// =>
// <div>
//     <h1 class="heading-main">Houses</h1>
//     <ul>
//         <li>Lannister</li><li>Stark</li><li>Tyrell</li>
//     </ul>
//     <a class="js-link-back" href="/">Back to home</a>
// </div>
```

Note that the list of names required `D.html` to be used on the inner template literal. Without this, the HTML in the list would have been escaped:

```javascript
"&lt;li&gt;Lannister&lt;/li&gt;&lt;li&gt;Stark&lt;/li&gt;&lt;li&gt;Tyrell&lt;/li&gt;"
```

All strings that are interpolated are escaped in this way. To dangerously escape a variable that is not defined via a template literal, use the `D` constructor:

```javascript
const title = someExternalFunctionForGettingTitle();

D.dom`<h1>${new D(title)}</h1>`;
```

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