Socket
Socket
Sign inDemoInstall

value2stream

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

value2stream

Transform any value to stream. Create a stream from any value - string, array, buffer, number, promise or even Error object.


Version published
Weekly downloads
3
decreased by-62.5%
Maintainers
1
Weekly downloads
 
Created
Source

value2stream npmjs.com The MIT License npm downloads

Transform any value to stream. Create a stream from any value - string, array, buffer, number, promise or even Error object.

code climate standard code style travis build status coverage status dependency status

Note: Be aware of that if you pass Error object you will still recieve it as value. It won't fire the error event on created stream. That will only happen if you pass rejected promise. And all this is intentional - you just pass a value and recieve a stream with that value.

Install

npm i value2stream --save

Usage

For more use-cases see the tests

const value2stream = require('value2stream')

value2stream

Create a stream from any value.

Params

  • val {Mixed}: Any type of value except function. Use callback2stream for functions.
  • [opts] {Object|Function=}: Directly passed to promise2stream and through2, otherwise Promise contstructor.
  • [Promize] {Function}: Promise constructor to be used when no support for native Promise.
  • returns {Stream}

Example

var toStream = require('value2promise')

toStream(123).on('data', function (val) {
  console.log(val) // => 123
})
toStream('str foo').on('data', function (val) {
  console.log(val) // => 'str foo'
})

// not throws if `opts.objectMode: true` (default)
toStream({ foo: 'bar' }).on('data', function (val) {
  console.log(val) // => { foo: 'bar' }
})

// throws when non-object mode
toStream({ foo: 'bar' }, { objectMode: false })
  .once('error', function (err) {
    console.log(err instanceof Error) // => true
    console.log(err) // => [Error: Invalid non-string/buffer chunk]
  })

// same applies if non-object and promise resolves object
var fails = Promise.resolve({ a: 'b' })
toStream(fails, { objectMode: false })
  .once('error', function (err) {
    console.log(err instanceof Error) // => true
    console.log(err) // => [Error: Invalid non-string/buffer chunk]
  })

var promise = Promise.resolve('foo bar')
toStream(promise).on('data', function (val) {
  console.log(val) // => 'foo bar'
})

var rejected = Promise.reject(new Error('err msg'))
toStream(rejected).once('error', function (err) {
  console.log(err instanceof Error) // => true
  console.log(err.message) // => 'err msg'
})

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

Keywords

FAQs

Package last updated on 06 May 2016

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