Comparing version 1.2.0 to 1.3.0
13
index.js
@@ -11,7 +11,16 @@ var Readable = require('readable-stream').Readable | ||
function toFunction(list) { | ||
list = list.slice() | ||
return function (_, cb) { | ||
cb(null, list.length ? list.shift() : null) | ||
} | ||
} | ||
function from2(opts, read) { | ||
if (typeof opts === 'function') { | ||
if (typeof opts !== 'object' || Array.isArray(opts)) { | ||
read = opts | ||
opts = {} | ||
} | ||
if (Array.isArray(read)) read = toFunction(read) | ||
@@ -70,3 +79,3 @@ var rs = new Proto(opts) | ||
function obj(opts, read) { | ||
if (typeof opts === 'function') { | ||
if (typeof opts === 'function' || Array.isArray(opts)) { | ||
read = opts | ||
@@ -73,0 +82,0 @@ opts = {} |
{ | ||
"name": "from2", | ||
"description": "Convenience wrapper for ReadableStream, with an API lifted from \"from\" and \"through2\"", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
# from2 [![Flattr this!](https://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=hughskennedy&url=http://github.com/hughsk/from2&title=from2&description=hughsk/from2%20on%20GitHub&language=en_GB&tags=flattr,github,javascript&category=software)[![experimental](http://hughsk.github.io/stability-badges/dist/experimental.svg)](http://github.com/hughsk/stability-badges) # | ||
`from2` is a high-level module for creating readable streams that properly handle backpressure. | ||
Convience wrapper for | ||
@@ -4,0 +6,0 @@ [readable-stream](http://github.com/isaacs/readable-stream)'s `ReadableStream` |
28
test.js
@@ -60,2 +60,28 @@ var test = require('tape') | ||
stream.destroy() | ||
}) | ||
}) | ||
test('arrays', function (t) { | ||
var input = ['a', 'b', 'c'] | ||
var stream = from(input) | ||
var output = [] | ||
stream.on('data', function (letter) { | ||
output.push(letter.toString()) | ||
}) | ||
stream.on('end', function () { | ||
t.deepEqual(input, output) | ||
t.end() | ||
}) | ||
}) | ||
test('obj arrays', function (t) { | ||
var input = [{foo:'a'}, {foo:'b'}, {foo:'c'}] | ||
var stream = from.obj(input) | ||
var output = [] | ||
stream.on('data', function (letter) { | ||
output.push(letter) | ||
}) | ||
stream.on('end', function () { | ||
t.deepEqual(input, output) | ||
t.end() | ||
}) | ||
}) |
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
7892
149
68