qstd 0.3.0 → 0.3.2
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 +22 -16
- package/dist/client/index.js +22 -16
- package/dist/server/aws/ddb/domain.d.ts +5 -5
- package/dist/server/aws/ddb/domain.d.ts.map +1 -1
- package/dist/server/index.cjs +22 -16
- package/dist/server/index.js +22 -16
- package/dist/shared/time.d.ts +11 -3
- package/dist/shared/time.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client/index.cjs
CHANGED
|
@@ -265,11 +265,18 @@ __export(time_exports, {
|
|
|
265
265
|
});
|
|
266
266
|
var formatDuration = (ms, options = {}) => {
|
|
267
267
|
if (ms === null || ms === void 0) return "--:--";
|
|
268
|
-
const {
|
|
269
|
-
|
|
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);
|
|
270
276
|
const hours = Math.floor(totalSeconds / 3600);
|
|
271
277
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
272
278
|
const seconds = totalSeconds % 60;
|
|
279
|
+
const milliseconds = absMs % 1e3;
|
|
273
280
|
if (fmt === "clock") {
|
|
274
281
|
if (hours > 0) {
|
|
275
282
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -312,23 +319,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
312
319
|
}
|
|
313
320
|
}
|
|
314
321
|
const parts = [];
|
|
322
|
+
const separator = spaces ? " " : "";
|
|
315
323
|
if (showZero) {
|
|
316
324
|
const hasHours = hours > 0;
|
|
317
325
|
const hasMinutes = minutes > 0;
|
|
318
326
|
const hasSeconds = seconds > 0;
|
|
319
|
-
|
|
327
|
+
const hasMs = milliseconds > 0;
|
|
328
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
320
329
|
if (hasHours) parts.push(`${hours}h`);
|
|
321
330
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
322
|
-
|
|
331
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
332
|
+
parts.push(`${seconds}s`);
|
|
333
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
323
334
|
} else {
|
|
324
|
-
parts.push("0s");
|
|
335
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
325
336
|
}
|
|
326
337
|
} else {
|
|
327
338
|
if (hours > 0) parts.push(`${hours}h`);
|
|
328
339
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
329
340
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
341
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
330
342
|
}
|
|
331
|
-
|
|
343
|
+
if (parts.length === 0) {
|
|
344
|
+
return showMs ? "0ms" : "0s";
|
|
345
|
+
}
|
|
346
|
+
return parts.join(separator);
|
|
332
347
|
};
|
|
333
348
|
var formatDate = (input, options = {}) => {
|
|
334
349
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -461,16 +476,7 @@ function startTimer(options = {}) {
|
|
|
461
476
|
const getElapsed = () => {
|
|
462
477
|
const elapsed = Date.now() - start;
|
|
463
478
|
if (fmt === "compact") {
|
|
464
|
-
|
|
465
|
-
const minutes = Math.floor(elapsed % 36e5 / 6e4);
|
|
466
|
-
const seconds = Math.floor(elapsed % 6e4 / 1e3);
|
|
467
|
-
const milliseconds = elapsed % 1e3;
|
|
468
|
-
let result = "";
|
|
469
|
-
if (hours > 0) result += `${hours}h`;
|
|
470
|
-
if (minutes > 0) result += `${minutes}m`;
|
|
471
|
-
if (seconds > 0) result += `${seconds}s`;
|
|
472
|
-
if (milliseconds > 0 || result === "") result += `${milliseconds}ms`;
|
|
473
|
-
return result;
|
|
479
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
474
480
|
}
|
|
475
481
|
return elapsed;
|
|
476
482
|
};
|
package/dist/client/index.js
CHANGED
|
@@ -263,11 +263,18 @@ __export(time_exports, {
|
|
|
263
263
|
});
|
|
264
264
|
var formatDuration = (ms, options = {}) => {
|
|
265
265
|
if (ms === null || ms === void 0) return "--:--";
|
|
266
|
-
const {
|
|
267
|
-
|
|
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);
|
|
268
274
|
const hours = Math.floor(totalSeconds / 3600);
|
|
269
275
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
270
276
|
const seconds = totalSeconds % 60;
|
|
277
|
+
const milliseconds = absMs % 1e3;
|
|
271
278
|
if (fmt === "clock") {
|
|
272
279
|
if (hours > 0) {
|
|
273
280
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -310,23 +317,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
310
317
|
}
|
|
311
318
|
}
|
|
312
319
|
const parts = [];
|
|
320
|
+
const separator = spaces ? " " : "";
|
|
313
321
|
if (showZero) {
|
|
314
322
|
const hasHours = hours > 0;
|
|
315
323
|
const hasMinutes = minutes > 0;
|
|
316
324
|
const hasSeconds = seconds > 0;
|
|
317
|
-
|
|
325
|
+
const hasMs = milliseconds > 0;
|
|
326
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
318
327
|
if (hasHours) parts.push(`${hours}h`);
|
|
319
328
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
320
|
-
|
|
329
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
330
|
+
parts.push(`${seconds}s`);
|
|
331
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
321
332
|
} else {
|
|
322
|
-
parts.push("0s");
|
|
333
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
323
334
|
}
|
|
324
335
|
} else {
|
|
325
336
|
if (hours > 0) parts.push(`${hours}h`);
|
|
326
337
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
327
338
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
339
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
328
340
|
}
|
|
329
|
-
|
|
341
|
+
if (parts.length === 0) {
|
|
342
|
+
return showMs ? "0ms" : "0s";
|
|
343
|
+
}
|
|
344
|
+
return parts.join(separator);
|
|
330
345
|
};
|
|
331
346
|
var formatDate = (input, options = {}) => {
|
|
332
347
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -459,16 +474,7 @@ function startTimer(options = {}) {
|
|
|
459
474
|
const getElapsed = () => {
|
|
460
475
|
const elapsed = Date.now() - start;
|
|
461
476
|
if (fmt === "compact") {
|
|
462
|
-
|
|
463
|
-
const minutes = Math.floor(elapsed % 36e5 / 6e4);
|
|
464
|
-
const seconds = Math.floor(elapsed % 6e4 / 1e3);
|
|
465
|
-
const milliseconds = elapsed % 1e3;
|
|
466
|
-
let result = "";
|
|
467
|
-
if (hours > 0) result += `${hours}h`;
|
|
468
|
-
if (minutes > 0) result += `${minutes}m`;
|
|
469
|
-
if (seconds > 0) result += `${seconds}s`;
|
|
470
|
-
if (milliseconds > 0 || result === "") result += `${milliseconds}ms`;
|
|
471
|
-
return result;
|
|
477
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
472
478
|
}
|
|
473
479
|
return elapsed;
|
|
474
480
|
};
|
|
@@ -3,7 +3,7 @@ import * as _t from "./types";
|
|
|
3
3
|
export type Client = ReturnType<typeof create>;
|
|
4
4
|
export declare const create: (props?: {
|
|
5
5
|
credentials?: _t.Credentials;
|
|
6
|
-
tableName
|
|
6
|
+
tableName?: string;
|
|
7
7
|
}) => {
|
|
8
8
|
client: DynamoDBDocumentClient;
|
|
9
9
|
tableName: string | undefined;
|
|
@@ -166,7 +166,7 @@ export declare function batchGet<T extends Record<string, unknown>>(ddb: Client,
|
|
|
166
166
|
* });
|
|
167
167
|
*/
|
|
168
168
|
export declare function batchWrite<T extends Record<string, unknown>>(ddb: Client, props: {
|
|
169
|
-
tableName
|
|
169
|
+
tableName?: string;
|
|
170
170
|
items: {
|
|
171
171
|
item: T;
|
|
172
172
|
cond?: string;
|
|
@@ -174,7 +174,7 @@ export declare function batchWrite<T extends Record<string, unknown>>(ddb: Clien
|
|
|
174
174
|
maxRetries?: number;
|
|
175
175
|
}): Promise<_t.BatchWriteResult>;
|
|
176
176
|
export declare function batchWrite<T extends Record<string, unknown>, I>(ddb: Client, props: {
|
|
177
|
-
tableName
|
|
177
|
+
tableName?: string;
|
|
178
178
|
items: I[];
|
|
179
179
|
transform: (item: I) => {
|
|
180
180
|
item: T;
|
|
@@ -228,7 +228,7 @@ export declare function batchWrite<T extends Record<string, unknown>, I>(ddb: Cl
|
|
|
228
228
|
* });
|
|
229
229
|
*/
|
|
230
230
|
export declare function batchDelete(ddb: Client, props: {
|
|
231
|
-
tableName
|
|
231
|
+
tableName?: string;
|
|
232
232
|
keys: Array<{
|
|
233
233
|
key: _t.Key;
|
|
234
234
|
cond?: string;
|
|
@@ -236,7 +236,7 @@ export declare function batchDelete(ddb: Client, props: {
|
|
|
236
236
|
maxRetries?: number;
|
|
237
237
|
}): Promise<_t.BatchDeleteResult>;
|
|
238
238
|
export declare function batchDelete<I>(ddb: Client, props: {
|
|
239
|
-
tableName
|
|
239
|
+
tableName?: string;
|
|
240
240
|
keys: I[];
|
|
241
241
|
transform: (item: I) => {
|
|
242
242
|
key: _t.Key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../../../src/server/aws/ddb/domain.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,sBAA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I,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;AACjC,wBAAgB,WAAW,CAAC,CAAC,EAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE;IACL,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK;QAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,EAAE,CAAC,iBAAiB,CAAC,CAAC;AAkHjC,eAAO,MAAM,WAAW,GAAI,KAAK,MAAM,EAAE,WAAW,MAAM,yEAIzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GACtB,KAAK,MAAM,EACX,OAAO;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,qBAkB7B,CAAC"}
|
package/dist/server/index.cjs
CHANGED
|
@@ -268,11 +268,18 @@ __export(time_exports, {
|
|
|
268
268
|
});
|
|
269
269
|
var formatDuration = (ms, options = {}) => {
|
|
270
270
|
if (ms === null || ms === void 0) return "--:--";
|
|
271
|
-
const {
|
|
272
|
-
|
|
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);
|
|
273
279
|
const hours = Math.floor(totalSeconds / 3600);
|
|
274
280
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
275
281
|
const seconds = totalSeconds % 60;
|
|
282
|
+
const milliseconds = absMs % 1e3;
|
|
276
283
|
if (fmt === "clock") {
|
|
277
284
|
if (hours > 0) {
|
|
278
285
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -315,23 +322,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
315
322
|
}
|
|
316
323
|
}
|
|
317
324
|
const parts = [];
|
|
325
|
+
const separator = spaces ? " " : "";
|
|
318
326
|
if (showZero) {
|
|
319
327
|
const hasHours = hours > 0;
|
|
320
328
|
const hasMinutes = minutes > 0;
|
|
321
329
|
const hasSeconds = seconds > 0;
|
|
322
|
-
|
|
330
|
+
const hasMs = milliseconds > 0;
|
|
331
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
323
332
|
if (hasHours) parts.push(`${hours}h`);
|
|
324
333
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
325
|
-
|
|
334
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
335
|
+
parts.push(`${seconds}s`);
|
|
336
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
326
337
|
} else {
|
|
327
|
-
parts.push("0s");
|
|
338
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
328
339
|
}
|
|
329
340
|
} else {
|
|
330
341
|
if (hours > 0) parts.push(`${hours}h`);
|
|
331
342
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
332
343
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
344
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
333
345
|
}
|
|
334
|
-
|
|
346
|
+
if (parts.length === 0) {
|
|
347
|
+
return showMs ? "0ms" : "0s";
|
|
348
|
+
}
|
|
349
|
+
return parts.join(separator);
|
|
335
350
|
};
|
|
336
351
|
var formatDate = (input, options = {}) => {
|
|
337
352
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -464,16 +479,7 @@ function startTimer(options = {}) {
|
|
|
464
479
|
const getElapsed = () => {
|
|
465
480
|
const elapsed = Date.now() - start;
|
|
466
481
|
if (fmt === "compact") {
|
|
467
|
-
|
|
468
|
-
const minutes = Math.floor(elapsed % 36e5 / 6e4);
|
|
469
|
-
const seconds = Math.floor(elapsed % 6e4 / 1e3);
|
|
470
|
-
const milliseconds = elapsed % 1e3;
|
|
471
|
-
let result = "";
|
|
472
|
-
if (hours > 0) result += `${hours}h`;
|
|
473
|
-
if (minutes > 0) result += `${minutes}m`;
|
|
474
|
-
if (seconds > 0) result += `${seconds}s`;
|
|
475
|
-
if (milliseconds > 0 || result === "") result += `${milliseconds}ms`;
|
|
476
|
-
return result;
|
|
482
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
477
483
|
}
|
|
478
484
|
return elapsed;
|
|
479
485
|
};
|
package/dist/server/index.js
CHANGED
|
@@ -266,11 +266,18 @@ __export(time_exports, {
|
|
|
266
266
|
});
|
|
267
267
|
var formatDuration = (ms, options = {}) => {
|
|
268
268
|
if (ms === null || ms === void 0) return "--:--";
|
|
269
|
-
const {
|
|
270
|
-
|
|
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);
|
|
271
277
|
const hours = Math.floor(totalSeconds / 3600);
|
|
272
278
|
const minutes = Math.floor(totalSeconds % 3600 / 60);
|
|
273
279
|
const seconds = totalSeconds % 60;
|
|
280
|
+
const milliseconds = absMs % 1e3;
|
|
274
281
|
if (fmt === "clock") {
|
|
275
282
|
if (hours > 0) {
|
|
276
283
|
return `${hours}:${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
|
@@ -313,23 +320,31 @@ var formatDuration = (ms, options = {}) => {
|
|
|
313
320
|
}
|
|
314
321
|
}
|
|
315
322
|
const parts = [];
|
|
323
|
+
const separator = spaces ? " " : "";
|
|
316
324
|
if (showZero) {
|
|
317
325
|
const hasHours = hours > 0;
|
|
318
326
|
const hasMinutes = minutes > 0;
|
|
319
327
|
const hasSeconds = seconds > 0;
|
|
320
|
-
|
|
328
|
+
const hasMs = milliseconds > 0;
|
|
329
|
+
if (hasHours || hasMinutes || hasSeconds || showMs && hasMs) {
|
|
321
330
|
if (hasHours) parts.push(`${hours}h`);
|
|
322
331
|
if (hasHours || hasMinutes) parts.push(`${minutes}m`);
|
|
323
|
-
|
|
332
|
+
if (hasHours || hasMinutes || hasSeconds || !showMs)
|
|
333
|
+
parts.push(`${seconds}s`);
|
|
334
|
+
if (showMs) parts.push(`${milliseconds}ms`);
|
|
324
335
|
} else {
|
|
325
|
-
parts.push("0s");
|
|
336
|
+
parts.push(showMs ? "0ms" : "0s");
|
|
326
337
|
}
|
|
327
338
|
} else {
|
|
328
339
|
if (hours > 0) parts.push(`${hours}h`);
|
|
329
340
|
if (minutes > 0) parts.push(`${minutes}m`);
|
|
330
341
|
if (seconds > 0) parts.push(`${seconds}s`);
|
|
342
|
+
if (showMs && milliseconds > 0) parts.push(`${milliseconds}ms`);
|
|
331
343
|
}
|
|
332
|
-
|
|
344
|
+
if (parts.length === 0) {
|
|
345
|
+
return showMs ? "0ms" : "0s";
|
|
346
|
+
}
|
|
347
|
+
return parts.join(separator);
|
|
333
348
|
};
|
|
334
349
|
var formatDate = (input, options = {}) => {
|
|
335
350
|
const { style = "medium", pattern, includeTime = false } = options;
|
|
@@ -462,16 +477,7 @@ function startTimer(options = {}) {
|
|
|
462
477
|
const getElapsed = () => {
|
|
463
478
|
const elapsed = Date.now() - start;
|
|
464
479
|
if (fmt === "compact") {
|
|
465
|
-
|
|
466
|
-
const minutes = Math.floor(elapsed % 36e5 / 6e4);
|
|
467
|
-
const seconds = Math.floor(elapsed % 6e4 / 1e3);
|
|
468
|
-
const milliseconds = elapsed % 1e3;
|
|
469
|
-
let result = "";
|
|
470
|
-
if (hours > 0) result += `${hours}h`;
|
|
471
|
-
if (minutes > 0) result += `${minutes}m`;
|
|
472
|
-
if (seconds > 0) result += `${seconds}s`;
|
|
473
|
-
if (milliseconds > 0 || result === "") result += `${milliseconds}ms`;
|
|
474
|
-
return result;
|
|
480
|
+
return formatDuration(elapsed, { format: "compact", showMs: true });
|
|
475
481
|
}
|
|
476
482
|
return elapsed;
|
|
477
483
|
};
|
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;
|
|
@@ -113,14 +121,14 @@ type TimerOptions<T extends TimerFormat = "ms"> = {
|
|
|
113
121
|
format?: T;
|
|
114
122
|
};
|
|
115
123
|
type Timer<T extends TimerFormat> = {
|
|
116
|
-
/** Returns elapsed time since timer started. For "ms" format returns number, for "compact" returns string like "
|
|
124
|
+
/** Returns elapsed time since timer started. For "ms" format returns number, for "compact" returns string like "1s 234ms" */
|
|
117
125
|
stop: () => T extends "compact" ? string : number;
|
|
118
126
|
/** Returns current elapsed time without stopping (same as stop, but semantically for intermediate checks) */
|
|
119
127
|
elapsed: () => T extends "compact" ? string : number;
|
|
120
128
|
};
|
|
121
129
|
/**
|
|
122
130
|
* Starts a timer and returns an object with stop/elapsed methods.
|
|
123
|
-
* @param options - Optional configuration. `format: "ms"` (default) returns numbers, `format: "compact"` returns strings like "
|
|
131
|
+
* @param options - Optional configuration. `format: "ms"` (default) returns numbers, `format: "compact"` returns strings like "1s 234ms"
|
|
124
132
|
* @returns Timer object with stop() and elapsed() methods
|
|
125
133
|
*
|
|
126
134
|
* @example
|
|
@@ -133,7 +141,7 @@ type Timer<T extends TimerFormat> = {
|
|
|
133
141
|
* // Compact format (returns string)
|
|
134
142
|
* const timer = Time.startTimer({ format: "compact" });
|
|
135
143
|
* // ... do work ...
|
|
136
|
-
* const formatted = timer.stop(); // "
|
|
144
|
+
* const formatted = timer.stop(); // "1s 234ms"
|
|
137
145
|
*
|
|
138
146
|
* // Check elapsed time without "stopping"
|
|
139
147
|
* const timer = Time.startTimer();
|
|
@@ -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;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