npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hstream

v3.1.1

Published

streaming html templates

Downloads

2,381

Readme

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 actions standard

Install

npm install hstream

Usage

var hstream = require('hstream')

hstream({
  'div > .x[attr="value"]': fs.createReadStream('./xyz.html')
})

API

hstream(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.

_html and _replaceHtml can also be a function. Then they are called with the html contents of the element being replaced, and should return a stream or a string.

When setting attributes, you can also use a function that receives the value of the attribute as the only parameter and that returns a stream or string with the new contents.

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() },
  // replace an element with something that depends on the current value
  '#f': { _html: function (input) { return input.toUpperCase() } },
  // replace an attribute with something that depends on its current value
  '#g': { class: function (current) { return cx(current, 'other-class') } }
})

Benchmarks

Run npm run bench.

hstream:

NANOBENCH version 2
> /usr/bin/node bench/hstream.js

# 10× single transform
ok ~233 ms (0 s + 232898600 ns)

# many transforms
ok ~159 ms (0 s + 158674007 ns)

# small file
ok ~11 ms (0 s + 11377188 ns)

all benchmarks completed
ok ~403 ms (0 s + 402949795 ns)

hyperstream:

NANOBENCH version 2
> /usr/bin/node bench/hyperstream.js

# 10× single transform
ok ~1.84 s (1 s + 841403862 ns)

# many transforms
ok ~1.69 s (1 s + 694201406 ns)

# small file
ok ~101 ms (0 s + 101124108 ns)

all benchmarks completed
ok ~3.64 s (3 s + 636729376 ns)

License

Apache-2.0