Create a HTML element string
$ npm install create-html-element
const createHtmlElement = require('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>'
Type: object
Type: string
Default: div
HTML tag name.
Type: Object
HTML tag attributes.
HTML tag value in unescaped HTML.
This option is mutually exclusive with the text
option.
HTML tag value in escaped HTML.
This option is mutually exclusive with the html
option.
- stringify-attributes - Turn an object into a string of HTML attributes
MIT ยฉ Sindre Sorhus