hstream
streaming html templates
like hyperstream, but faster. it does not support all hyperstream features.
currently unsupported:
- inserting text; only html is supported
- prepending or appending to attributes
Install
npm install hstream
Usage
var hyperstream = require('hstream')
hyperstream({
'div > .x[attr="value"]': fs.createReadStream('./xyz.html')
})
API
hyperstream(updates)
Create a through stream that applies updates
. updates
is an object with CSS
selectors for keys. Values can be different types depending on what sort of
update you want to do.
Selectors support the most common CSS features, like matching tag names,
classes, IDs, attributes. Pseudo selectors are not supported, but PRs are
welcome.
Pass a stream or string to replace the matching element's contents with some
HTML. Pass an object to set attributes on the matching element or do some
special operations. When passing an object, you can use keys prefixed with _
for the following special operations:
_html
- Replace the matching element's contents with some HTML_prependHtml
- Prepend some HTML to the matching element_appendHtml
- Append some HTML to the matching element
All properties accept streams and strings.
hstream({
'#a': someReadableStream(),
'#b': 'a string value',
'#c': { _prependHtml: 'here comes the <b>content</b>: ', _appendHtml: ' …that\'s all folks!' },
'#d': { _html: someReadableStream(), 'attr': 'value' },
'#e': { 'data-whatever': someReadableStream() }
})
Benchmarks
Run npm run bench
.
NANOBENCH version 2
> node bench/hyperstream.js
# hyperstream single
ok ~5.38 s (5 s + 381237046 ns)
# hyperstream many
ok ~5.67 s (5 s + 673399368 ns)
# hyperstream small file
ok ~946 ms (0 s + 946487806 ns)
# hstream single
ok ~1.16 s (1 s + 159528184 ns)
# hstream many
ok ~951 ms (0 s + 951094352 ns)
# hstream small file
ok ~70 ms (0 s + 70058016 ns)
all benchmarks completed
ok ~14 s (14 s + 181804772 ns)
License
Apache-2.0