Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including hyperstream with all npm packages installed. Try it out:

var hyperstream = require("hyperstream")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

hyperstream v1.2.2

stream html into html at a css selector


stream html into html at a css selector

build status


var hyperstream = require('hyperstream');
var fs = require('fs');

var hs = hyperstream({
    '#a': fs.createReadStream(__dirname + '/a.html'),
    '#b': fs.createReadStream(__dirname + '/b.html')
var rs = fs.createReadStream(__dirname + '/index.html');
$ node example/hs.js
    <div id="a"><h1>a!!!</h1></div>
    <div id="b"><b>bbbbbbbbbbbbbbbbbbbbbb</b></div>


var hyperstream = require('hyperstream')

var hs = hyperstream(streamMap)

Return a duplex stream that takes an html stream as input and produces an html stream as output, inserting the streams given by streamMap at the css selector keys.

If streamMap values are strings or functions, update the contents at the css selector key with their contents directly without using a stream.

If streamMap values are non-stream objects, iterate over the keys and set attributes for each key.

These attributes are special. Each attribute can be a string, buffer, or stream:

  • _html - set the inner content as raw html
  • _text - set the inner content as text encoded as html entities
  • _append, _appendText - add text to the end of the inner content encoded as html entities
  • _appendHtml - add raw html to the end of the inner content
  • _prepend, _prependText - add text to the beginning of the inner content encoded as html entities
  • _prependHtml - add raw html to the beginning of the inner context

For example, to set raw html into the inner content with the _html attribute, do:

    '#content': {
        _html: stream,
        'data-start': 'cats!',
        'data-end': 'cats!\ufff'

You can also specify string operations for properties with an object instead of a string. The object can have these properties:

  • append
  • prepend

Object properties are particularly handy for adding classes:

    '.row': {
        class: { append: ' active' }

which turns:

<div class="row"><b>woo</b></div>


<div class="row active"><b>woo</b></div>, hs.update(), hs.replace(), hs.remove()

Proxy through methods to the underlying trumpet instance.


With npm do:

npm install hyperstream



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free