hyperfast
update html elements by mapping query selectors to attributes, text, and hypertext
It's a fork of hyperglue, but about 10x faster.
example
in node
var hyperfast = ;var fs = ;var html = fs;{var name = doctitle;return;}console;console;
arrays
You can also duplicate existing elements in order to render arrays of results:
var hyperfast = ;var html ='<div id="rows">''<div class="row">''<span class="name"></span>''<span class="message"></span>''</div>''<b>ahoy!</b>''</div>';console;
output:
T-REXRAWRrobotbeep boopDr Xmwahahaahoy!
methods
var hyperfast =
hyperfast(src, updates)
Return an html element from the source string or element src
with updates
applied to it.
In the browser you get a complete html element. In node you get an object with
an innerHTML
property populated with the string contents of the replacement.
updates
should have query selectors
as keys and target strings, numbers, or objects as values.
Each update
query selector can have the special pseudo-class :first
which
causes the selector to only match the first value like querySelector()
instead
of all the matching elements like querySelectorAll()
, the default.
If the target values in updates
are strings or numbers, set the inner text
content of the matching elements to that value.
When the target values are html elements, replace the inner content at the selected element with a clone of the value.
For target values of arrays, recursively apply hyperfast(node.cloneNode(), value)
for each matching element in the array and then remove the original
node. This feature makes rendering arrays of content super simple.
If the target values in updates
are non-html element objects, update the
attributes on all matching elements with the keys in the target values. Use
'_text'
to set the text content and '_html'
to set the innerHTML in object
form. If '_html'
is an HTML element, replace the inner content at the
selector elements with a clone of the '_html'
value.
install
With npm do:
npm install hyperfast
license
MIT
kudos
Inspried by plates.