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

slide-stream

v2.0.0

Published

Transform a stream of JSON slide metadata into a stream of HTML documents

Downloads

7

Readme

slide-stream

Transform a stream of JSON slide metadata into a stream of HTML documents

build status

Installation

This module is installed via npm:

$ npm install slide-stream

Example Usage

Render a stream of slide-deck JSON into HTML documents. This example registers two slide middleware rendering functions which will have the option to render the current slide JSON, or to pass it to the next middleware plugin:

var slideStream = require('slide-stream'),
    streamify = require('stream-array'),
    concat = require('concat-stream');

// Simple Title Slide Middleware
function titleSlide() {
  return function (slide, cb) {
    // if slide is not for me, then go to next middleware
    if (slide.type !== 'title') return cb();

    var html =
      '<h1>' + slide.title + '</h1>\n' +
      '<b>' + slide.body + '</b>\n' +
      '<hr>\n';
    cb(null, html);
  };
}

// Default Slide
function defaultSlide() {
  return function (slide, cb) {
    // No check: always render
    var html =
      '<h2>' + slide.title + '</h2>\n' +
      '<b>' + slide.body + '</b>\n';
    cb(null, html);
  };
}

var slides = slideStream(),

// register middleware stack, order of registration is order of application
slides.use(titleSlide());
slides.use(defaultSlide());

// sample JSON stream of deck slides
var deck = [
  { type: 'title', title: 'Slide 0', body: 'This is Slide 0' },
  { type: 'default', title: 'Slide 1', body: 'This is Slide 1' },
  { type: 'default', title: 'Slide 2', body: 'This is Slide 2' },
];

streamify(deck)
  .pipe(slides)
  .pipe(concat({ encoding: 'object' }, function (results) {
    console.log(results);
    // [ '<h1>Slide 0</h1>\n<b>This is Slide 0</b>\n<hr>\n',
    //   '<h2>Slide 1</h2>\n<b>This is Slide 1</b>\n',
    //   '<h2>Slide 2</h2>\n<b>This is Slide 2</b>\n' ]
  }));

API

SlideStream()

Returns a new instance of a slide Transform stream.

SlideStream#use(middleware)

Register a middleware with the slide stream. See API below for details.

Middleware API

Each slide middleware function has the following signature:

middleware(slide, cb)

Where:

  • slide - is the slide fragment of JSON that will contain the metadata of the slide that will be rendered.
  • cb(err, html):
    • err - error if there was an error.
    • html - if this present, then this HTML will be rendered out of the stream. If undefined, then the next middleware render plugin will be called.