Socket
Socket
Sign inDemoInstall

hstream

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hstream

streaming html templates


Version published
Weekly downloads
151
decreased by-71.46%
Maintainers
3
Weekly downloads
 
Created
Source

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

npm travis standard

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
  • _replaceHtml - Replace the entire element with some HTML

All properties accept streams and strings.

hstream({
  '#a': someReadableStream(), // replace content with a stream
  '#b': 'a string value', // replace content with a string
  // prepend and append some html
  '#c': { _prependHtml: 'here comes the <b>content</b>: ', _appendHtml: ' …that\'s all folks!' },
  // replace content with a stream and set an attribute `attr="value"`
  '#d': { _html: someReadableStream(), 'attr': 'value' },
  // set an attribute `data-whatever` to a streamed 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

Keywords

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc