@vbarbarosh/node-helpers 3.46.0 → 3.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/stream_map_flatten.js +24 -0
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const stream = require('stream');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pass each item through a user-defined generator, which yields each item as it is passed down
|
|
5
|
+
*/
|
|
6
|
+
function stream_map_flatten(fn)
|
|
7
|
+
{
|
|
8
|
+
return new stream.Transform({
|
|
9
|
+
objectMode: true,
|
|
10
|
+
transform: async function (item, encoding, callback) {
|
|
11
|
+
try {
|
|
12
|
+
for await (const chunk of fn(item)) {
|
|
13
|
+
this.push(chunk);
|
|
14
|
+
}
|
|
15
|
+
callback();
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
callback(error);
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = stream_map_flatten;
|