@tstdl/base 0.84.36 → 0.84.37
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 +1 -1
- package/utils/event-loop.js +2 -2
- package/utils/format.d.ts +5 -0
- package/utils/format.js +55 -0
- package/utils/helpers.d.ts +0 -1
- package/utils/helpers.js +0 -21
package/package.json
CHANGED
package/utils/event-loop.js
CHANGED
|
@@ -22,7 +22,7 @@ __export(event_loop_exports, {
|
|
|
22
22
|
runEventLoopWatcher: () => runEventLoopWatcher
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(event_loop_exports);
|
|
25
|
-
var
|
|
25
|
+
var import_format = require("./format.js");
|
|
26
26
|
var import_periodic_sampler = require("./periodic-sampler.js");
|
|
27
27
|
var import_timer = require("./timer.js");
|
|
28
28
|
async function measureEventLoopDelay() {
|
|
@@ -36,7 +36,7 @@ async function measureEventLoopDelay() {
|
|
|
36
36
|
}
|
|
37
37
|
function runEventLoopWatcher(logger, cancellationToken) {
|
|
38
38
|
const sampler = new import_periodic_sampler.PeriodicSampler(measureEventLoopDelay, 50);
|
|
39
|
-
sampler.watch(0, 100, import_periodic_sampler.AggregationMode.ThirdQuartile).subscribe((delay) => logger.debug(`eventloop: ${(0,
|
|
39
|
+
sampler.watch(0, 100, import_periodic_sampler.AggregationMode.ThirdQuartile).subscribe((delay) => logger.debug(`eventloop: ${(0, import_format.formatDuration)(delay, 2)}`));
|
|
40
40
|
sampler.start();
|
|
41
41
|
cancellationToken.then(async () => sampler.stop());
|
|
42
42
|
}
|
package/utils/format.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var format_exports = {};
|
|
20
|
+
__export(format_exports, {
|
|
21
|
+
formatBytes: () => formatBytes,
|
|
22
|
+
formatDuration: () => formatDuration
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(format_exports);
|
|
25
|
+
const siByteSizes = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
26
|
+
const iecByteSizes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
27
|
+
function formatDuration(milliseconds, precision) {
|
|
28
|
+
let value;
|
|
29
|
+
let suffix;
|
|
30
|
+
if (milliseconds >= 10 ** 3) {
|
|
31
|
+
value = milliseconds / 10 ** 3;
|
|
32
|
+
suffix = "s";
|
|
33
|
+
} else if (milliseconds >= 1) {
|
|
34
|
+
value = milliseconds;
|
|
35
|
+
suffix = "ms";
|
|
36
|
+
} else if (milliseconds >= 1 / 10 ** 3) {
|
|
37
|
+
value = milliseconds * 10 ** 3;
|
|
38
|
+
suffix = "us";
|
|
39
|
+
} else {
|
|
40
|
+
value = milliseconds * 10 ** 6;
|
|
41
|
+
suffix = "ns";
|
|
42
|
+
}
|
|
43
|
+
const trimmed = parseFloat(value.toFixed(precision));
|
|
44
|
+
const result = `${trimmed} ${suffix}`;
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function formatBytes(bytes, { decimals = 2, unit = "IEC" } = {}) {
|
|
48
|
+
const iec = unit == "IEC";
|
|
49
|
+
const base = iec ? 1024 : 1e3;
|
|
50
|
+
const exponent = Math.floor(Math.log(bytes) / Math.log(base));
|
|
51
|
+
const prefix = (iec ? iecByteSizes : siByteSizes)[exponent];
|
|
52
|
+
const result = bytes / base ** exponent;
|
|
53
|
+
const formattedResult = Intl.NumberFormat(void 0, { useGrouping: false, maximumFractionDigits: decimals }).format(result);
|
|
54
|
+
return `${formattedResult} ${prefix}`;
|
|
55
|
+
}
|
package/utils/helpers.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare function structuredClone<T>(value: T): T;
|
|
|
17
17
|
export declare function structuredCloneAsync<T>(value: T, options?: {
|
|
18
18
|
transfer?: any[];
|
|
19
19
|
}): Promise<T>;
|
|
20
|
-
export declare function formatDuration(milliseconds: number, precision: number): string;
|
|
21
20
|
export declare function valueOfType<T>(value: T): T;
|
|
22
21
|
export declare function flatten<T>(array: DeepArray<T>): T[];
|
|
23
22
|
export declare function toError(obj: any): Error;
|
package/utils/helpers.js
CHANGED
|
@@ -19,7 +19,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var helpers_exports = {};
|
|
20
20
|
__export(helpers_exports, {
|
|
21
21
|
flatten: () => flatten,
|
|
22
|
-
formatDuration: () => formatDuration,
|
|
23
22
|
iif: () => iif,
|
|
24
23
|
normalizeText: () => normalizeText,
|
|
25
24
|
parseFirstAndFamilyName: () => parseFirstAndFamilyName,
|
|
@@ -50,26 +49,6 @@ async function structuredCloneAsync(value, options) {
|
|
|
50
49
|
port1.postMessage(value, options);
|
|
51
50
|
return promise;
|
|
52
51
|
}
|
|
53
|
-
function formatDuration(milliseconds, precision) {
|
|
54
|
-
let value;
|
|
55
|
-
let suffix;
|
|
56
|
-
if (milliseconds >= 10 ** 3) {
|
|
57
|
-
value = milliseconds / 10 ** 3;
|
|
58
|
-
suffix = "s";
|
|
59
|
-
} else if (milliseconds >= 1) {
|
|
60
|
-
value = milliseconds;
|
|
61
|
-
suffix = "ms";
|
|
62
|
-
} else if (milliseconds >= 1 / 10 ** 3) {
|
|
63
|
-
value = milliseconds * 10 ** 3;
|
|
64
|
-
suffix = "us";
|
|
65
|
-
} else {
|
|
66
|
-
value = milliseconds * 10 ** 6;
|
|
67
|
-
suffix = "ns";
|
|
68
|
-
}
|
|
69
|
-
const trimmed = parseFloat(value.toFixed(precision));
|
|
70
|
-
const result = `${trimmed} ${suffix}`;
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
52
|
function valueOfType(value) {
|
|
74
53
|
return value;
|
|
75
54
|
}
|