object-stream-tools
Advanced tools
Comparing version
37
index.js
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
const stream = require('stream'); | ||
@@ -5,16 +7,17 @@ const through2Concurrent = require('through2-concurrent'); | ||
'use strict'; | ||
function thru(transform, flush) { | ||
return new stream.Transform({ | ||
objectMode: true, | ||
transform: (obj, enc, cb) => transform(obj, cb), | ||
flush | ||
}); | ||
} | ||
const thru = (transform, flush) => new stream.Transform({ | ||
objectMode: true, | ||
transform, | ||
flush | ||
}); | ||
function thruParallel(maxConcurrency, transform, flush) { | ||
return through2Concurrent.obj({ maxConcurrency }, | ||
(obj, enc, cb) => transform(obj, cb), flush | ||
); | ||
} | ||
const thruParallel = (transform, maxConcurrency) => | ||
thruConcurrent.obj({ maxConcurrency }, transform); | ||
const devNull = require('fs').createWriteStream('/dev/null'); | ||
const arrayToStream = (data) => { | ||
function arrayToStream(data) { | ||
const newStream = new stream.Readable({ objectMode: true }); | ||
@@ -26,3 +29,3 @@ data.forEach(item => newStream.push(item)); | ||
const streamToSet = (stream) => { | ||
function streamToSet(stream) { | ||
return new Promise((resolve, reject) => { | ||
@@ -37,3 +40,3 @@ const set = new Set(); | ||
const newReadable = () => { | ||
function newReadable() { | ||
const rs = new stream.Readable({ objectMode: true }); | ||
@@ -66,10 +69,4 @@ rs._read = () => {}; | ||
}; | ||
module.exports = { | ||
thru, | ||
Stream, | ||
devNull, | ||
thruConcurrent, | ||
thruParallel, | ||
@@ -76,0 +73,0 @@ arrayToStream, |
{ | ||
"name": "object-stream-tools", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Useful tools for manipulating object streams. Will be especially helpful to developers used to map - filter - reduce approach of nodejs arrays.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node_modules/tap/bin/run.js test/test.js" | ||
}, | ||
@@ -30,3 +30,11 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/kichooo/object-stream-tools#readme" | ||
"homepage": "https://github.com/kichooo/object-stream-tools#readme", | ||
"devDependencies": { | ||
"JSONStream": "^1.1.1", | ||
"tap": "^5.7.2" | ||
}, | ||
"dependencies": { | ||
"stream-to-array": "^2.3.0", | ||
"through2-concurrent": "^1.1.1" | ||
} | ||
} |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
7649
62.36%8
33.33%153
131.82%0
-100%2
Infinity%2
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added