This module is similar to JSX, but provided as a standards-compliant ES6 tagged
template string function.
hyperx works with virtual-dom,
react,
hyperscript, or any DOM builder with a
hyperscript-style API: h(tagName, attrs, children).
You might also want to check out the hyperxify browserify transform to
statically compile hyperx into javascript expressions to save sending the hyperx
parser down the wire.
compatibility
Template strings are available in:
node 4+, chrome 41, firefox 34, edge, opera 28, safari 9
If you're targeting these platforms, there's no need to use a transpiler!
examples
virtual-dom node example
var vdom = require('virtual-dom')var hyperx = require('hyperx')var hx = hyperx(vdom.h)var title = 'world'var wow = [1,2,3]var tree = hx`<div> <h1 y="ab${1+2}cd">hello ${title}!</h1> ${hx`<i>cool</i>`} wow ${wow.map(function (w, i) { return
Return a tagged template function hx from a hyperscript-style factory function
h.
Values to use for h:
virtual-dom - vdom.h
react - React.createElement with parameter children spread
hyperscript - hyperscript
Optionally provide:
opts.concat(a, b) - custom concatenation function to combine quasiliteral
strings with expressions. The h factory function will receive the objects
returned by the concatenation function and can make specific use of them. This
is useful if you want to implement a pre-processor to generate javascript from
hyperx syntax.
opts.attrToProp - turn off attribute to property conversions when false
opts.createFragment - if your template string has multiple root elements, they
will be provided as an array to this function. the return value will then be returned
by the template literal