@putout/formatter-memory 3.1.0 → 3.1.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.
Files changed (2) hide show
  1. package/lib/memory.js +9 -6
  2. package/package.json +1 -1
package/lib/memory.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import {Writable} from 'stream';
2
+ import {hrtime} from 'process';
2
3
 
3
4
  import dump from '@putout/formatter-dump';
4
5
  import cliProgress from 'cli-progress';
@@ -7,9 +8,8 @@ import once from 'once';
7
8
  import format from 'format-io';
8
9
  import montag from 'montag';
9
10
 
10
- import {hrtime} from 'node:process';
11
-
12
- const start = hrtime.bigint();
11
+ const start = once(() => hrtime.bigint());
12
+ const end = once(() => hrtime.bigint());
13
13
 
14
14
  const OK = '👌';
15
15
  const {
@@ -27,6 +27,8 @@ const {
27
27
  } = process.env;
28
28
 
29
29
  export default ({name, options, places, index, count, filesCount, errorsCount}) => {
30
+ start();
31
+
30
32
  const {
31
33
  color = '#ea4336',
32
34
  minCount = 0,
@@ -132,11 +134,12 @@ function getInfo(memory) {
132
134
  `;
133
135
  }
134
136
 
137
+ export const maybeZero = (a) => a <= 9 ? '0' : '';
138
+
135
139
  function calcTime() {
136
- const end = hrtime.bigint();
137
- const time = Math.round(Number(end - start) / 1e9);
140
+ const time = Math.round(Number(end() - start()) / 1e9);
138
141
  const minutes = Math.floor(time / 60);
139
142
  const seconds = time % 60;
140
143
 
141
- return `0${minutes}:${seconds <= 9 ? '0' : ''}${seconds}`;
144
+ return `${maybeZero(minutes)}${minutes}:${maybeZero(seconds)}${seconds}`;
142
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/formatter-memory",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "🐊Putout formatter shows memory usage",
6
6
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/formatter-memory#readme",