@lage-run/format-hrtime 0.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.
- package/lib/formatDuration.d.ts +9 -0
- package/lib/formatDuration.js +37 -0
- package/lib/formatDuration.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/package.json +23 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function formatDuration(seconds: string): string;
|
|
2
|
+
export declare function hrToSeconds(hrtime: [number, number]): string;
|
|
3
|
+
/**
|
|
4
|
+
* calculates the difference of two hrtime values
|
|
5
|
+
* @param start
|
|
6
|
+
* @param end
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function hrtimeDiff(start: [number, number], end: [number, number]): [number, number];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hrtimeDiff = exports.hrToSeconds = exports.formatDuration = void 0;
|
|
4
|
+
function formatDuration(seconds) {
|
|
5
|
+
const raw = parseFloat(seconds);
|
|
6
|
+
if (raw > 60) {
|
|
7
|
+
const minutes = Math.floor(raw / 60);
|
|
8
|
+
const seconds = (raw - minutes * 60).toFixed(2);
|
|
9
|
+
return `${minutes}m ${seconds}s`;
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
const seconds = raw.toFixed(2);
|
|
13
|
+
return `${seconds}s`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.formatDuration = formatDuration;
|
|
17
|
+
function hrToSeconds(hrtime) {
|
|
18
|
+
const raw = hrtime[0] + hrtime[1] / 1e9;
|
|
19
|
+
return raw.toFixed(2);
|
|
20
|
+
}
|
|
21
|
+
exports.hrToSeconds = hrToSeconds;
|
|
22
|
+
/**
|
|
23
|
+
* calculates the difference of two hrtime values
|
|
24
|
+
* @param start
|
|
25
|
+
* @param end
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
function hrtimeDiff(start, end) {
|
|
29
|
+
const sec = end[0] - start[0];
|
|
30
|
+
const nsec = end[1] - start[1];
|
|
31
|
+
if (nsec < 0) {
|
|
32
|
+
return [sec - 1, 1e9 + nsec];
|
|
33
|
+
}
|
|
34
|
+
return [sec, nsec];
|
|
35
|
+
}
|
|
36
|
+
exports.hrtimeDiff = hrtimeDiff;
|
|
37
|
+
//# sourceMappingURL=formatDuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/B,IAAI,IAAI,GAAG,CAAC,EAAE;QACZ,OAAO,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,CAAC;KAC9B;IAED,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACrB,CAAC;AATD,gCASC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { formatDuration, hrToSeconds, hrtimeDiff } from "./formatDuration";
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hrtimeDiff = exports.hrToSeconds = exports.formatDuration = void 0;
|
|
4
|
+
var formatDuration_1 = require("./formatDuration");
|
|
5
|
+
Object.defineProperty(exports, "formatDuration", { enumerable: true, get: function () { return formatDuration_1.formatDuration; } });
|
|
6
|
+
Object.defineProperty(exports, "hrToSeconds", { enumerable: true, get: function () { return formatDuration_1.hrToSeconds; } });
|
|
7
|
+
Object.defineProperty(exports, "hrtimeDiff", { enumerable: true, get: function () { return formatDuration_1.hrtimeDiff; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mDAA2E;AAAlE,gHAAA,cAAc,OAAA;AAAE,6GAAA,WAAW,OAAA;AAAE,4GAAA,UAAU,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lage-run/format-hrtime",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "hrtime formatter for Lage",
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://github.com/microsoft/lage"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"main": "lib/index.js",
|
|
10
|
+
"types": "lib/index.d.ts",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"start": "tsc -w --preserveWatchOutput",
|
|
14
|
+
"test": "jest"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {},
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"lib/**/*"
|
|
22
|
+
]
|
|
23
|
+
}
|