create-html-element
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

create-html-element

Create a HTML element string

Install

npm install create-html-element

Usage

import createHtmlElement from 'create-html-element';

createHtmlElement({
	name: 'h1',
	attributes: {
		class: 'unicorn',
		rainbow: true,
		horse: false,
		number: 1,
		multiple: [
			'a',
			'b'
		]
	},
	html: '🦄'
});
//=> '<h1 class="unicorn" rainbow number="1" multiple="a b">🦄</h1>'

createHtmlElement({text: 'Hello <em>World</em>'});
//=> '<div>Hello &lt;em&gt;World&lt;/em&gt;</div>'

API

createHtmlElement(options)

options

Type: object

name

Type: string
Default: 'div'

HTML tag name.

attributes

Type: object

HTML tag attributes.

html

HTML tag value in unescaped HTML.

This option is mutually exclusive with the text option.

text

HTML tag value in escaped HTML.

This option is mutually exclusive with the html option.

Related

Package Sidebar

Install

npm i create-html-element

Weekly Downloads

1,035

Version

4.0.1

License

MIT

Unpacked Size

4.79 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus