@oclif/multi-stage-output 0.8.8 → 0.8.9
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/lib/components/timer.js +5 -9
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +10 -13
- package/package.json +3 -3
package/lib/components/timer.js
CHANGED
|
@@ -3,20 +3,16 @@ import React from 'react';
|
|
|
3
3
|
import { readableTime } from '../utils.js';
|
|
4
4
|
export function Timer({ color, isStopped, unit, }) {
|
|
5
5
|
const [time, setTime] = React.useState(0);
|
|
6
|
-
const
|
|
6
|
+
const startTime = React.useRef(Date.now());
|
|
7
7
|
React.useEffect(() => {
|
|
8
8
|
if (isStopped) {
|
|
9
|
-
setTime(
|
|
10
|
-
setPreviousDate(Date.now());
|
|
9
|
+
setTime(Date.now() - startTime.current);
|
|
11
10
|
return () => { };
|
|
12
11
|
}
|
|
13
12
|
const intervalId = setInterval(() => {
|
|
14
|
-
setTime(
|
|
15
|
-
setPreviousDate(Date.now());
|
|
13
|
+
setTime(Date.now() - startTime.current);
|
|
16
14
|
}, unit === 'ms' ? 1 : 1000);
|
|
17
|
-
return () => {
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
}, [time, isStopped, previousDate, unit]);
|
|
15
|
+
return () => { clearInterval(intervalId); };
|
|
16
|
+
}, [isStopped, unit]);
|
|
21
17
|
return React.createElement(Text, { color: color }, readableTime(time, unit));
|
|
22
18
|
}
|
package/lib/utils.d.ts
CHANGED
package/lib/utils.js
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
function truncate(value, decimals = 2) {
|
|
2
|
-
const remainder = value % 1;
|
|
3
|
-
// truncate remainder to specified decimals
|
|
4
|
-
const fractionalPart = remainder ? remainder.toString().split('.')[1].slice(0, decimals) : '0'.repeat(decimals);
|
|
5
|
-
const wholeNumberPart = Math.floor(value).toString();
|
|
6
|
-
return decimals ? `${wholeNumberPart}.${fractionalPart}` : wholeNumberPart;
|
|
7
|
-
}
|
|
8
1
|
export function readableTime(time, granularity, decimalPlaces = 2) {
|
|
9
|
-
if
|
|
10
|
-
return '< 1s';
|
|
11
|
-
}
|
|
12
|
-
const decimals = granularity === 'ms' ? decimalPlaces : 0;
|
|
13
|
-
// if time < 1000ms, return time in ms
|
|
2
|
+
// if time < 1000ms, return time in ms or < 1s
|
|
14
3
|
if (time < 1000) {
|
|
15
|
-
return `${time}ms`;
|
|
4
|
+
return granularity === 's' ? '< 1s' : `${time}ms`;
|
|
16
5
|
}
|
|
6
|
+
const decimals = granularity === 'ms' ? decimalPlaces : 0;
|
|
17
7
|
// if time < 60s, return time in seconds
|
|
18
8
|
if (time < 60_000) {
|
|
19
9
|
return `${truncate(time / 1000, decimals)}s`;
|
|
@@ -29,3 +19,10 @@ export function readableTime(time, granularity, decimalPlaces = 2) {
|
|
|
29
19
|
const minutes = Math.floor((time % 3_600_000) / 60_000);
|
|
30
20
|
return `${hours}h ${minutes}m`;
|
|
31
21
|
}
|
|
22
|
+
export function truncate(value, decimals = 2) {
|
|
23
|
+
if (decimals) {
|
|
24
|
+
const factor = 10 ** decimals;
|
|
25
|
+
return (Math.trunc(value * factor) / factor).toFixed(decimals);
|
|
26
|
+
}
|
|
27
|
+
return Math.floor(value).toString();
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/multi-stage-output",
|
|
3
3
|
"description": "Terminal output for oclif commands with multiple stages",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.9",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/multi-stage-output/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"@types/sinon": "^17.0.3",
|
|
24
24
|
"chai": "^4.5.0",
|
|
25
25
|
"commitlint": "^19",
|
|
26
|
-
"eslint": "^9.
|
|
27
|
-
"eslint-config-oclif": "^6.0.
|
|
26
|
+
"eslint": "^9.20.0",
|
|
27
|
+
"eslint-config-oclif": "^6.0.5",
|
|
28
28
|
"eslint-config-prettier": "^10",
|
|
29
29
|
"eslint-config-xo": "^0.46.0",
|
|
30
30
|
"eslint-config-xo-react": "^0.28.0",
|