@vbarbarosh/node-helpers 3.47.0 → 3.47.2

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.47.0",
5
+ "version": "3.47.2",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -8,7 +8,7 @@ function format_kilo(num)
8
8
  return '0';
9
9
  }
10
10
  if (num < 1000) {
11
- return num.toString();
11
+ return num.toFixed(0);
12
12
  }
13
13
  const i = parseInt(Math.floor(Math.log(num) / Math.log(1000)), 10);
14
14
  return `${(num / (1000 ** i)).toFixed(2)}${sizes[i]}`;
@@ -7,6 +7,8 @@ const items = [
7
7
  [undefined, 'n/a'],
8
8
  [0, '0'],
9
9
  [1, '1'],
10
+ [55.45, '55'],
11
+ [55.55, '56'],
10
12
  [900, '900'],
11
13
  [1500, '1.50K'],
12
14
  [2000, '2.00K'],
@@ -1,8 +1,9 @@
1
1
  const stream = require('stream');
2
2
 
3
- function stream_discard()
3
+ function stream_discard({objectMode = false} = {})
4
4
  {
5
5
  return new stream.Writable({
6
+ objectMode,
6
7
  write: function (buffer, encoding, callback) {
7
8
  callback();
8
9
  },
@@ -1,7 +1,7 @@
1
1
  const stream = require('stream');
2
2
 
3
3
  /**
4
- * Pass each item through a user-defined generator, which yields each item as it is passed down
4
+ * Pass each item through a user-defined generator, passes down each yielded item.
5
5
  */
6
6
  function stream_map_flatten(fn)
7
7
  {
@@ -53,7 +53,7 @@ function stream_map_parallel({handler, concurrency})
53
53
  callback_next = null;
54
54
  tmp();
55
55
  }
56
- if (callback_flush && !buf.length) {
56
+ if (callback_flush && !running) {
57
57
  callback_flush();
58
58
  }
59
59
  }
@@ -0,0 +1,26 @@
1
+ const Promise = require('bluebird');
2
+ const assert = require('assert');
3
+ const stream = require('stream');
4
+ const stream_each = require('./stream_each');
5
+ const stream_map_parallel = require('./stream_map_parallel');
6
+
7
+ describe('stream_map_parallel', function () {
8
+ it('basic', async function () {
9
+ const r = Array(100).fill().map((v,i) => i);
10
+ const out = [];
11
+ await stream.promises.pipeline(
12
+ stream.Readable.from(r),
13
+ stream_map_parallel({
14
+ concurrency: 5,
15
+ handler: async function (num) {
16
+ await Promise.delay(0);
17
+ return num;
18
+ },
19
+ }),
20
+ stream_each(function (item) {
21
+ out.push(item);
22
+ }),
23
+ );
24
+ assert.deepStrictEqual(out, r);
25
+ });
26
+ });