Giter VIP home page Giter VIP logo

stream-from-iterator's Introduction

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, ...}).

Related

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

License

MIT © Michael Mayer

stream-from-iterator's People

Contributors

schnittstabil avatar

Stargazers

 avatar David Braun avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.