create-html-element
v4.0.0 html element create document string make tag
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 <em>World</em></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
- stringify-attributes - Turn an object into a string of HTML attributes
npm i [email protected]
Metadata
- MIT
- ^12.20.0 || ^14.13.1 || >=16.0.0
- Sindre Sorhus
- released 10/13/2021