@ix-xs/node-comfort 2.0.0 → 2.1.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/CHANGELOG.md +150 -0
- package/README.md +32 -30
- package/index.js +3 -3
- package/package.json +8 -7
- package/src/Arr.js +222 -58
- package/src/Async.js +322 -90
- package/src/Cache.js +148 -44
- package/src/Checker.js +257 -26
- package/src/Cli.js +404 -145
- package/src/Color.js +224 -83
- package/src/Crypto.js +481 -106
- package/src/Emitter.js +104 -37
- package/src/Env.js +176 -42
- package/src/FS.js +203 -60
- package/src/Func.js +226 -76
- package/src/Http.js +311 -149
- package/src/Id.js +281 -96
- package/src/Logger.js +302 -78
- package/src/Num.js +182 -60
- package/src/Obj.js +340 -125
- package/src/SQLite.js +426 -105
- package/src/Schema.js +602 -87
- package/src/Str.js +316 -86
- package/src/Sys.js +197 -54
- package/src/Time.js +572 -317
- package/src/Utils.js +62 -41
- package/src/errors.js +54 -11
- package/src/internal/shared.js +415 -0
- package/types/index.d.ts +59 -17
- package/types/src/Arr.d.ts +78 -0
- package/types/src/Arr.d.ts.map +1 -1
- package/types/src/Async.d.ts +52 -1
- package/types/src/Async.d.ts.map +1 -1
- package/types/src/Cache.d.ts +33 -7
- package/types/src/Cache.d.ts.map +1 -1
- package/types/src/Checker.d.ts +155 -2
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/Cli.d.ts +97 -15
- package/types/src/Cli.d.ts.map +1 -1
- package/types/src/Color.d.ts +7 -1
- package/types/src/Color.d.ts.map +1 -1
- package/types/src/Crypto.d.ts +99 -13
- package/types/src/Crypto.d.ts.map +1 -1
- package/types/src/Emitter.d.ts +36 -17
- package/types/src/Emitter.d.ts.map +1 -1
- package/types/src/Env.d.ts +31 -1
- package/types/src/Env.d.ts.map +1 -1
- package/types/src/FS.d.ts +36 -5
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Func.d.ts +147 -19
- package/types/src/Func.d.ts.map +1 -1
- package/types/src/Http.d.ts +113 -43
- package/types/src/Http.d.ts.map +1 -1
- package/types/src/Id.d.ts +60 -8
- package/types/src/Id.d.ts.map +1 -1
- package/types/src/Logger.d.ts +53 -2
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts +48 -7
- package/types/src/Num.d.ts.map +1 -1
- package/types/src/Obj.d.ts +67 -4
- package/types/src/Obj.d.ts.map +1 -1
- package/types/src/SQLite.d.ts +123 -14
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Schema.d.ts +256 -7
- package/types/src/Schema.d.ts.map +1 -1
- package/types/src/Str.d.ts +49 -1
- package/types/src/Str.d.ts.map +1 -1
- package/types/src/Sys.d.ts +51 -6
- package/types/src/Sys.d.ts.map +1 -1
- package/types/src/Time.d.ts +130 -34
- package/types/src/Time.d.ts.map +1 -1
- package/types/src/Utils.d.ts +15 -11
- package/types/src/Utils.d.ts.map +1 -1
- package/types/src/errors.d.ts +27 -3
- package/types/src/errors.d.ts.map +1 -1
- package/types/src/internal/shared.d.ts +123 -0
- package/types/src/internal/shared.d.ts.map +1 -0
package/types/src/Time.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export type RelativeOptions = {
|
|
|
51
51
|
/**
|
|
52
52
|
* `"auto"` says `"yesterday"` instead of `"1 day ago"`. Defaults to `"always"`.
|
|
53
53
|
*/
|
|
54
|
-
numeric?: "
|
|
54
|
+
numeric?: "auto" | "always" | undefined;
|
|
55
55
|
/**
|
|
56
56
|
* `"short"` gives `"in 3 mo."`. Defaults to `"long"`.
|
|
57
57
|
*/
|
|
@@ -94,7 +94,37 @@ export type WeekOptions = {
|
|
|
94
94
|
/**
|
|
95
95
|
* First day of the week: `0` for Sunday, `1` for Monday. Defaults to `1`.
|
|
96
96
|
*/
|
|
97
|
-
weekStartsOn?: 0 |
|
|
97
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Zone whose calendar is used. Defaults to the global zone, then the system's.
|
|
100
|
+
*/
|
|
101
|
+
timeZone?: string | undefined;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Options for `parse()`.
|
|
105
|
+
*/
|
|
106
|
+
export type ParseDateOptions = {
|
|
107
|
+
/**
|
|
108
|
+
* Language of month names in the text. Defaults to the global locale.
|
|
109
|
+
*/
|
|
110
|
+
locale?: string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Zone the text is written in, unless it carries its own offset. Defaults to the global zone, then the system's.
|
|
113
|
+
*/
|
|
114
|
+
timeZone?: string | undefined;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Options for `range()`.
|
|
118
|
+
*/
|
|
119
|
+
export type DateRangeOptions = {
|
|
120
|
+
/**
|
|
121
|
+
* How many units between two dates. Defaults to `1`.
|
|
122
|
+
*/
|
|
123
|
+
step?: number | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Zone whose calendar is used for days, weeks, months and years.
|
|
126
|
+
*/
|
|
127
|
+
timeZone?: string | undefined;
|
|
98
128
|
};
|
|
99
129
|
/**
|
|
100
130
|
* Time zone setting.
|
|
@@ -142,6 +172,10 @@ export type CronOptions = {
|
|
|
142
172
|
* Start a run even if the previous one hasn't finished. By default it's skipped.
|
|
143
173
|
*/
|
|
144
174
|
overlap?: boolean | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* `cron()` only: also run once right away.
|
|
177
|
+
*/
|
|
178
|
+
immediate?: boolean | undefined;
|
|
145
179
|
/**
|
|
146
180
|
* Called when the task fails.
|
|
147
181
|
*/
|
|
@@ -197,19 +231,6 @@ export type Stopwatch = {
|
|
|
197
231
|
*/
|
|
198
232
|
reset: () => void;
|
|
199
233
|
};
|
|
200
|
-
/**
|
|
201
|
-
* Parsed cron fields.
|
|
202
|
-
*/
|
|
203
|
-
export type CronSpec = {
|
|
204
|
-
seconds: Set<number>;
|
|
205
|
-
minutes: Set<number>;
|
|
206
|
-
hours: Set<number>;
|
|
207
|
-
days: Set<number>;
|
|
208
|
-
months: Set<number>;
|
|
209
|
-
weekdays: Set<number>;
|
|
210
|
-
anyDay: boolean;
|
|
211
|
-
anyWeekday: boolean;
|
|
212
|
-
};
|
|
213
234
|
/**
|
|
214
235
|
* Sets the default language for `relative`, `calendar`, `formatDuration`
|
|
215
236
|
* and `format`.
|
|
@@ -291,12 +312,13 @@ export function parseDuration(input: string | number): number | null;
|
|
|
291
312
|
* time.formatDuration(90_000, { long: true, locale: "fr" }); // "1 minute 30 secondes"
|
|
292
313
|
* time.formatDuration(93_784_000, { units: 2 }); // "1d 2h"
|
|
293
314
|
* time.formatDuration(5_405_000, { clock: true }); // "01:30:05"
|
|
315
|
+
* time.formatDuration("90m"); // "1h 30m"
|
|
294
316
|
*
|
|
295
|
-
* @param {number}
|
|
317
|
+
* @param {number | string} duration Milliseconds, or text like `"90m"`.
|
|
296
318
|
* @param {FormatDurationOptions} [options]
|
|
297
319
|
* @returns {string}
|
|
298
320
|
*/
|
|
299
|
-
export function formatDuration(
|
|
321
|
+
export function formatDuration(duration: number | string, options?: FormatDurationOptions): string;
|
|
300
322
|
/**
|
|
301
323
|
* Describes a date relative to now: `"3 hours ago"`, `"in 2 days"`, in
|
|
302
324
|
* any language.
|
|
@@ -339,6 +361,7 @@ export function calendar(date: DateInput, options?: CalendarOptions): string;
|
|
|
339
361
|
* | `dddd` / `ddd` | Monday / Mon | | `A` / `a` | PM / pm |
|
|
340
362
|
* | `d` | weekday, 0 is Sunday | | `Z` / `ZZ` | +02:00 / +0200 |
|
|
341
363
|
* | `W` / `WW` | ISO week | | `X` / `x` | Unix seconds / ms |
|
|
364
|
+
* | `Do` | 5th | | `z` | zone name, like EST or GMT+1 |
|
|
342
365
|
*
|
|
343
366
|
* Text in brackets stays as is: `"[Today is] dddd"`.
|
|
344
367
|
*
|
|
@@ -353,6 +376,23 @@ export function calendar(date: DateInput, options?: CalendarOptions): string;
|
|
|
353
376
|
* @returns {string} Or `"Invalid Date"`.
|
|
354
377
|
*/
|
|
355
378
|
export function format(date: DateInput, pattern?: string, options?: FormatDateOptions): string;
|
|
379
|
+
/**
|
|
380
|
+
* Reads a date written in a known format: the opposite of `format()`, with
|
|
381
|
+
* the same tokens. Parts the pattern doesn't have default to today's date
|
|
382
|
+
* and to midnight.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* time.parse("15/01/2024 14:30", "DD/MM/YYYY HH:mm");
|
|
386
|
+
* time.parse("15 janvier 2024", "D MMMM YYYY", { locale: "fr" });
|
|
387
|
+
* time.parse("2024-01-15 09:00", "YYYY-MM-DD HH:mm", { timeZone: "Asia/Tokyo" });
|
|
388
|
+
* time.parse("31/02/2024", "DD/MM/YYYY"); // undefined, no such day
|
|
389
|
+
*
|
|
390
|
+
* @param {string} text
|
|
391
|
+
* @param {string} pattern Tokens like `YYYY`, `MM`, `DD`, `HH`, `mm`, `ss`, `A`, `Z`. Text in brackets must match as is.
|
|
392
|
+
* @param {ParseDateOptions} [options]
|
|
393
|
+
* @returns {Date | undefined} `undefined` when the text doesn't match or isn't a real date.
|
|
394
|
+
*/
|
|
395
|
+
export function parse(text: string, pattern: string, options?: ParseDateOptions): Date | undefined;
|
|
356
396
|
/**
|
|
357
397
|
* The date as `YYYY-MM-DD`, the format `<input type="date">` and most APIs
|
|
358
398
|
* expect.
|
|
@@ -366,20 +406,26 @@ export function format(date: DateInput, pattern?: string, options?: FormatDateOp
|
|
|
366
406
|
*/
|
|
367
407
|
export function toISODate(date?: DateInput, options?: TimeZoneOptions): string;
|
|
368
408
|
/**
|
|
369
|
-
* Adds time to a date and returns a new `Date`.
|
|
370
|
-
*
|
|
409
|
+
* Adds time to a date and returns a new `Date`. Whole days, weeks, months
|
|
410
|
+
* and years follow the calendar: one day later is the same time tomorrow,
|
|
411
|
+
* even when the clocks change in between, and January 31 plus one month is
|
|
412
|
+
* the end of February. Hours and smaller units are exact.
|
|
371
413
|
*
|
|
372
414
|
* @example
|
|
373
415
|
* time.add(new Date(), "2h30m");
|
|
374
416
|
* time.add(new Date(), 3, "days");
|
|
417
|
+
* time.add(new Date(), "1 month");
|
|
375
418
|
* time.add(new Date(2024, 0, 31), 1, "month"); // 2024-02-29
|
|
419
|
+
* time.add(date, "1 day", { timeZone: "Europe/Paris" });
|
|
376
420
|
*
|
|
377
421
|
* @param {DateInput} date
|
|
378
|
-
* @param {number | string} amount A number with `unit`, or a duration like `"1h30m"`.
|
|
379
|
-
* @param {CalendarUnit} [unit="ms"]
|
|
422
|
+
* @param {number | string} amount A number with `unit`, or a duration like `"1h30m"` or `"1 month"`.
|
|
423
|
+
* @param {CalendarUnit | TimeZoneOptions} [unit="ms"] The unit of a number. With a text amount there is none to give: the options can come here.
|
|
424
|
+
* @param {TimeZoneOptions} [options] The zone whose calendar is followed.
|
|
380
425
|
* @returns {Date}
|
|
426
|
+
* @throws {TypeError} If a text amount isn't a duration, or the unit isn't one.
|
|
381
427
|
*/
|
|
382
|
-
export function add(date: DateInput, amount: number | string, unit?: CalendarUnit): Date;
|
|
428
|
+
export function add(date: DateInput, amount: number | string, unit?: CalendarUnit | TimeZoneOptions, options?: TimeZoneOptions): Date;
|
|
383
429
|
/**
|
|
384
430
|
* Subtracts time from a date and returns a new `Date`.
|
|
385
431
|
*
|
|
@@ -389,10 +435,12 @@ export function add(date: DateInput, amount: number | string, unit?: CalendarUni
|
|
|
389
435
|
*
|
|
390
436
|
* @param {DateInput} date
|
|
391
437
|
* @param {number | string} amount
|
|
392
|
-
* @param {CalendarUnit} [unit="ms"]
|
|
438
|
+
* @param {CalendarUnit | TimeZoneOptions} [unit="ms"] The unit of a number, or the options when the amount is text.
|
|
439
|
+
* @param {TimeZoneOptions} [options]
|
|
393
440
|
* @returns {Date}
|
|
441
|
+
* @throws {TypeError} If a text amount isn't a duration, or the unit isn't one.
|
|
394
442
|
*/
|
|
395
|
-
export function subtract(date: DateInput, amount: number | string, unit?: CalendarUnit): Date;
|
|
443
|
+
export function subtract(date: DateInput, amount: number | string, unit?: CalendarUnit | TimeZoneOptions, options?: TimeZoneOptions): Date;
|
|
396
444
|
/**
|
|
397
445
|
* `a - b` in a unit. Fixed units can give fractions; months and years are
|
|
398
446
|
* whole calendar months and years.
|
|
@@ -404,16 +452,20 @@ export function subtract(date: DateInput, amount: number | string, unit?: Calend
|
|
|
404
452
|
* @param {DateInput} a
|
|
405
453
|
* @param {DateInput} b
|
|
406
454
|
* @param {CalendarUnit} [unit="ms"]
|
|
455
|
+
* @param {TimeZoneOptions} [options] The zone whose calendar months and years follow.
|
|
407
456
|
* @returns {number}
|
|
457
|
+
* @throws {TypeError} If the unit isn't one.
|
|
408
458
|
*/
|
|
409
|
-
export function diff(a: DateInput, b: DateInput, unit?: CalendarUnit): number;
|
|
459
|
+
export function diff(a: DateInput, b: DateInput, unit?: CalendarUnit, options?: TimeZoneOptions): number;
|
|
410
460
|
/**
|
|
411
|
-
* A new `Date` at the start of the day, week, month... in
|
|
461
|
+
* A new `Date` at the start of the day, week, month... in the global time
|
|
462
|
+
* zone, or the one you name.
|
|
412
463
|
*
|
|
413
464
|
* @example
|
|
414
|
-
* time.startOf(new Date(), "day");
|
|
415
|
-
* time.startOf(new Date(), "week");
|
|
416
|
-
* time.startOf(new Date(), "week", { weekStartsOn: 0 });
|
|
465
|
+
* time.startOf(new Date(), "day"); // today at 00:00
|
|
466
|
+
* time.startOf(new Date(), "week"); // Monday at 00:00
|
|
467
|
+
* time.startOf(new Date(), "week", { weekStartsOn: 0 }); // Sunday at 00:00
|
|
468
|
+
* time.startOf(new Date(), "day", { timeZone: "Asia/Tokyo" }); // midnight in Tokyo
|
|
417
469
|
*
|
|
418
470
|
* @param {DateInput} date
|
|
419
471
|
* @param {StartOfUnit} unit
|
|
@@ -461,6 +513,20 @@ export function isAfter(a: DateInput, b: DateInput): boolean;
|
|
|
461
513
|
* @returns {boolean}
|
|
462
514
|
*/
|
|
463
515
|
export function isBetween(date: DateInput, start: DateInput, end: DateInput): boolean;
|
|
516
|
+
/**
|
|
517
|
+
* Are both dates in the same year, month, week, day, hour...?
|
|
518
|
+
*
|
|
519
|
+
* @example
|
|
520
|
+
* time.isSame(a, b, "month");
|
|
521
|
+
* time.isSame(a, b, "day", { timeZone: "America/New_York" });
|
|
522
|
+
*
|
|
523
|
+
* @param {DateInput} a
|
|
524
|
+
* @param {DateInput} b
|
|
525
|
+
* @param {StartOfUnit} unit
|
|
526
|
+
* @param {WeekOptions} [options]
|
|
527
|
+
* @returns {boolean}
|
|
528
|
+
*/
|
|
529
|
+
export function isSame(a: DateInput, b: DateInput, unit: StartOfUnit, options?: WeekOptions): boolean;
|
|
464
530
|
/**
|
|
465
531
|
* Are both dates on the same calendar day?
|
|
466
532
|
*
|
|
@@ -544,9 +610,10 @@ export function daysInMonth(dateOrYear: DateInput | number, month?: number): num
|
|
|
544
610
|
* Day of the year, from 1 to 366.
|
|
545
611
|
*
|
|
546
612
|
* @param {DateInput} [date] Defaults to now.
|
|
613
|
+
* @param {TimeZoneOptions} [options]
|
|
547
614
|
* @returns {number}
|
|
548
615
|
*/
|
|
549
|
-
export function dayOfYear(date?: DateInput): number;
|
|
616
|
+
export function dayOfYear(date?: DateInput, options?: TimeZoneOptions): number;
|
|
550
617
|
/**
|
|
551
618
|
* ISO week number, from 1 to 53. Weeks start on Monday, and week 1 holds
|
|
552
619
|
* the year's first Thursday.
|
|
@@ -555,11 +622,12 @@ export function dayOfYear(date?: DateInput): number;
|
|
|
555
622
|
* time.weekOfYear(new Date(2021, 0, 3)); // 53, the last week of 2020
|
|
556
623
|
*
|
|
557
624
|
* @param {DateInput} [date] Defaults to now.
|
|
558
|
-
* @param {{ utc?: boolean }} [options]
|
|
625
|
+
* @param {{ utc?: boolean, timeZone?: string }} [options] `utc` reads the date in UTC, `timeZone` in another zone.
|
|
559
626
|
* @returns {number}
|
|
560
627
|
*/
|
|
561
628
|
export function weekOfYear(date?: DateInput, options?: {
|
|
562
629
|
utc?: boolean;
|
|
630
|
+
timeZone?: string;
|
|
563
631
|
}): number;
|
|
564
632
|
/**
|
|
565
633
|
* The earliest date.
|
|
@@ -581,6 +649,33 @@ export function max(dates: Iterable<DateInput>): Date | undefined;
|
|
|
581
649
|
* @returns {number}
|
|
582
650
|
*/
|
|
583
651
|
export function unix(): number;
|
|
652
|
+
/**
|
|
653
|
+
* A `Date` from a Unix timestamp in seconds, as found in JWTs and many APIs.
|
|
654
|
+
*
|
|
655
|
+
* @example
|
|
656
|
+
* time.fromUnix(1705329000); // 2024-01-15T14:30:00.000Z
|
|
657
|
+
*
|
|
658
|
+
* @param {number} seconds
|
|
659
|
+
* @returns {Date}
|
|
660
|
+
*/
|
|
661
|
+
export function fromUnix(seconds: number): Date;
|
|
662
|
+
/**
|
|
663
|
+
* Every date from `start` to `end`, both included, one unit apart. Handy
|
|
664
|
+
* for charts, calendars and reports.
|
|
665
|
+
*
|
|
666
|
+
* @example
|
|
667
|
+
* time.range("2024-01-01", "2024-01-07", "day"); // 7 dates
|
|
668
|
+
* time.range(start, end, "month"); // the same day each month
|
|
669
|
+
* time.range(start, end, "minute", { step: 15 }); // every quarter of an hour
|
|
670
|
+
*
|
|
671
|
+
* @param {DateInput} start
|
|
672
|
+
* @param {DateInput} end
|
|
673
|
+
* @param {CalendarUnit} [unit="day"]
|
|
674
|
+
* @param {DateRangeOptions} [options]
|
|
675
|
+
* @returns {Date[]}
|
|
676
|
+
* @throws {RangeError} If the step isn't positive, or the range would hold more than a million dates.
|
|
677
|
+
*/
|
|
678
|
+
export function range(start: DateInput, end: DateInput, unit?: CalendarUnit, options?: DateRangeOptions): Date[];
|
|
584
679
|
/**
|
|
585
680
|
* Starts a precise stopwatch.
|
|
586
681
|
*
|
|
@@ -630,9 +725,10 @@ export function every(interval: number | string, task: () => unknown, options?:
|
|
|
630
725
|
*
|
|
631
726
|
* Expressions have 5 fields (`minute hour day month weekday`), or 6 with
|
|
632
727
|
* seconds first. You can use `*`, lists (`1,15`), ranges (`1-5`), steps
|
|
633
|
-
* (`*\/15`), names (`jan`, `mon-fri`)
|
|
634
|
-
* `@monthly`, `@yearly`. As in classic
|
|
635
|
-
* weekday are set, either one matching is
|
|
728
|
+
* (`*\/15`), names (`jan`, `mon-fri`), `L` for the last day of the month,
|
|
729
|
+
* and `@daily`, `@hourly`, `@weekly`, `@monthly`, `@yearly`. As in classic
|
|
730
|
+
* cron, when both the day and the weekday are set, either one matching is
|
|
731
|
+
* enough.
|
|
636
732
|
*
|
|
637
733
|
* @example
|
|
638
734
|
* time.nextRun("0 9 * * mon-fri"); // next weekday at 09:00
|
package/types/src/Time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Time.d.ts","sourceRoot":"","sources":["../../src/Time.js"],"names":[],"mappings":";;;;wBAqBa,IAAI,GAAG,MAAM,GAAG,MAAM;;;;2BAKtB,IAAI,GAAG,aAAa,GAAG,cAAc,GAAG,GAAG,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,GAAG,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO,GAAG,GAAG,GAAG,KAAK,GAAG,MAAM,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO;;;;2BAKxL,YAAY,GAAG,GAAG,GAAG,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO;;;;0BAKhE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ
|
|
1
|
+
{"version":3,"file":"Time.d.ts","sourceRoot":"","sources":["../../src/Time.js"],"names":[],"mappings":";;;;wBAqBa,IAAI,GAAG,MAAM,GAAG,MAAM;;;;2BAKtB,IAAI,GAAG,aAAa,GAAG,cAAc,GAAG,GAAG,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,GAAG,GAAG,KAAK,GAAG,QAAQ,GAAG,SAAS,GAAG,GAAG,GAAG,MAAM,GAAG,OAA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;;;;GAQG;AACH,kCAHW,MAAM,GACJ,IAAI,CAIhB;AAED;;;;;;;;;;;;;;;GAeG;AACH,6BAPW,SAAS,OACT,SAAS,SACT,YAAY,YACZ,gBAAgB,GACd,IAAI,EAAE,CAkBlB;AAED;;;;;;;;;;GAUG;AACH,6BAFa,SAAS,CA2BrB;AAED;;;;;;;;;;GAUG;AACH,wBAJa,CAAC,MACH,MAAM,CAAC,GACL,OAAO,CAAC;IAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAM7D;AAED;;;;;;;;;;;;;;;GAeG;AACH,gCANW,MAAM,GAAG,MAAM,QACf,MAAM,OAAO,YACb,YAAY,GACV,aAAa,CAoCzB;AAqDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,oCALW,MAAM,YACN,WAAW,GACT,IAAI,GAAG,SAAS,CAK5B;AAED;;;;;;;;;;;;;;;GAeG;AACH,iCANW,MAAM,QACN,MAAM,OAAO,YACb,WAAW,GACT,aAAa,CAgDzB"}
|
package/types/src/Utils.d.ts
CHANGED
|
@@ -16,13 +16,13 @@ export type WaitOptions = {
|
|
|
16
16
|
*/
|
|
17
17
|
export type WhenOptions = {
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Time between two checks, in ms or like `"1s"`. Defaults to `50`.
|
|
20
20
|
*/
|
|
21
|
-
interval?: number | undefined;
|
|
21
|
+
interval?: string | number | undefined;
|
|
22
22
|
/**
|
|
23
|
-
* Give up after this
|
|
23
|
+
* Give up after this long, in ms or like `"10s"`, and emit `"timeout"`.
|
|
24
24
|
*/
|
|
25
|
-
timeout?: number | null | undefined;
|
|
25
|
+
timeout?: string | number | null | undefined;
|
|
26
26
|
/**
|
|
27
27
|
* Stop after this many triggers.
|
|
28
28
|
*/
|
|
@@ -71,8 +71,8 @@ export type DontCrashController = {
|
|
|
71
71
|
/**
|
|
72
72
|
* Options for `when()`.
|
|
73
73
|
* @typedef {object} WhenOptions
|
|
74
|
-
* @property {number} [interval]
|
|
75
|
-
* @property {number | null} [timeout] Give up after this
|
|
74
|
+
* @property {number | string} [interval] Time between two checks, in ms or like `"1s"`. Defaults to `50`.
|
|
75
|
+
* @property {number | string | null} [timeout] Give up after this long, in ms or like `"10s"`, and emit `"timeout"`.
|
|
76
76
|
* @property {number | null} [max] Stop after this many triggers.
|
|
77
77
|
*/
|
|
78
78
|
/**
|
|
@@ -113,7 +113,7 @@ export function wait(duration: number | string, options?: WaitOptions): Promise<
|
|
|
113
113
|
* await a condition, `nc.async.poll()` is simpler.
|
|
114
114
|
*
|
|
115
115
|
* @example
|
|
116
|
-
* nc.when(() => queue.length > 0, { reason: "jobs waiting" }, { interval: 500, max: 1, timeout:
|
|
116
|
+
* nc.when(() => queue.length > 0, { reason: "jobs waiting" }, { interval: 500, max: 1, timeout: "10s" })
|
|
117
117
|
* .on("trigger", (payload) => nc.info(payload.reason))
|
|
118
118
|
* .on("timeout", () => nc.warn("Nothing happened in 10s"))
|
|
119
119
|
* .start();
|
|
@@ -145,12 +145,13 @@ export function when(predicate: boolean | PromiseLike<boolean> | (() => unknown)
|
|
|
145
145
|
export function dontCrash(): DontCrashController;
|
|
146
146
|
/**
|
|
147
147
|
* `JSON.stringify` that never throws. Circular references become
|
|
148
|
-
* `"[Circular]"`, bigints become strings, Maps become objects
|
|
149
|
-
* arrays.
|
|
148
|
+
* `"[Circular]"`, bigints become strings, Maps become objects, Sets become
|
|
149
|
+
* arrays, and errors keep their name, message and stack.
|
|
150
150
|
*
|
|
151
151
|
* @example
|
|
152
152
|
* nc.JSONString({ a: 1 }); // '{\n "a": 1\n}'
|
|
153
153
|
* nc.JSONString({ id: 10n, tags: new Set(["x"]) }, 0); // '{"id":"10","tags":["x"]}'
|
|
154
|
+
* nc.JSONString({ error: new Error("boom") }, 0); // '{"error":{"name":"Error","message":"boom","stack":"..."}}'
|
|
154
155
|
*
|
|
155
156
|
* @param {unknown} value
|
|
156
157
|
* @param {number} [spaces=4] Indentation. Use `0` for a single line.
|
|
@@ -159,18 +160,21 @@ export function dontCrash(): DontCrashController;
|
|
|
159
160
|
export function JSONString(value: unknown, spaces?: number): string;
|
|
160
161
|
/**
|
|
161
162
|
* `JSON.parse` with an optional fallback. With a fallback, invalid input
|
|
162
|
-
* returns it instead of throwing.
|
|
163
|
+
* returns it instead of throwing. A leading byte order mark, which Windows
|
|
164
|
+
* editors like to add, is ignored.
|
|
163
165
|
*
|
|
164
166
|
* @example
|
|
165
167
|
* nc.JSONParse('{"a":1}'); // { a: 1 }
|
|
166
168
|
* nc.JSONParse("oops", null); // null
|
|
167
169
|
* nc.JSONParse("oops"); // throws SyntaxError
|
|
170
|
+
* nc.JSONParse(text, {}, (key, value) => (key === "at" ? new Date(value) : value));
|
|
168
171
|
*
|
|
169
172
|
* @template [T=any]
|
|
170
173
|
* @param {string} text
|
|
171
174
|
* @param {T} [fallback] Returned when `text` isn't valid JSON.
|
|
175
|
+
* @param {(this: any, key: string, value: any) => any} [reviver] Passed to `JSON.parse`.
|
|
172
176
|
* @returns {T}
|
|
173
177
|
* @throws {SyntaxError} If `text` is invalid and there's no fallback.
|
|
174
178
|
*/
|
|
175
|
-
export function JSONParse<T = any>(text: string, fallback?: T, ...args: any[]): T;
|
|
179
|
+
export function JSONParse<T = any>(text: string, fallback?: T, reviver?: (this: any, key: string, value: any) => any, ...args: any[]): T;
|
|
176
180
|
//# sourceMappingURL=Utils.d.ts.map
|
package/types/src/Utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/Utils.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAgCc,MAAM,QAAQ;;;;UACd,MAAM,QAAQ;;;;QACd,CAAC,CAAC,SAAS,SAAS,GAAG,OAAO,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,SAAS,O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G,CAAC,SAAS,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,KAAK,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,mBAAmB;;;;aACjM,MAAM,IAAI;;AAhCxB;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;GAGG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AACH,+BANW,MAAM,GAAG,MAAM,YACf,WAAW,GACT,OAAO,CAAC,IAAI,CAAC,CAazB;AAED;;;;;;;;;;;;;;;GAeG;AACH,gCALW,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,YAChD,GAAG,YACH,WAAW,GACT,QAAQ,CAuEpB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,6BAFa,mBAAmB,CAoE/B;AAKD;;;;;;;;;;;;;GAaG;AACH,kCAJW,OAAO,WACP,MAAM,GACJ,MAAM,CA6BlB;AAgBD;;;;;;;;;;;;;;;;;GAiBG;AACH,0BAPc,CAAC,cACJ,MAAM,aACN,CAAC,YACD,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,mBACzC,CAAC,CAWb"}
|
package/types/src/errors.d.ts
CHANGED
|
@@ -37,9 +37,13 @@ export type ValidationIssue = {
|
|
|
37
37
|
received?: string | undefined;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
-
* The errors node-comfort throws
|
|
41
|
-
*
|
|
42
|
-
*
|
|
40
|
+
* The errors node-comfort throws when something goes wrong at run time: a
|
|
41
|
+
* request fails, data is invalid, a command exits badly. They all extend
|
|
42
|
+
* `NodeComfortError` (itself a regular `Error`) and carry a stable `code`,
|
|
43
|
+
* so you can branch on the kind of failure without parsing messages.
|
|
44
|
+
*
|
|
45
|
+
* A mistake in your own code, like a wrong argument, still throws a plain
|
|
46
|
+
* `TypeError` or `RangeError`, as it does everywhere in JavaScript.
|
|
43
47
|
*
|
|
44
48
|
* @example
|
|
45
49
|
* try {
|
|
@@ -63,6 +67,15 @@ export type ValidationIssue = {
|
|
|
63
67
|
* if (error instanceof nc.errors.NodeComfortError) logger.warn(error.code);
|
|
64
68
|
*/
|
|
65
69
|
export class NodeComfortError extends Error {
|
|
70
|
+
/**
|
|
71
|
+
* Makes `instanceof` work when two copies of the package are installed,
|
|
72
|
+
* which would otherwise give two unrelated `HttpError` classes.
|
|
73
|
+
*
|
|
74
|
+
* @override
|
|
75
|
+
* @param {unknown} value
|
|
76
|
+
* @returns {boolean}
|
|
77
|
+
*/
|
|
78
|
+
static override [Symbol.hasInstance](value: unknown): boolean;
|
|
66
79
|
/**
|
|
67
80
|
* @param {string} message
|
|
68
81
|
* @param {NodeComfortErrorOptions} [options]
|
|
@@ -70,6 +83,17 @@ export class NodeComfortError extends Error {
|
|
|
70
83
|
constructor(message: string, options?: NodeComfortErrorOptions);
|
|
71
84
|
/** Stable, machine-readable code. */
|
|
72
85
|
code: string;
|
|
86
|
+
/**
|
|
87
|
+
* What `JSON.stringify()` writes for the error: its name, code, message
|
|
88
|
+
* and own fields, without the stack. Handy for API responses and logs.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* res.status(400).json({ error });
|
|
92
|
+
* // {"error":{"name":"ValidationError","code":"ERR_VALIDATION","message":"...","issues":[...]}}
|
|
93
|
+
*
|
|
94
|
+
* @returns {Record<string, unknown>}
|
|
95
|
+
*/
|
|
96
|
+
toJSON(): Record<string, unknown>;
|
|
73
97
|
}
|
|
74
98
|
/**
|
|
75
99
|
* Thrown by `nc.assert()` and `nc.assertType()`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.js"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.js"],"names":[],"mappings":";;;;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C1E,+BAAoC;CAEvC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parsed cron fields. `lastDay` is set by `L` in the day-of-month field.
|
|
3
|
+
*/
|
|
4
|
+
export type CronSpec = {
|
|
5
|
+
seconds: Set<number>;
|
|
6
|
+
minutes: Set<number>;
|
|
7
|
+
hours: Set<number>;
|
|
8
|
+
days: Set<number>;
|
|
9
|
+
months: Set<number>;
|
|
10
|
+
weekdays: Set<number>;
|
|
11
|
+
anyDay: boolean;
|
|
12
|
+
anyWeekday: boolean;
|
|
13
|
+
lastDay: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** Keys that must never be copied onto an object: they reach its prototype. */
|
|
16
|
+
export const UNSAFE_KEYS: Set<string>;
|
|
17
|
+
export namespace MS {
|
|
18
|
+
let ms: number;
|
|
19
|
+
let s: number;
|
|
20
|
+
let m: number;
|
|
21
|
+
let h: number;
|
|
22
|
+
let d: number;
|
|
23
|
+
let w: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The defaults set with `time.setLocale()` and `time.setTimezone()`. English
|
|
27
|
+
* by default, so output never depends on the machine.
|
|
28
|
+
* @type {{ locale: string, timeZone: string | undefined }}
|
|
29
|
+
*/
|
|
30
|
+
export const timeConfig: {
|
|
31
|
+
locale: string;
|
|
32
|
+
timeZone: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
export const ASCII: RegExp;
|
|
35
|
+
/**
|
|
36
|
+
* @param {unknown} value
|
|
37
|
+
* @returns {value is Record<string, any>}
|
|
38
|
+
*/
|
|
39
|
+
export function isPlainObject(value: unknown): value is Record<string, any>;
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} unit
|
|
42
|
+
* @returns {keyof typeof MS | "M" | "y" | undefined}
|
|
43
|
+
*/
|
|
44
|
+
export function unitOf(unit: string): keyof typeof MS | "M" | "y" | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* A duration in milliseconds, or `null` when the input isn't one.
|
|
47
|
+
* @param {unknown} input
|
|
48
|
+
* @returns {number | null}
|
|
49
|
+
*/
|
|
50
|
+
export function parseDuration(input: unknown): number | null;
|
|
51
|
+
/**
|
|
52
|
+
* Milliseconds from a number or a duration string.
|
|
53
|
+
* @param {number | string} value
|
|
54
|
+
* @param {string} [what="duration"] Names the value in the error message.
|
|
55
|
+
* @returns {number}
|
|
56
|
+
* @throws {TypeError} If it can't be read.
|
|
57
|
+
*/
|
|
58
|
+
export function toMs(value: number | string, what?: string): number;
|
|
59
|
+
/**
|
|
60
|
+
* `setTimeout` that also works past its 24.8-day limit. `Infinity` never fires.
|
|
61
|
+
* @param {() => void} fn
|
|
62
|
+
* @param {number} ms
|
|
63
|
+
* @param {boolean} [unref=false]
|
|
64
|
+
* @returns {() => void} Cancels the timer.
|
|
65
|
+
*/
|
|
66
|
+
export function setLongTimeout(fn: () => void, ms: number, unref?: boolean): () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Resolves after `ms`, or rejects with an `AbortError` when the signal fires.
|
|
69
|
+
* @param {number} ms
|
|
70
|
+
* @param {AbortSignal} [signal]
|
|
71
|
+
* @param {boolean} [unref=false]
|
|
72
|
+
* @returns {Promise<void>}
|
|
73
|
+
*/
|
|
74
|
+
export function sleep(ms: number, signal?: AbortSignal, unref?: boolean): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Blocks the thread for a few milliseconds. Only for short retries of
|
|
77
|
+
* synchronous file operations.
|
|
78
|
+
* @param {number} ms
|
|
79
|
+
*/
|
|
80
|
+
export function sleepSync(ms: number): void;
|
|
81
|
+
export namespace intl {
|
|
82
|
+
let number: (locale?: string, options?: object) => Intl.NumberFormat;
|
|
83
|
+
let dateTime: (locale?: string, options?: object) => Intl.DateTimeFormat;
|
|
84
|
+
let plural: (locale?: string, options?: object) => Intl.PluralRules;
|
|
85
|
+
let collator: (locale?: string, options?: object) => Intl.Collator;
|
|
86
|
+
let relativeTime: (locale?: string, options?: object) => Intl.RelativeTimeFormat;
|
|
87
|
+
let list: (locale?: string, options?: object) => Intl.ListFormat;
|
|
88
|
+
}
|
|
89
|
+
/** The grapheme segmenter, built on first use. */
|
|
90
|
+
export function segmenter(): Intl.Segmenter;
|
|
91
|
+
/**
|
|
92
|
+
* Splits text into graphemes, so emoji and accents stay whole.
|
|
93
|
+
* @param {string} input
|
|
94
|
+
* @returns {string[]}
|
|
95
|
+
*/
|
|
96
|
+
export function graphemes(input: string): string[];
|
|
97
|
+
/**
|
|
98
|
+
* Counts graphemes without building an array.
|
|
99
|
+
* @param {string} input
|
|
100
|
+
* @returns {number}
|
|
101
|
+
*/
|
|
102
|
+
export function graphemeCount(input: string): number;
|
|
103
|
+
/**
|
|
104
|
+
* Adds numbers with Neumaier's compensation, so `0.1 + 0.2 + 0.3` is `0.6`.
|
|
105
|
+
* @param {Iterable<number>} values
|
|
106
|
+
* @returns {number}
|
|
107
|
+
*/
|
|
108
|
+
export function preciseSum(values: Iterable<number>): number;
|
|
109
|
+
/**
|
|
110
|
+
* A cache key for a list of arguments. Primitives are compared by value and
|
|
111
|
+
* type, plain objects and arrays by content, everything else by identity.
|
|
112
|
+
* @param {readonly unknown[]} args
|
|
113
|
+
* @returns {unknown} A primitive usable as a `Map` key.
|
|
114
|
+
*/
|
|
115
|
+
export function argsKey(args: readonly unknown[]): unknown;
|
|
116
|
+
/**
|
|
117
|
+
* Parses a cron expression with 5 fields, or 6 with seconds first.
|
|
118
|
+
* @param {string} expression
|
|
119
|
+
* @returns {CronSpec}
|
|
120
|
+
* @throws {SyntaxError} If the expression is invalid.
|
|
121
|
+
*/
|
|
122
|
+
export function parseCron(expression: string): CronSpec;
|
|
123
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/internal/shared.js"],"names":[],"mappings":";;;uBAmTa;IAAE,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,GAAG,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