hyperscript-html
Hyperscript-html provides a simple, fast, and lightweight hyperscript function to generate HTML.
Example
Input
var HyperScript wrap = // import {HyperScript, wrap} from 'hyperscript-html' // If you're using es modules. var h = var html =
Input with wrapped elements
var HyperScript wrap = // import {HyperScript, wrap} from 'hyperscript-html' // If you're using es modules. var div h1 p = var html =
Output
The Title The content
API
HyperScript([options])
The hyperscript
constructor, takes optional options object argument, returns a hyperscript
function.
var h = // or with optionsvar h =
hyperscript(tag[, attrs[, ...children]])
The hyperscript
function returned from the HyperScript
constructor, takes a required tag name (eg. 'div'
), and optional attributes object, and optional children. The children can be added as an array or multiple arguments, or a combination of arrays and arguments.
// tag // tag and attributes // If the `shortHand` option is `true` (default),// you can supply a CSS selector like string for the tag// and the values will be extracted to their respective attributes. // tag with child arguments // tag with child array // tag with attributes and child arguments
wrap(elements[, options])
The wrap function creates shorthand hyperscript
functions. It takes an object of elements with mapping function name : element tag
(eg. {div: 'div', BOX: 'div}
), and an optional options object (the same options that HyperScript
takes). It returns an object of bound shorthand hyperscript functions.
var box h1 p =
options object
Option | Default value | Description |
---|---|---|
tab |
'\t' |
What to use as the tab. |
nl |
'\n' |
What to use as the line break. |
prettyPrint |
true |
Format the HTML output nicely with newlines and tabs, set to false for faster rendering. |
attrsNewLine |
true |
Put attributes on a new line when prettyPrint is true . |
shortHand |
true , always false for wrap fn |
Use CSS like selector syntax in tag names for shorthand id, class and attributes values. Set to false for faster rendering. |
voidElements |
true |
Leave the closing tag off of empty void elements. |
flexibleArgs |
true |
Make the hyperscript functions interface flexible, if false you must provide a value for attributes argument or null if you supply children (eg. h('div', null, 'child text') . |