@evolu/common 8.1.0 → 8.3.0
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/src/Function.d.ts +1 -0
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Http.d.ts +9 -0
- package/dist/src/Http.d.ts.map +1 -1
- package/dist/src/Number.d.ts +66 -6
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +11 -3
- package/dist/src/Object.d.ts +1 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/RefCount.d.ts +1 -0
- package/dist/src/RefCount.d.ts.map +1 -1
- package/dist/src/Relation.d.ts +2 -0
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Resource.d.ts +1 -0
- package/dist/src/Resource.d.ts.map +1 -1
- package/dist/src/Result.d.ts +383 -548
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +296 -46
- package/dist/src/Schedule.d.ts +2 -2
- package/dist/src/Schedule.d.ts.map +1 -1
- package/dist/src/StackTrace.d.ts +1 -0
- package/dist/src/StackTrace.d.ts.map +1 -1
- package/dist/src/Task.d.ts +978 -1061
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1010 -159
- package/dist/src/Time.d.ts +71 -34
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +77 -1
- package/dist/src/Type.d.ts +1740 -795
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1634 -211
- package/dist/src/Types.d.ts +0 -24
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/intl/_en.d.ts +126 -0
- package/dist/src/intl/_en.d.ts.map +1 -0
- package/dist/src/intl/_en.js +267 -0
- package/dist/src/intl/ar.d.ts +117 -0
- package/dist/src/intl/ar.d.ts.map +1 -0
- package/dist/src/intl/ar.js +245 -0
- package/dist/src/intl/bn.d.ts +117 -0
- package/dist/src/intl/bn.d.ts.map +1 -0
- package/dist/src/intl/bn.js +258 -0
- package/dist/src/intl/ca.d.ts +117 -0
- package/dist/src/intl/ca.d.ts.map +1 -0
- package/dist/src/intl/ca.js +258 -0
- package/dist/src/intl/cs.d.ts +30 -7
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +65 -28
- package/dist/src/intl/da.d.ts +117 -0
- package/dist/src/intl/da.d.ts.map +1 -0
- package/dist/src/intl/da.js +258 -0
- package/dist/src/intl/de.d.ts +117 -0
- package/dist/src/intl/de.d.ts.map +1 -0
- package/dist/src/intl/de.js +258 -0
- package/dist/src/intl/el.d.ts +117 -0
- package/dist/src/intl/el.d.ts.map +1 -0
- package/dist/src/intl/el.js +265 -0
- package/dist/src/intl/es.d.ts +117 -0
- package/dist/src/intl/es.d.ts.map +1 -0
- package/dist/src/intl/es.js +258 -0
- package/dist/src/intl/fa.d.ts +117 -0
- package/dist/src/intl/fa.d.ts.map +1 -0
- package/dist/src/intl/fa.js +258 -0
- package/dist/src/intl/fi.d.ts +117 -0
- package/dist/src/intl/fi.d.ts.map +1 -0
- package/dist/src/intl/fi.js +258 -0
- package/dist/src/intl/fil.d.ts +117 -0
- package/dist/src/intl/fil.d.ts.map +1 -0
- package/dist/src/intl/fil.js +258 -0
- package/dist/src/intl/fr.d.ts +117 -0
- package/dist/src/intl/fr.d.ts.map +1 -0
- package/dist/src/intl/fr.js +258 -0
- package/dist/src/intl/he.d.ts +117 -0
- package/dist/src/intl/he.d.ts.map +1 -0
- package/dist/src/intl/he.js +258 -0
- package/dist/src/intl/hi.d.ts +117 -0
- package/dist/src/intl/hi.d.ts.map +1 -0
- package/dist/src/intl/hi.js +258 -0
- package/dist/src/intl/hr.d.ts +117 -0
- package/dist/src/intl/hr.d.ts.map +1 -0
- package/dist/src/intl/hr.js +265 -0
- package/dist/src/intl/hu.d.ts +63 -0
- package/dist/src/intl/hu.d.ts.map +1 -0
- package/dist/src/intl/hu.js +204 -0
- package/dist/src/intl/id.d.ts +117 -0
- package/dist/src/intl/id.d.ts.map +1 -0
- package/dist/src/intl/id.js +258 -0
- package/dist/src/intl/index.d.ts +42 -0
- package/dist/src/intl/index.d.ts.map +1 -1
- package/dist/src/intl/index.js +42 -0
- package/dist/src/intl/it.d.ts +117 -0
- package/dist/src/intl/it.d.ts.map +1 -0
- package/dist/src/intl/it.js +258 -0
- package/dist/src/intl/ja.d.ts +117 -0
- package/dist/src/intl/ja.d.ts.map +1 -0
- package/dist/src/intl/ja.js +258 -0
- package/dist/src/intl/ko.d.ts +117 -0
- package/dist/src/intl/ko.d.ts.map +1 -0
- package/dist/src/intl/ko.js +258 -0
- package/dist/src/intl/ml.d.ts +117 -0
- package/dist/src/intl/ml.d.ts.map +1 -0
- package/dist/src/intl/ml.js +258 -0
- package/dist/src/intl/mr.d.ts +117 -0
- package/dist/src/intl/mr.d.ts.map +1 -0
- package/dist/src/intl/mr.js +258 -0
- package/dist/src/intl/ms.d.ts +117 -0
- package/dist/src/intl/ms.d.ts.map +1 -0
- package/dist/src/intl/ms.js +245 -0
- package/dist/src/intl/nb.d.ts +63 -0
- package/dist/src/intl/nb.d.ts.map +1 -0
- package/dist/src/intl/nb.js +191 -0
- package/dist/src/intl/nl.d.ts +117 -0
- package/dist/src/intl/nl.d.ts.map +1 -0
- package/dist/src/intl/nl.js +258 -0
- package/dist/src/intl/pa.d.ts +117 -0
- package/dist/src/intl/pa.d.ts.map +1 -0
- package/dist/src/intl/pa.js +258 -0
- package/dist/src/intl/pl.d.ts +117 -0
- package/dist/src/intl/pl.d.ts.map +1 -0
- package/dist/src/intl/pl.js +242 -0
- package/dist/src/intl/pt-BR.d.ts +117 -0
- package/dist/src/intl/pt-BR.d.ts.map +1 -0
- package/dist/src/intl/pt-BR.js +258 -0
- package/dist/src/intl/pt.d.ts +117 -0
- package/dist/src/intl/pt.d.ts.map +1 -0
- package/dist/src/intl/pt.js +246 -0
- package/dist/src/intl/ro.d.ts +117 -0
- package/dist/src/intl/ro.d.ts.map +1 -0
- package/dist/src/intl/ro.js +258 -0
- package/dist/src/intl/sk.d.ts +117 -0
- package/dist/src/intl/sk.d.ts.map +1 -0
- package/dist/src/intl/sk.js +244 -0
- package/dist/src/intl/sl.d.ts +117 -0
- package/dist/src/intl/sl.d.ts.map +1 -0
- package/dist/src/intl/sl.js +258 -0
- package/dist/src/intl/sv.d.ts +117 -0
- package/dist/src/intl/sv.d.ts.map +1 -0
- package/dist/src/intl/sv.js +258 -0
- package/dist/src/intl/sw.d.ts +63 -0
- package/dist/src/intl/sw.d.ts.map +1 -0
- package/dist/src/intl/sw.js +191 -0
- package/dist/src/intl/ta.d.ts +117 -0
- package/dist/src/intl/ta.d.ts.map +1 -0
- package/dist/src/intl/ta.js +258 -0
- package/dist/src/intl/te.d.ts +117 -0
- package/dist/src/intl/te.d.ts.map +1 -0
- package/dist/src/intl/te.js +258 -0
- package/dist/src/intl/th.d.ts +117 -0
- package/dist/src/intl/th.d.ts.map +1 -0
- package/dist/src/intl/th.js +258 -0
- package/dist/src/intl/tr.d.ts +117 -0
- package/dist/src/intl/tr.d.ts.map +1 -0
- package/dist/src/intl/tr.js +255 -0
- package/dist/src/intl/uk.d.ts +117 -0
- package/dist/src/intl/uk.d.ts.map +1 -0
- package/dist/src/intl/uk.js +258 -0
- package/dist/src/intl/ur.d.ts +117 -0
- package/dist/src/intl/ur.d.ts.map +1 -0
- package/dist/src/intl/ur.js +245 -0
- package/dist/src/intl/vi.d.ts +117 -0
- package/dist/src/intl/vi.d.ts.map +1 -0
- package/dist/src/intl/vi.js +255 -0
- package/dist/src/intl/zh-CN.d.ts +117 -0
- package/dist/src/intl/zh-CN.d.ts.map +1 -0
- package/dist/src/intl/zh-CN.js +258 -0
- package/dist/src/intl/zh-TW.d.ts +117 -0
- package/dist/src/intl/zh-TW.d.ts.map +1 -0
- package/dist/src/intl/zh-TW.js +258 -0
- package/dist/src/local-first/Owner.d.ts +156 -62
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +119 -20
- package/package.json +1 -1
- package/src/Function.ts +2 -0
- package/src/Http.ts +9 -0
- package/src/Number.ts +85 -14
- package/src/Object.ts +2 -0
- package/src/RefCount.ts +2 -0
- package/src/Relation.ts +4 -0
- package/src/Resource.ts +2 -0
- package/src/Result.ts +397 -560
- package/src/Schedule.ts +1 -1
- package/src/StackTrace.ts +2 -0
- package/src/Task.ts +1145 -1225
- package/src/Time.ts +110 -62
- package/src/Type.ts +2842 -835
- package/src/Types.ts +0 -49
- package/src/intl/_en.ts +497 -0
- package/src/intl/ar.ts +417 -0
- package/src/intl/bn.ts +486 -0
- package/src/intl/ca.ts +488 -0
- package/src/intl/cs.ts +131 -32
- package/src/intl/da.ts +488 -0
- package/src/intl/de.ts +488 -0
- package/src/intl/el.ts +494 -0
- package/src/intl/es.ts +488 -0
- package/src/intl/fa.ts +487 -0
- package/src/intl/fi.ts +487 -0
- package/src/intl/fil.ts +488 -0
- package/src/intl/fr.ts +488 -0
- package/src/intl/he.ts +486 -0
- package/src/intl/hi.ts +487 -0
- package/src/intl/hr.ts +494 -0
- package/src/intl/hu.ts +387 -0
- package/src/intl/id.ts +487 -0
- package/src/intl/index.ts +42 -0
- package/src/intl/it.ts +488 -0
- package/src/intl/ja.ts +488 -0
- package/src/intl/ko.ts +487 -0
- package/src/intl/ml.ts +487 -0
- package/src/intl/mr.ts +487 -0
- package/src/intl/ms.ts +410 -0
- package/src/intl/nb.ts +364 -0
- package/src/intl/nl.ts +488 -0
- package/src/intl/pa.ts +487 -0
- package/src/intl/pl.ts +450 -0
- package/src/intl/pt-BR.ts +487 -0
- package/src/intl/pt.ts +424 -0
- package/src/intl/ro.ts +488 -0
- package/src/intl/sk.ts +412 -0
- package/src/intl/sl.ts +487 -0
- package/src/intl/sv.ts +488 -0
- package/src/intl/sw.ts +324 -0
- package/src/intl/ta.ts +487 -0
- package/src/intl/te.ts +487 -0
- package/src/intl/th.ts +484 -0
- package/src/intl/tr.ts +487 -0
- package/src/intl/uk.ts +488 -0
- package/src/intl/ur.ts +410 -0
- package/src/intl/vi.ts +435 -0
- package/src/intl/zh-CN.ts +482 -0
- package/src/intl/zh-TW.ts +482 -0
- package/src/local-first/Owner.ts +156 -62
package/src/Time.ts
CHANGED
|
@@ -10,12 +10,6 @@ import type { yieldNow } from "./Task.ts";
|
|
|
10
10
|
import {
|
|
11
11
|
brand,
|
|
12
12
|
type DateIso,
|
|
13
|
-
lessThan,
|
|
14
|
-
type NonNaNNumber,
|
|
15
|
-
NonNegativeInt,
|
|
16
|
-
positive,
|
|
17
|
-
} from "./Type.ts";
|
|
18
|
-
import type {
|
|
19
13
|
Digit,
|
|
20
14
|
Digit1To23,
|
|
21
15
|
Digit1To51,
|
|
@@ -23,7 +17,13 @@ import type {
|
|
|
23
17
|
Digit1To6,
|
|
24
18
|
Digit1To9,
|
|
25
19
|
Digit1To99,
|
|
26
|
-
|
|
20
|
+
lessThan,
|
|
21
|
+
type NonNaNNumber,
|
|
22
|
+
NonNegativeInt,
|
|
23
|
+
positive,
|
|
24
|
+
templateLiteral,
|
|
25
|
+
union,
|
|
26
|
+
} from "./Type.ts";
|
|
27
27
|
|
|
28
28
|
/** Time and timer operations. */
|
|
29
29
|
export interface Time {
|
|
@@ -376,104 +376,150 @@ export const performanceDurationBetween = (
|
|
|
376
376
|
};
|
|
377
377
|
|
|
378
378
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
379
|
+
* {@link DurationLiteral} or {@link Millis}.
|
|
380
|
+
*
|
|
381
|
+
* Convenience input accepting a human-readable {@link DurationLiteral} or
|
|
382
|
+
* validated milliseconds as {@link Millis}. APIs normalize it to `Millis`.
|
|
383
|
+
*
|
|
384
|
+
* ### Example
|
|
385
|
+
*
|
|
386
|
+
* ```ts
|
|
387
|
+
* import { Millis, spaced } from "@evolu/common";
|
|
388
|
+
*
|
|
389
|
+
* const readableSchedule = spaced("1s");
|
|
390
|
+
* const validatedSchedule = spaced(Millis.orThrow(1000));
|
|
391
|
+
*
|
|
392
|
+
* expectTypeOf(readableSchedule).toEqualTypeOf(validatedSchedule);
|
|
393
|
+
* ```
|
|
381
394
|
*/
|
|
382
395
|
export type Duration = DurationLiteral | Millis;
|
|
383
396
|
|
|
384
|
-
/** Positive duration accepted by timer-based APIs. */
|
|
385
|
-
export type PositiveDuration = DurationLiteral | PositiveMillis;
|
|
386
|
-
|
|
387
397
|
/**
|
|
388
|
-
*
|
|
398
|
+
* {@link DurationLiteral} or {@link PositiveMillis}.
|
|
389
399
|
*
|
|
390
|
-
*
|
|
391
|
-
*
|
|
392
|
-
* - Milliseconds: `1ms`, `500ms`, `999ms` (1-999)
|
|
393
|
-
* - Seconds: `1s`, `59s`, `12.5s` (1-59, 1.1-59.9)
|
|
394
|
-
* - Minutes: `1m`, `59m`, `12.5m` (1-59, 1.1-59.9)
|
|
395
|
-
* - Hours: `1h`, `23h`, `12.5h` (1-23, 1.1-23.9)
|
|
396
|
-
* - Days: `1d`, `6d`, `1.5d` (1-6, 1.1-6.9)
|
|
397
|
-
* - Weeks: `1w`, `51w`, `1.5w` (1-51, 1.1-51.9)
|
|
398
|
-
* - Months: not supported (variable length)
|
|
399
|
-
* - Years: `1y`, `99y`, `1.5y` (1-99, 1.1-99.9)
|
|
400
|
+
* Convenience input accepting a human-readable {@link DurationLiteral} or
|
|
401
|
+
* validated milliseconds as {@link PositiveMillis} for timer-based APIs.
|
|
400
402
|
*
|
|
401
|
-
*
|
|
402
|
-
* equivalent representations (e.g., 1000ms must be written as `"1s"`, not
|
|
403
|
-
* `"1000ms"`).
|
|
403
|
+
* ### Example
|
|
404
404
|
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
* use {@link Millis} directly.
|
|
405
|
+
* ```ts
|
|
406
|
+
* import { PositiveMillis, sleep } from "@evolu/common";
|
|
408
407
|
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
408
|
+
* const readableSleep = sleep("1s");
|
|
409
|
+
* const validatedSleep = sleep(PositiveMillis.orThrow(1000));
|
|
411
410
|
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
411
|
+
* expectTypeOf(readableSleep).toEqualTypeOf(validatedSleep);
|
|
412
|
+
* ```
|
|
414
413
|
*/
|
|
415
|
-
export type DurationLiteral
|
|
416
|
-
| DurationLiteralMilliseconds
|
|
417
|
-
| DurationLiteralSeconds
|
|
418
|
-
| DurationLiteralMinutes
|
|
419
|
-
| DurationLiteralHours
|
|
420
|
-
| DurationLiteralDays
|
|
421
|
-
| DurationLiteralWeeks
|
|
422
|
-
| DurationLiteralYears;
|
|
414
|
+
export type PositiveDuration = DurationLiteral | PositiveMillis;
|
|
423
415
|
|
|
424
416
|
/** Milliseconds duration: `"1ms"` to `"999ms"`. See {@link DurationLiteral}. */
|
|
417
|
+
export const DurationLiteralMilliseconds = /*#__PURE__*/ union(
|
|
418
|
+
/*#__PURE__*/ templateLiteral(Digit1To9, "ms"),
|
|
419
|
+
/*#__PURE__*/ templateLiteral(Digit1To9, Digit, "ms"),
|
|
420
|
+
/*#__PURE__*/ templateLiteral(Digit1To9, Digit, Digit, "ms"),
|
|
421
|
+
);
|
|
425
422
|
export type DurationLiteralMilliseconds =
|
|
426
|
-
|
|
427
|
-
| `${Digit1To9}${Digit}ms` // 10-99
|
|
428
|
-
| `${Digit1To9}${Digit}${Digit}ms`; // 100-999
|
|
423
|
+
typeof DurationLiteralMilliseconds.Output;
|
|
429
424
|
|
|
430
425
|
/**
|
|
431
426
|
* Seconds duration: `"1s"` to `"59s"` or `"1.1s"` to `"59.9s"`. See
|
|
432
427
|
* {@link DurationLiteral}.
|
|
433
428
|
*/
|
|
434
|
-
export
|
|
435
|
-
|
|
436
|
-
|
|
429
|
+
export const DurationLiteralSeconds = /*#__PURE__*/ union(
|
|
430
|
+
/*#__PURE__*/ templateLiteral(Digit1To59, "s"),
|
|
431
|
+
/*#__PURE__*/ templateLiteral(Digit1To59, ".", Digit1To9, "s"),
|
|
432
|
+
);
|
|
433
|
+
export type DurationLiteralSeconds = typeof DurationLiteralSeconds.Output;
|
|
437
434
|
|
|
438
435
|
/**
|
|
439
436
|
* Minutes duration: `"1m"` to `"59m"` or `"1.1m"` to `"59.9m"`. See
|
|
440
437
|
* {@link DurationLiteral}.
|
|
441
438
|
*/
|
|
442
|
-
export
|
|
443
|
-
|
|
444
|
-
|
|
439
|
+
export const DurationLiteralMinutes = /*#__PURE__*/ union(
|
|
440
|
+
/*#__PURE__*/ templateLiteral(Digit1To59, "m"),
|
|
441
|
+
/*#__PURE__*/ templateLiteral(Digit1To59, ".", Digit1To9, "m"),
|
|
442
|
+
);
|
|
443
|
+
export type DurationLiteralMinutes = typeof DurationLiteralMinutes.Output;
|
|
445
444
|
|
|
446
445
|
/**
|
|
447
446
|
* Hours duration: `"1h"` to `"23h"` or `"1.1h"` to `"23.9h"`. See
|
|
448
447
|
* {@link DurationLiteral}.
|
|
449
448
|
*/
|
|
450
|
-
export
|
|
451
|
-
|
|
452
|
-
|
|
449
|
+
export const DurationLiteralHours = /*#__PURE__*/ union(
|
|
450
|
+
/*#__PURE__*/ templateLiteral(Digit1To23, "h"),
|
|
451
|
+
/*#__PURE__*/ templateLiteral(Digit1To23, ".", Digit1To9, "h"),
|
|
452
|
+
);
|
|
453
|
+
export type DurationLiteralHours = typeof DurationLiteralHours.Output;
|
|
453
454
|
|
|
454
455
|
/**
|
|
455
456
|
* Days duration: `"1d"` to `"6d"` or `"1.1d"` to `"6.9d"`. See
|
|
456
457
|
* {@link DurationLiteral}.
|
|
457
458
|
*/
|
|
458
|
-
export
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
export const DurationLiteralDays = /*#__PURE__*/ union(
|
|
460
|
+
/*#__PURE__*/ templateLiteral(Digit1To6, "d"),
|
|
461
|
+
/*#__PURE__*/ templateLiteral(Digit1To6, ".", Digit1To9, "d"),
|
|
462
|
+
);
|
|
463
|
+
export type DurationLiteralDays = typeof DurationLiteralDays.Output;
|
|
461
464
|
|
|
462
465
|
/**
|
|
463
466
|
* Weeks duration: `"1w"` to `"51w"` or `"1.1w"` to `"51.9w"`. See
|
|
464
467
|
* {@link DurationLiteral}.
|
|
465
468
|
*/
|
|
466
|
-
export
|
|
467
|
-
|
|
468
|
-
|
|
469
|
+
export const DurationLiteralWeeks = /*#__PURE__*/ union(
|
|
470
|
+
/*#__PURE__*/ templateLiteral(Digit1To51, "w"),
|
|
471
|
+
/*#__PURE__*/ templateLiteral(Digit1To51, ".", Digit1To9, "w"),
|
|
472
|
+
);
|
|
473
|
+
export type DurationLiteralWeeks = typeof DurationLiteralWeeks.Output;
|
|
469
474
|
|
|
470
475
|
/**
|
|
471
476
|
* Years duration: `"1y"` to `"99y"` or `"1.1y"` to `"99.9y"`. See
|
|
472
477
|
* {@link DurationLiteral}.
|
|
473
478
|
*/
|
|
474
|
-
export
|
|
475
|
-
|
|
476
|
-
|
|
479
|
+
export const DurationLiteralYears = /*#__PURE__*/ union(
|
|
480
|
+
/*#__PURE__*/ templateLiteral(Digit1To99, "y"),
|
|
481
|
+
/*#__PURE__*/ templateLiteral(Digit1To99, ".", Digit1To9, "y"),
|
|
482
|
+
);
|
|
483
|
+
export type DurationLiteralYears = typeof DurationLiteralYears.Output;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Duration literal Type with compile-time and runtime validation.
|
|
487
|
+
*
|
|
488
|
+
* Supported formats:
|
|
489
|
+
*
|
|
490
|
+
* - Milliseconds: `1ms`, `500ms`, `999ms` (1-999)
|
|
491
|
+
* - Seconds: `1s`, `59s`, `12.5s` (1-59, 1.1-59.9)
|
|
492
|
+
* - Minutes: `1m`, `59m`, `12.5m` (1-59, 1.1-59.9)
|
|
493
|
+
* - Hours: `1h`, `23h`, `12.5h` (1-23, 1.1-23.9)
|
|
494
|
+
* - Days: `1d`, `6d`, `1.5d` (1-6, 1.1-6.9)
|
|
495
|
+
* - Weeks: `1w`, `51w`, `1.5w` (1-51, 1.1-51.9)
|
|
496
|
+
* - Months: not supported (variable length)
|
|
497
|
+
* - Years: `1y`, `99y`, `1.5y` (1-99, 1.1-99.9)
|
|
498
|
+
*
|
|
499
|
+
* Each unit uses a bounded range. Where units convert exactly, this avoids
|
|
500
|
+
* equivalent representations (e.g., 1000ms must be written as `"1s"`, not
|
|
501
|
+
* `"1000ms"`).
|
|
502
|
+
*
|
|
503
|
+
* Decimal values cover cases like 1.5s (1500ms) or 1.5h (90 minutes) without
|
|
504
|
+
* allowing redundant forms. For precise values that don't fit (e.g., 1050ms),
|
|
505
|
+
* use {@link Millis} directly.
|
|
506
|
+
*
|
|
507
|
+
* Zero duration (0ms) is not supported. For yielding without delay, use `await
|
|
508
|
+
* Promise.resolve()` for microtasks or the {@link yieldNow} for macrotasks.
|
|
509
|
+
*
|
|
510
|
+
* See {@link Duration} for a type that also accepts {@link Millis}. Use
|
|
511
|
+
* {@link durationToMillis} to convert to milliseconds.
|
|
512
|
+
*/
|
|
513
|
+
export const DurationLiteral = /*#__PURE__*/ union(
|
|
514
|
+
DurationLiteralMilliseconds,
|
|
515
|
+
DurationLiteralSeconds,
|
|
516
|
+
DurationLiteralMinutes,
|
|
517
|
+
DurationLiteralHours,
|
|
518
|
+
DurationLiteralDays,
|
|
519
|
+
DurationLiteralWeeks,
|
|
520
|
+
DurationLiteralYears,
|
|
521
|
+
);
|
|
522
|
+
export type DurationLiteral = typeof DurationLiteral.Output;
|
|
477
523
|
|
|
478
524
|
/**
|
|
479
525
|
* Converts a duration to milliseconds.
|
|
@@ -496,6 +542,8 @@ export type DurationLiteralYears =
|
|
|
496
542
|
export function durationToMillis(
|
|
497
543
|
duration: DurationLiteral | PositiveMillis,
|
|
498
544
|
): PositiveMillis;
|
|
545
|
+
|
|
546
|
+
/** Converts a general {@link Duration}, including zero, to milliseconds. */
|
|
499
547
|
export function durationToMillis(duration: Duration): Millis;
|
|
500
548
|
export function durationToMillis(duration: Duration): Millis {
|
|
501
549
|
if (typeof duration === "number") return duration;
|