@vbarbarosh/node-helpers 3.15.0 → 3.16.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.15.0",
5
+ "version": "3.16.0",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -0,0 +1,23 @@
1
+ const stream = require('stream');
2
+
3
+ /**
4
+ * Call `fn` on each item.
5
+ */
6
+ function stream_each(fn)
7
+ {
8
+ return stream.Transform({
9
+ objectMode: true,
10
+ transform: async function (item, encoding, next) {
11
+ try {
12
+ await fn(item);
13
+ this.push(item, encoding);
14
+ next();
15
+ }
16
+ catch (error) {
17
+ next(error);
18
+ }
19
+ },
20
+ });
21
+ }
22
+
23
+ module.exports = stream_each;
@@ -8,7 +8,7 @@ function stream_group(chunk_size)
8
8
  const chunk = [];
9
9
  return new stream.Transform({
10
10
  objectMode: true,
11
- transform: function (item, enc, next) {
11
+ transform: function (item, encoding, next) {
12
12
  chunk.push(item);
13
13
  if (chunk.length >= chunk_size) {
14
14
  this.push(chunk.splice(0));
@@ -18,8 +18,8 @@ function stream_group(chunk_size)
18
18
  flush: function (next) {
19
19
  if (chunk.length) {
20
20
  this.push(chunk.splice(0));
21
- next();
22
21
  }
22
+ next();
23
23
  },
24
24
  });
25
25
  }