stream-collect
Advanced tools
Comparing version 1.2.1 to 1.3.0
11
index.js
@@ -114,3 +114,2 @@ /* jshint node: true */ | ||
stream.PassThrough.call( this, options ); | ||
@@ -144,4 +143,14 @@ addToStream(this); | ||
/** | ||
* A PassThrough set to objectMode | ||
*/ | ||
function PassThroughObject(options) { | ||
options = options || {}; | ||
options.objectMode = true; | ||
return new PassThrough(options); | ||
} | ||
module.exports = collect; | ||
collect.addToStream = addToStream; | ||
collect.PassThrough = collect.stream = PassThrough; | ||
collect.PassThroughObject = collect.objectStream = PassThroughObject; |
{ | ||
"name": "stream-collect", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Collects the output of a stream as callback or promise", | ||
"keywords": [ | ||
"stream", | ||
"collect", | ||
"promise" | ||
], | ||
"main": "index.js", | ||
@@ -6,0 +11,0 @@ "scripts": { |
@@ -75,3 +75,6 @@ # Stream collect | ||
## `collect.objectStream()` / `collect.PassThroughObject()` | ||
Returns a new `collect.stream` with `objectMode` set to true. | ||
## collect.addToStream(stream) | ||
@@ -78,0 +81,0 @@ |
@@ -244,3 +244,47 @@ /* jshint node: true, mocha: true */ | ||
describe( 'collect.PassThroughObject', function() { | ||
it( 'creates a collect.PassThrough instance', function( ) { | ||
expect( new collect.PassThroughObject() ).toBeA( collect.PassThrough ); | ||
} ); | ||
it( 'is a PassThrough stream', function( ) { | ||
expect( new collect.PassThroughObject() ).toBeA( PassThrough ); | ||
} ); | ||
it( 'is can be instigated without new', function( ) { | ||
expect( collect.PassThroughObject() ).toBeA( PassThrough ); | ||
} ); | ||
it( 'collect.objectStream is a collect.PassThroughStream', function( ) { | ||
expect( collect.objectStream ).toBe( collect.PassThroughObject ); | ||
} ); | ||
it( 'creates a PassThrough instance with objectMode on', function( ) { | ||
var objectStream = collect.objectStream(); | ||
expect( objectStream._readableState.objectMode ).toBe( true ); | ||
expect( objectStream._writableState.objectMode ).toBe( true ); | ||
} ); | ||
it( 'collects as an object stream', function() { | ||
var stream = new collect.PassThrough( {objectMode: true }); | ||
var ob1 = {}; | ||
var ob2 = {}; | ||
stream.write( ob1 ); | ||
stream.end( ob2 ); | ||
return stream.pipe( collect.objectStream() ) | ||
.then( function(data) { | ||
expect( data[0] ).toBe(ob1); | ||
expect( data[1] ).toBe(ob2); | ||
} ); | ||
} ); | ||
} ); | ||
describe( 'collect', function() { | ||
@@ -247,0 +291,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3306729
375
84