Socket
Socket
Sign inDemoInstall

stream-tag

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-tag

A tagged template literal utility for Node streams


Version published
Weekly downloads
1.9K
increased by18.76%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

stream-tag

A tagged template literal utility for Node streams

Works in node.js and the browser, if streams are polyfilled.

This utility is a small tagged-template-literal function that enables interpolation of strings, numbers, Buffers, promises, and streams into a new stream.

This is highly useful when constructing stream templates that will be emitted by a server-side rendering service for instance. One example of such use-case is React's streamed SSR, where it's useful to combine its stream with other variables into an HTML output template.

Installation

yarn add stream-tag
# or
npm install stream-tag

Usage

const streamTag = require('stream-tag');

const stream = streamTag`
  one
  ${'two'}
  ${3}
  ${Promise.resolve('four')}
  ${Promise.resolve(5)}
  ${Buffer.from('six')}
  ${streamTag`seven`}
`;

// This is what stream emits
const output = `
  one
  two
  3
  four
  5
  six
  seven
`;

API

streamTag(templateStringArr, ...interpolations)

Can be called as a tagged template literal. Returns a stream emitting the template with all interpolations combined into the output.

templateStringArr

Type: string[]

interpolations

Type: Array<void | string | number | Buffer | ReadableStream | Promise>

Promises may only resolve to all other values in the array above.

After writing this I noticed that there's already the execellent stream-template library, which does about the same.

Licence

MIT

Keywords

FAQs

Last updated on 09 Jul 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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc