Create a HTML element string
npm install create-html-element> Create a HTML element string
``sh`
npm install create-html-element
`js
import createHtmlElement from 'create-html-element';
createHtmlElement({
name: 'h1',
attributes: {
class: 'unicorn',
rainbow: true,
horse: false,
number: 1,
multiple: [
'a',
'b'
]
},
html: '🦄'
});
//=> '
createHtmlElement({text: 'Hello World'});
//=> '
API
$3
#### options
Type:
object##### name
Type:
string\
Default: 'div'HTML tag name.
##### attributes
Type:
objectHTML tag attributes.
##### html
HTML tag value in unescaped HTML.
This option is mutually exclusive with the
text and children options.##### text
HTML tag value in escaped HTML.
This option is mutually exclusive with the
html and children options.##### children
Type:
ArrayHTML tag children.
Strings are escaped, objects are passed to
createHtmlElement.This option is mutually exclusive with the
html and text options.`js
import createHtmlElement from 'create-html-element';createHtmlElement({
name: 'div',
children: [
'',
{
name: 'iframe',
attributes: {
src: 'https://example.com'
}
},
{
name: 'span',
text: 'Label here plz'
}
]
});
//=> '<unsafe>Label here <em>plz</em>'
``- stringify-attributes - Turn an object into a string of HTML attributes