@vbarbarosh/node-helpers 3.46.0 → 3.47.1
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/format_kilo.js +1 -1
- package/src/format_kilo.test.js +2 -0
- package/src/stream_map_flatten.js +24 -0
package/package.json
CHANGED
package/src/format_kilo.js
CHANGED
package/src/format_kilo.test.js
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const stream = require('stream');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pass each item through a user-defined generator, passes down each yielded item.
|
|
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;
|