domify
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

domify

Turn a HTML string into DOM elements, cross-platform

Usage

Works out of the box in the browser:

import domify from 'domify';

document.addEventListener('DOMContentLoaded', () => {
	const element = domify('<p>Hello <em>there</em></p>');
	document.body.appendChild(element);
});

You can also run it in Node.js and other non-browser environments by passing a custom implementation of document:

import {JSDOM} from 'jsdom';

const jsdom = new JSDOM();

domify('<p>Hello <em>there</em></p>', jsdom.window.document);

Note: For browser-only use, prefer DOMParser.parseFromString().

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    2,504
    • latest

Version History

Package Sidebar

Install

npm i domify

Weekly Downloads

119,221

Version

2.0.0

License

MIT

Unpacked Size

4.91 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus