qstd 0.2.28 → 0.3.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/dist/client/index.cjs +34 -11
- package/dist/client/index.js +34 -11
- package/dist/server/index.cjs +34 -11
- package/dist/server/index.js +34 -11
- package/dist/shared/log.d.ts +0 -10
- package/dist/shared/log.d.ts.map +1 -1
- package/dist/shared/time.d.ts +44 -0
- package/dist/shared/time.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client/index.cjs
CHANGED
|
@@ -260,15 +260,23 @@ __export(time_exports, {
|
|
|
260
260
|
formatThreadDateRange: () => formatThreadDateRange,
|
|
261
261
|
now: () => now,
|
|
262
262
|
sleep: () => sleep,
|
|
263
|
+
startTimer: () => startTimer,
|
|
263
264
|
toMs: () => toMs
|
|
264
265
|
});
|
|
265
266
|
var formatDuration = (ms, options = {}) => {
|
|
266
267
|
if (ms === null || ms === void 0) return "--:--";
|
|
267
|
-
const {
|
|
268
|
-
|
|
268
|
+
const {
|
|
269
|
+
format: fmt = "clock",
|
|
270
|
+
showZero = false,
|
|
271
|
+
showMs = false,
|
|
272
|
+
spaces = true
|
|
273
|
+
} = options;
|
|
274
|
+
const absMs = Math.abs(ms);
|
|
275
|
+
const totalSeconds = Math.floor(absMs / 1e3);
|
|
269
276
|
const hours = Math.floor(totalSeconds / 3600);
|
|
270
277
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
271
278
|
const seconds = totalSeconds % 60;
|
|
279
|
+
const milliseconds = absMs % 1e3;
|
|
272
280
|
if (fmt === "clock") {
|
|
273
281
|
if (hours > 0) {
|
|
274
282
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -311,23 +319,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
311
319
|
}
|
|
312
320
|
}
|
|
313
321
|
const parts = [];
|
|
322
|
+
const separator = spaces ? " " : "";
|
|
314
323
|
if (showZero) {
|
|
315
324
|
const hasHours = hours > 0;
|
|
316
325
|
const hasMinutes = minutes > 0;
|
|
317
326
|
const hasSeconds = seconds > 0;
|
|
318
|
-
|
|
327
|
+
const hasMs = milliseconds > 0;
|
|
328
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
319
329
|
if (hasHours) parts.push(`${hours}h`);
|
|
320
330
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
321
|
-
|
|
331
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
332
|
+
parts.push(`${seconds}s`);
|
|
333
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
322
334
|
} else {
|
|
323
|
-
parts.push("0s");
|
|
335
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
324
336
|
}
|
|
325
337
|
} else {
|
|
326
338
|
if (hours > 0) parts.push(`${hours}h`);
|
|
327
339
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
328
340
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
341
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
342
|
+
}
|
|
343
|
+
if (parts.length === 0) {
|
|
344
|
+
return showMs ? "0ms" : "0s";
|
|
329
345
|
}
|
|
330
|
-
return parts.join(
|
|
346
|
+
return parts.join(separator);
|
|
331
347
|
};
|
|
332
348
|
var formatDate = (input, options = {}) => {
|
|
333
349
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -454,6 +470,18 @@ var toMs = (value, unit = "seconds") => {
|
|
|
454
470
|
};
|
|
455
471
|
return value * multipliers[unit];
|
|
456
472
|
};
|
|
473
|
+
function startTimer(options = {}) {
|
|
474
|
+
const start = Date.now();
|
|
475
|
+
const fmt = options.format ?? "ms";
|
|
476
|
+
const getElapsed = () => {
|
|
477
|
+
const elapsed = Date.now() - start;
|
|
478
|
+
if (fmt === "compact") {
|
|
479
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
480
|
+
}
|
|
481
|
+
return elapsed;
|
|
482
|
+
};
|
|
483
|
+
return { stop: getElapsed, elapsed: getElapsed };
|
|
484
|
+
}
|
|
457
485
|
|
|
458
486
|
// src/shared/flow.ts
|
|
459
487
|
var flow_exports = {};
|
|
@@ -551,14 +579,9 @@ __export(log_exports, {
|
|
|
551
579
|
info: () => info,
|
|
552
580
|
label: () => label,
|
|
553
581
|
log: () => log,
|
|
554
|
-
startTimer: () => startTimer,
|
|
555
582
|
warn: () => warn
|
|
556
583
|
});
|
|
557
584
|
var stringify = (value) => JSON.stringify(value, null, 2);
|
|
558
|
-
var startTimer = () => {
|
|
559
|
-
const start = Date.now();
|
|
560
|
-
return () => Date.now() - start;
|
|
561
|
-
};
|
|
562
585
|
var log = (...values) => {
|
|
563
586
|
console.log(...values.map(stringify));
|
|
564
587
|
};
|
package/dist/client/index.js
CHANGED
|
@@ -258,15 +258,23 @@ __export(time_exports, {
|
|
|
258
258
|
formatThreadDateRange: () => formatThreadDateRange,
|
|
259
259
|
now: () => now,
|
|
260
260
|
sleep: () => sleep,
|
|
261
|
+
startTimer: () => startTimer,
|
|
261
262
|
toMs: () => toMs
|
|
262
263
|
});
|
|
263
264
|
var formatDuration = (ms, options = {}) => {
|
|
264
265
|
if (ms === null || ms === void 0) return "--:--";
|
|
265
|
-
const {
|
|
266
|
-
|
|
266
|
+
const {
|
|
267
|
+
format: fmt = "clock",
|
|
268
|
+
showZero = false,
|
|
269
|
+
showMs = false,
|
|
270
|
+
spaces = true
|
|
271
|
+
} = options;
|
|
272
|
+
const absMs = Math.abs(ms);
|
|
273
|
+
const totalSeconds = Math.floor(absMs / 1e3);
|
|
267
274
|
const hours = Math.floor(totalSeconds / 3600);
|
|
268
275
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
269
276
|
const seconds = totalSeconds % 60;
|
|
277
|
+
const milliseconds = absMs % 1e3;
|
|
270
278
|
if (fmt === "clock") {
|
|
271
279
|
if (hours > 0) {
|
|
272
280
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -309,23 +317,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
309
317
|
}
|
|
310
318
|
}
|
|
311
319
|
const parts = [];
|
|
320
|
+
const separator = spaces ? " " : "";
|
|
312
321
|
if (showZero) {
|
|
313
322
|
const hasHours = hours > 0;
|
|
314
323
|
const hasMinutes = minutes > 0;
|
|
315
324
|
const hasSeconds = seconds > 0;
|
|
316
|
-
|
|
325
|
+
const hasMs = milliseconds > 0;
|
|
326
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
317
327
|
if (hasHours) parts.push(`${hours}h`);
|
|
318
328
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
319
|
-
|
|
329
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
330
|
+
parts.push(`${seconds}s`);
|
|
331
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
320
332
|
} else {
|
|
321
|
-
parts.push("0s");
|
|
333
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
322
334
|
}
|
|
323
335
|
} else {
|
|
324
336
|
if (hours > 0) parts.push(`${hours}h`);
|
|
325
337
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
326
338
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
339
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
340
|
+
}
|
|
341
|
+
if (parts.length === 0) {
|
|
342
|
+
return showMs ? "0ms" : "0s";
|
|
327
343
|
}
|
|
328
|
-
return parts.join(
|
|
344
|
+
return parts.join(separator);
|
|
329
345
|
};
|
|
330
346
|
var formatDate = (input, options = {}) => {
|
|
331
347
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -452,6 +468,18 @@ var toMs = (value, unit = "seconds") => {
|
|
|
452
468
|
};
|
|
453
469
|
return value * multipliers[unit];
|
|
454
470
|
};
|
|
471
|
+
function startTimer(options = {}) {
|
|
472
|
+
const start = Date.now();
|
|
473
|
+
const fmt = options.format ?? "ms";
|
|
474
|
+
const getElapsed = () => {
|
|
475
|
+
const elapsed = Date.now() - start;
|
|
476
|
+
if (fmt === "compact") {
|
|
477
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
478
|
+
}
|
|
479
|
+
return elapsed;
|
|
480
|
+
};
|
|
481
|
+
return { stop: getElapsed, elapsed: getElapsed };
|
|
482
|
+
}
|
|
455
483
|
|
|
456
484
|
// src/shared/flow.ts
|
|
457
485
|
var flow_exports = {};
|
|
@@ -549,14 +577,9 @@ __export(log_exports, {
|
|
|
549
577
|
info: () => info,
|
|
550
578
|
label: () => label,
|
|
551
579
|
log: () => log,
|
|
552
|
-
startTimer: () => startTimer,
|
|
553
580
|
warn: () => warn
|
|
554
581
|
});
|
|
555
582
|
var stringify = (value) => JSON.stringify(value, null, 2);
|
|
556
|
-
var startTimer = () => {
|
|
557
|
-
const start = Date.now();
|
|
558
|
-
return () => Date.now() - start;
|
|
559
|
-
};
|
|
560
583
|
var log = (...values) => {
|
|
561
584
|
console.log(...values.map(stringify));
|
|
562
585
|
};
|
package/dist/server/index.cjs
CHANGED
|
@@ -263,15 +263,23 @@ __export(time_exports, {
|
|
|
263
263
|
formatThreadDateRange: () => formatThreadDateRange,
|
|
264
264
|
now: () => now,
|
|
265
265
|
sleep: () => sleep,
|
|
266
|
+
startTimer: () => startTimer,
|
|
266
267
|
toMs: () => toMs
|
|
267
268
|
});
|
|
268
269
|
var formatDuration = (ms, options = {}) => {
|
|
269
270
|
if (ms === null || ms === void 0) return "--:--";
|
|
270
|
-
const {
|
|
271
|
-
|
|
271
|
+
const {
|
|
272
|
+
format: fmt = "clock",
|
|
273
|
+
showZero = false,
|
|
274
|
+
showMs = false,
|
|
275
|
+
spaces = true
|
|
276
|
+
} = options;
|
|
277
|
+
const absMs = Math.abs(ms);
|
|
278
|
+
const totalSeconds = Math.floor(absMs / 1e3);
|
|
272
279
|
const hours = Math.floor(totalSeconds / 3600);
|
|
273
280
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
274
281
|
const seconds = totalSeconds % 60;
|
|
282
|
+
const milliseconds = absMs % 1e3;
|
|
275
283
|
if (fmt === "clock") {
|
|
276
284
|
if (hours > 0) {
|
|
277
285
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -314,23 +322,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
314
322
|
}
|
|
315
323
|
}
|
|
316
324
|
const parts = [];
|
|
325
|
+
const separator = spaces ? " " : "";
|
|
317
326
|
if (showZero) {
|
|
318
327
|
const hasHours = hours > 0;
|
|
319
328
|
const hasMinutes = minutes > 0;
|
|
320
329
|
const hasSeconds = seconds > 0;
|
|
321
|
-
|
|
330
|
+
const hasMs = milliseconds > 0;
|
|
331
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
322
332
|
if (hasHours) parts.push(`${hours}h`);
|
|
323
333
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
324
|
-
|
|
334
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
335
|
+
parts.push(`${seconds}s`);
|
|
336
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
325
337
|
} else {
|
|
326
|
-
parts.push("0s");
|
|
338
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
327
339
|
}
|
|
328
340
|
} else {
|
|
329
341
|
if (hours > 0) parts.push(`${hours}h`);
|
|
330
342
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
331
343
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
344
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
345
|
+
}
|
|
346
|
+
if (parts.length === 0) {
|
|
347
|
+
return showMs ? "0ms" : "0s";
|
|
332
348
|
}
|
|
333
|
-
return parts.join(
|
|
349
|
+
return parts.join(separator);
|
|
334
350
|
};
|
|
335
351
|
var formatDate = (input, options = {}) => {
|
|
336
352
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -457,6 +473,18 @@ var toMs = (value, unit = "seconds") => {
|
|
|
457
473
|
};
|
|
458
474
|
return value * multipliers[unit];
|
|
459
475
|
};
|
|
476
|
+
function startTimer(options = {}) {
|
|
477
|
+
const start = Date.now();
|
|
478
|
+
const fmt = options.format ?? "ms";
|
|
479
|
+
const getElapsed = () => {
|
|
480
|
+
const elapsed = Date.now() - start;
|
|
481
|
+
if (fmt === "compact") {
|
|
482
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
483
|
+
}
|
|
484
|
+
return elapsed;
|
|
485
|
+
};
|
|
486
|
+
return { stop: getElapsed, elapsed: getElapsed };
|
|
487
|
+
}
|
|
460
488
|
|
|
461
489
|
// src/shared/flow.ts
|
|
462
490
|
var flow_exports = {};
|
|
@@ -554,14 +582,9 @@ __export(log_exports, {
|
|
|
554
582
|
info: () => info,
|
|
555
583
|
label: () => label,
|
|
556
584
|
log: () => log,
|
|
557
|
-
startTimer: () => startTimer,
|
|
558
585
|
warn: () => warn
|
|
559
586
|
});
|
|
560
587
|
var stringify = (value) => JSON.stringify(value, null, 2);
|
|
561
|
-
var startTimer = () => {
|
|
562
|
-
const start = Date.now();
|
|
563
|
-
return () => Date.now() - start;
|
|
564
|
-
};
|
|
565
588
|
var log = (...values) => {
|
|
566
589
|
console.log(...values.map(stringify));
|
|
567
590
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -261,15 +261,23 @@ __export(time_exports, {
|
|
|
261
261
|
formatThreadDateRange: () => formatThreadDateRange,
|
|
262
262
|
now: () => now,
|
|
263
263
|
sleep: () => sleep,
|
|
264
|
+
startTimer: () => startTimer,
|
|
264
265
|
toMs: () => toMs
|
|
265
266
|
});
|
|
266
267
|
var formatDuration = (ms, options = {}) => {
|
|
267
268
|
if (ms === null || ms === void 0) return "--:--";
|
|
268
|
-
const {
|
|
269
|
-
|
|
269
|
+
const {
|
|
270
|
+
format: fmt = "clock",
|
|
271
|
+
showZero = false,
|
|
272
|
+
showMs = false,
|
|
273
|
+
spaces = true
|
|
274
|
+
} = options;
|
|
275
|
+
const absMs = Math.abs(ms);
|
|
276
|
+
const totalSeconds = Math.floor(absMs / 1e3);
|
|
270
277
|
const hours = Math.floor(totalSeconds / 3600);
|
|
271
278
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
272
279
|
const seconds = totalSeconds % 60;
|
|
280
|
+
const milliseconds = absMs % 1e3;
|
|
273
281
|
if (fmt === "clock") {
|
|
274
282
|
if (hours > 0) {
|
|
275
283
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -312,23 +320,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
312
320
|
}
|
|
313
321
|
}
|
|
314
322
|
const parts = [];
|
|
323
|
+
const separator = spaces ? " " : "";
|
|
315
324
|
if (showZero) {
|
|
316
325
|
const hasHours = hours > 0;
|
|
317
326
|
const hasMinutes = minutes > 0;
|
|
318
327
|
const hasSeconds = seconds > 0;
|
|
319
|
-
|
|
328
|
+
const hasMs = milliseconds > 0;
|
|
329
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
320
330
|
if (hasHours) parts.push(`${hours}h`);
|
|
321
331
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
322
|
-
|
|
332
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
333
|
+
parts.push(`${seconds}s`);
|
|
334
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
323
335
|
} else {
|
|
324
|
-
parts.push("0s");
|
|
336
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
325
337
|
}
|
|
326
338
|
} else {
|
|
327
339
|
if (hours > 0) parts.push(`${hours}h`);
|
|
328
340
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
329
341
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
342
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
343
|
+
}
|
|
344
|
+
if (parts.length === 0) {
|
|
345
|
+
return showMs ? "0ms" : "0s";
|
|
330
346
|
}
|
|
331
|
-
return parts.join(
|
|
347
|
+
return parts.join(separator);
|
|
332
348
|
};
|
|
333
349
|
var formatDate = (input, options = {}) => {
|
|
334
350
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -455,6 +471,18 @@ var toMs = (value, unit = "seconds") => {
|
|
|
455
471
|
};
|
|
456
472
|
return value * multipliers[unit];
|
|
457
473
|
};
|
|
474
|
+
function startTimer(options = {}) {
|
|
475
|
+
const start = Date.now();
|
|
476
|
+
const fmt = options.format ?? "ms";
|
|
477
|
+
const getElapsed = () => {
|
|
478
|
+
const elapsed = Date.now() - start;
|
|
479
|
+
if (fmt === "compact") {
|
|
480
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
481
|
+
}
|
|
482
|
+
return elapsed;
|
|
483
|
+
};
|
|
484
|
+
return { stop: getElapsed, elapsed: getElapsed };
|
|
485
|
+
}
|
|
458
486
|
|
|
459
487
|
// src/shared/flow.ts
|
|
460
488
|
var flow_exports = {};
|
|
@@ -552,14 +580,9 @@ __export(log_exports, {
|
|
|
552
580
|
info: () => info,
|
|
553
581
|
label: () => label,
|
|
554
582
|
log: () => log,
|
|
555
|
-
startTimer: () => startTimer,
|
|
556
583
|
warn: () => warn
|
|
557
584
|
});
|
|
558
585
|
var stringify = (value) => JSON.stringify(value, null, 2);
|
|
559
|
-
var startTimer = () => {
|
|
560
|
-
const start = Date.now();
|
|
561
|
-
return () => Date.now() - start;
|
|
562
|
-
};
|
|
563
586
|
var log = (...values) => {
|
|
564
587
|
console.log(...values.map(stringify));
|
|
565
588
|
};
|
package/dist/shared/log.d.ts
CHANGED
|
@@ -17,16 +17,6 @@
|
|
|
17
17
|
* log.header("HANDLER START"); // [audio-processor] ========== HANDLER START ==========
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
|
-
/**
|
|
21
|
-
* Starts a timer and returns a function that returns elapsed milliseconds.
|
|
22
|
-
* @returns A function that returns the elapsed time in ms since the timer started
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript // Timer
|
|
25
|
-
* const elapsed = Log.startTimer();
|
|
26
|
-
* // ... do work ...
|
|
27
|
-
* log.header(`COMPLETE (${elapsed()}ms)`); // ========== COMPLETE (123ms) ==========```
|
|
28
|
-
*/
|
|
29
|
-
export declare const startTimer: () => () => number;
|
|
30
20
|
/**
|
|
31
21
|
* Logs values to the console (no prefix).
|
|
32
22
|
* @param values - Values to log (will be JSON stringified)
|
package/dist/shared/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/shared/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/shared/log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,GAAI,GAAG,QAAQ,OAAO,EAAE,SAEvC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,GAAI,GAAG,QAAQ,OAAO,EAAE,SAExC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,GAAI,GAAG,QAAQ,OAAO,EAAE,SAExC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GAAI,GAAG,QAAQ,OAAO,EAAE,SAEzC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,SAAS,MAAM,SAErC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,KAAK,GAAI,MAAM,MAAM;IAChC,iEAAiE;sBAC/C,OAAO,EAAE;IAG3B,+EAA+E;sBAC7D,OAAO,EAAE;IAG3B,iFAAiF;uBAC9D,OAAO,EAAE;IAG5B,iGAAiG;sBAC/E,MAAM;CAGxB,CAAC"}
|
package/dist/shared/time.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ type DurationOptions = {
|
|
|
5
5
|
format?: DurationFormat;
|
|
6
6
|
/** Show zero values for intermediate units (e.g., "1h 0m 30s" vs "1h 30s") */
|
|
7
7
|
showZero?: boolean;
|
|
8
|
+
/** Include milliseconds in compact format (e.g., "1s 200ms") */
|
|
9
|
+
showMs?: boolean;
|
|
10
|
+
/** Use spaces between units (default: true). e.g., "1s 200ms" vs "1s200ms" */
|
|
11
|
+
spaces?: boolean;
|
|
8
12
|
};
|
|
9
13
|
/**
|
|
10
14
|
* Formats milliseconds into human-readable duration strings
|
|
@@ -13,6 +17,8 @@ type DurationOptions = {
|
|
|
13
17
|
* @param {Object} [options={}] - Configuration options
|
|
14
18
|
* @param {string} [options.format="clock"] - format
|
|
15
19
|
* @param {boolean} [options.showZero=false] - show zero prefix
|
|
20
|
+
* @param {boolean} [options.showMs=false] - include milliseconds (compact format only)
|
|
21
|
+
* @param {boolean} [options.spaces=true] - use spaces between units (compact format only)
|
|
16
22
|
*
|
|
17
23
|
* @example
|
|
18
24
|
* formatDuration(90000) // "1:30"
|
|
@@ -25,6 +31,8 @@ type DurationOptions = {
|
|
|
25
31
|
* formatDuration(1400, { format: "fractional" }) // "1.4s"
|
|
26
32
|
* formatDuration(45300, { format: "fractional" }) // "45.3s"
|
|
27
33
|
* formatDuration(64400, { format: "fractional" }) // "1m 4.4s"
|
|
34
|
+
* formatDuration(1234, { format: "compact", showMs: true }) // "1s 234ms"
|
|
35
|
+
* formatDuration(1234, { format: "compact", showMs: true, spaces: false }) // "1s234ms"
|
|
28
36
|
*/
|
|
29
37
|
export declare const formatDuration: (ms: number | null | undefined, options?: DurationOptions) => string;
|
|
30
38
|
type DateInput = Date | string | number;
|
|
@@ -108,5 +116,41 @@ export declare const now: () => number;
|
|
|
108
116
|
* const ms = toMs(5, "minutes") // Convert 5 minutes to milliseconds
|
|
109
117
|
*/
|
|
110
118
|
export declare const toMs: (value: number, unit?: Exclude<TimeUnit, "businessDays">) => number;
|
|
119
|
+
type TimerFormat = "ms" | "compact";
|
|
120
|
+
type TimerOptions<T extends TimerFormat = "ms"> = {
|
|
121
|
+
format?: T;
|
|
122
|
+
};
|
|
123
|
+
type Timer<T extends TimerFormat> = {
|
|
124
|
+
/** Returns elapsed time since timer started. For "ms" format returns number, for "compact" returns string like "1s 234ms" */
|
|
125
|
+
stop: () => T extends "compact" ? string : number;
|
|
126
|
+
/** Returns current elapsed time without stopping (same as stop, but semantically for intermediate checks) */
|
|
127
|
+
elapsed: () => T extends "compact" ? string : number;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Starts a timer and returns an object with stop/elapsed methods.
|
|
131
|
+
* @param options - Optional configuration. `format: "ms"` (default) returns numbers, `format: "compact"` returns strings like "1s 234ms"
|
|
132
|
+
* @returns Timer object with stop() and elapsed() methods
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // Default (returns milliseconds as number)
|
|
137
|
+
* const timer = Time.startTimer();
|
|
138
|
+
* // ... do work ...
|
|
139
|
+
* const ms = timer.stop(); // 1234
|
|
140
|
+
*
|
|
141
|
+
* // Compact format (returns string)
|
|
142
|
+
* const timer = Time.startTimer({ format: "compact" });
|
|
143
|
+
* // ... do work ...
|
|
144
|
+
* const formatted = timer.stop(); // "1s 234ms"
|
|
145
|
+
*
|
|
146
|
+
* // Check elapsed time without "stopping"
|
|
147
|
+
* const timer = Time.startTimer();
|
|
148
|
+
* console.log(timer.elapsed()); // 500
|
|
149
|
+
* // ... more work ...
|
|
150
|
+
* console.log(timer.stop()); // 1234
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function startTimer(): Timer<"ms">;
|
|
154
|
+
export declare function startTimer<T extends TimerFormat>(options: TimerOptions<T>): Timer<T>;
|
|
111
155
|
export {};
|
|
112
156
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/shared/time.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMvC,KAAK,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,CAAC;AAElE,KAAK,eAAe,GAAG;IACrB,kHAAkH;IAClH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/shared/time.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMvC,KAAK,cAAc,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,YAAY,CAAC;AAElE,KAAK,eAAe,GAAG;IACrB,kHAAkH;IAClH,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gEAAgE;IAChE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,cAAc,GACzB,IAAI,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7B,UAAS,eAAoB,WA2G9B,CAAC;AAMF,KAAK,SAAS,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAExC,KAAK,eAAe,GAChB,KAAK,GACL,OAAO,GACP,QAAQ,GACR,MAAM,GACN,UAAU,GACV,MAAM,CAAC;AAEX,KAAK,WAAW,GAAG;IACjB,8BAA8B;IAC9B,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,6BAA6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