🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

stream-from-iterator

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

stream-from-iterator

Create streams from ES2015 iterators

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

stream-from-iterator Dependencies Status Image Build Status Image Coverage Status XO code style

Create streams from ECMAScript® 2015 Iterators.

Install

npm install stream-from-iterator --save

Usage

import StreamFromIterator from 'stream-from-iterator';

function * strRange(start, end) {
	for (var i = start; i <= end; i++) {
		yield String(i);
	}
}

new StreamFromIterator(strRange(0, 9))
	.pipe(process.stdout); // output: 0123456789

Stream iterating over String | Buffers

import StreamFromIterator from 'stream-from-iterator';

new StreamFromIterator(['some', ' ', 'strings'].values())
	.pipe(process.stdout); // output: some strings

new StreamFromIterator([new Buffer('some'), ' mixed ', new Buffer('strings')].values())
	.pipe(process.stdout); // output: some mixed strings

Stream iterating over (arbitrary) Javascript Values

import StreamFromIterator from 'stream-from-iterator';

var i = 0;
StreamFromIterator.obj(['some', 42, 'mixed', 'array', () => {}].values())
	.on('data', data => {
		console.log(i++ + ': ' + typeof data);
		/* outputs:
			0: string
			1: number
			2: string
			3: string
			4: function
		*/
	});

API

Class: StreamFromIterator

StreamFromIterators are Readable streams.

new StreamFromIterator(iterator, [options])

  • iterator Iterator ES2015 Iterator iterating over arbitrary Javascript values like numbers, strings, objects, functions, ...
  • options Object passed through new Readable([options])

Note: The new operator can be omitted.

StreamFromIterator#obj(iterator, [options])

A convenience wrapper for new StreamFromIterator(iterator, {objectMode: true, ...}).

  • stream-from: Create streams from promises, iterators, factories and arbitrary Javascript values like functions, arrays, etc.

License

MIT © Michael Mayer

Keywords

readable

FAQs

Package last updated on 25 Aug 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