@vbarbarosh/node-helpers 3.28.0 → 3.29.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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "3.28.0",
5
+ "version": "3.29.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -3,13 +3,13 @@ const stream = require('stream');
3
3
  /**
4
4
  * Call `fn` on each item.
5
5
  */
6
- function stream_each(fn)
6
+ function stream_through(fn)
7
7
  {
8
- return stream.Transform({
8
+ return new stream.Transform({
9
9
  objectMode: true,
10
- transform: async function (item, encoding, next) {
10
+ transform: function (item, encoding, next) {
11
11
  try {
12
- await fn(item);
12
+ fn(item);
13
13
  this.push(item, encoding);
14
14
  next();
15
15
  }
@@ -20,4 +20,4 @@ function stream_each(fn)
20
20
  });
21
21
  }
22
22
 
23
- module.exports = stream_each;
23
+ module.exports = stream_through;
@@ -0,0 +1,19 @@
1
+ const stream = require('stream');
2
+
3
+ function stream_transform(fn)
4
+ {
5
+ return new stream.Transform({
6
+ objectMode: true,
7
+ transform: function (item, encoding, next) {
8
+ try {
9
+ this.push(fn(item));
10
+ next();
11
+ }
12
+ catch (error) {
13
+ next(error);
14
+ }
15
+ },
16
+ });
17
+ }
18
+
19
+ module.exports = stream_transform;