@lage-run/format-hrtime 0.1.3 → 0.1.5
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/formatDuration.d.ts +1 -1
- package/lib/formatDuration.js +36 -17
- package/lib/index.js +21 -7
- package/package.json +1 -1
- package/lib/formatDuration.js.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/formatDuration.d.ts
CHANGED
|
@@ -6,4 +6,4 @@ export declare function hrToSeconds(hrtime: [number, number]): string;
|
|
|
6
6
|
* @param end
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
|
-
export declare function hrtimeDiff(start
|
|
9
|
+
export declare function hrtimeDiff(start?: [number, number], end?: [number, number]): [number, number];
|
package/lib/formatDuration.js
CHANGED
|
@@ -1,37 +1,56 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
formatDuration: function() {
|
|
13
|
+
return formatDuration;
|
|
14
|
+
},
|
|
15
|
+
hrToSeconds: function() {
|
|
16
|
+
return hrToSeconds;
|
|
17
|
+
},
|
|
18
|
+
hrtimeDiff: function() {
|
|
19
|
+
return hrtimeDiff;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
4
22
|
function formatDuration(seconds) {
|
|
5
23
|
const raw = parseFloat(seconds);
|
|
6
24
|
if (raw > 60) {
|
|
7
25
|
const minutes = Math.floor(raw / 60);
|
|
8
26
|
const seconds = (raw - minutes * 60).toFixed(2);
|
|
9
27
|
return `${minutes}m ${seconds}s`;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
28
|
+
} else {
|
|
12
29
|
const seconds = raw.toFixed(2);
|
|
13
30
|
return `${seconds}s`;
|
|
14
31
|
}
|
|
15
32
|
}
|
|
16
|
-
exports.formatDuration = formatDuration;
|
|
17
33
|
function hrToSeconds(hrtime) {
|
|
18
34
|
const raw = hrtime[0] + hrtime[1] / 1e9;
|
|
19
35
|
return raw.toFixed(2);
|
|
20
36
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function hrtimeDiff(start, end) {
|
|
37
|
+
function hrtimeDiff(start = [
|
|
38
|
+
0,
|
|
39
|
+
0
|
|
40
|
+
], end = [
|
|
41
|
+
0,
|
|
42
|
+
0
|
|
43
|
+
]) {
|
|
29
44
|
const sec = end[0] - start[0];
|
|
30
45
|
const nsec = end[1] - start[1];
|
|
31
46
|
if (nsec < 0) {
|
|
32
|
-
return [
|
|
47
|
+
return [
|
|
48
|
+
Math.max(0, sec - 1),
|
|
49
|
+
1e9 + nsec
|
|
50
|
+
];
|
|
33
51
|
}
|
|
34
|
-
return [
|
|
52
|
+
return [
|
|
53
|
+
sec,
|
|
54
|
+
nsec
|
|
55
|
+
];
|
|
35
56
|
}
|
|
36
|
-
exports.hrtimeDiff = hrtimeDiff;
|
|
37
|
-
//# sourceMappingURL=formatDuration.js.map
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
formatDuration: function() {
|
|
13
|
+
return _formatDuration.formatDuration;
|
|
14
|
+
},
|
|
15
|
+
hrToSeconds: function() {
|
|
16
|
+
return _formatDuration.hrToSeconds;
|
|
17
|
+
},
|
|
18
|
+
hrtimeDiff: function() {
|
|
19
|
+
return _formatDuration.hrtimeDiff;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _formatDuration = require("./formatDuration.js");
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatDuration.js","sourceRoot":"","sources":["../src/formatDuration.ts"],"names":[],"mappings":";;;AAAA,SAAgB,cAAc,CAAC,OAAe;IAC5C,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,GAAG,GAAG,EAAE,EAAE;QACZ,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,CAAC,GAAG,GAAG,OAAO,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO,GAAG,OAAO,KAAK,OAAO,GAAG,CAAC;KAClC;SAAM;QACL,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC/B,OAAO,GAAG,OAAO,GAAG,CAAC;KACtB;AACH,CAAC;AAVD,wCAUC;AAED,SAAgB,WAAW,CAAC,MAAwB;IAClD,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;IACxC,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAHD,kCAGC;AAED;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAuB,EAAE,GAAqB;IACvE,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,KA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