@c9up/chronos 0.1.15 → 0.1.17

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.
Files changed (74) hide show
  1. package/README.md +136 -16
  2. package/dist/DateTime.d.ts +209 -8
  3. package/dist/DateTime.d.ts.map +1 -1
  4. package/dist/DateTime.js +815 -116
  5. package/dist/DateTime.js.map +1 -1
  6. package/dist/Duration.d.ts +37 -20
  7. package/dist/Duration.d.ts.map +1 -1
  8. package/dist/Duration.js +287 -120
  9. package/dist/Duration.js.map +1 -1
  10. package/dist/Interval.d.ts +50 -7
  11. package/dist/Interval.d.ts.map +1 -1
  12. package/dist/Interval.js +142 -29
  13. package/dist/Interval.js.map +1 -1
  14. package/dist/atlas.d.ts +11 -15
  15. package/dist/atlas.d.ts.map +1 -1
  16. package/dist/atlas.js +22 -17
  17. package/dist/atlas.js.map +1 -1
  18. package/dist/format.d.ts +47 -0
  19. package/dist/format.d.ts.map +1 -0
  20. package/dist/format.js +387 -0
  21. package/dist/format.js.map +1 -0
  22. package/dist/holidays.d.ts +43 -0
  23. package/dist/holidays.d.ts.map +1 -0
  24. package/dist/holidays.js +102 -0
  25. package/dist/holidays.js.map +1 -0
  26. package/dist/index.d.ts +8 -6
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +4 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/native/generated.d.ts +11 -2
  31. package/dist/native/generated.d.ts.map +1 -1
  32. package/dist/native.d.ts.map +1 -1
  33. package/dist/native.js +5 -2
  34. package/dist/native.js.map +1 -1
  35. package/dist/parse.d.ts +59 -0
  36. package/dist/parse.d.ts.map +1 -0
  37. package/dist/parse.js +404 -0
  38. package/dist/parse.js.map +1 -0
  39. package/dist/rrule.d.ts +34 -2
  40. package/dist/rrule.d.ts.map +1 -1
  41. package/dist/rrule.js +156 -32
  42. package/dist/rrule.js.map +1 -1
  43. package/index.darwin-arm64.node +0 -0
  44. package/index.darwin-x64.node +0 -0
  45. package/index.linux-arm64-gnu.node +0 -0
  46. package/index.linux-x64-gnu.node +0 -0
  47. package/index.win32-x64-msvc.node +0 -0
  48. package/package.json +2 -3
  49. package/src/DateTime.ts +1089 -124
  50. package/src/Duration.ts +318 -139
  51. package/src/Interval.ts +160 -53
  52. package/src/atlas.ts +23 -17
  53. package/src/format.ts +449 -0
  54. package/src/holidays.ts +161 -0
  55. package/src/index.ts +35 -7
  56. package/src/native/generated.ts +27 -2
  57. package/src/native.ts +7 -3
  58. package/src/parse.ts +559 -0
  59. package/src/rrule.ts +229 -38
  60. package/wasm/chronos_engine_wasm.d.ts +13 -4
  61. package/wasm/chronos_engine_wasm.js +87 -16
  62. package/wasm/chronos_engine_wasm_bg.wasm +0 -0
  63. package/wasm/chronos_engine_wasm_bg.wasm.d.ts +5 -2
  64. package/dist/utils.d.ts +0 -15
  65. package/dist/utils.d.ts.map +0 -1
  66. package/dist/utils.js +0 -17
  67. package/dist/utils.js.map +0 -1
  68. package/scripts/build-napi-types.mjs +0 -69
  69. package/scripts/clean-wasm-pack-meta.mjs +0 -32
  70. package/scripts/copy-napi.mjs +0 -56
  71. package/scripts/generate-napi-types.mjs +0 -156
  72. package/scripts/verify-napi.mjs +0 -46
  73. package/scripts/verify-wasm.mjs +0 -55
  74. package/src/utils.ts +0 -17
package/src/rrule.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type DateInput, DateTime } from "./DateTime.js";
1
2
  import { nativeChronos } from "./native.js";
2
3
 
3
4
  export type RRuleWeekday = "MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU";
@@ -24,41 +25,143 @@ export interface RRuleBuild {
24
25
  byMinute?: number[];
25
26
  bySecond?: number[];
26
27
  count?: number;
27
- until?: string;
28
+ /** Last instant of the series: a strict ISO 8601 string (UTC when offset-less) or a DateTime. */
29
+ until?: string | DateTime;
30
+ }
31
+
32
+ const FREQUENCIES: ReadonlySet<string> = new Set([
33
+ "SECONDLY",
34
+ "MINUTELY",
35
+ "HOURLY",
36
+ "DAILY",
37
+ "WEEKLY",
38
+ "MONTHLY",
39
+ "YEARLY",
40
+ ]);
41
+ const WEEKDAYS: ReadonlySet<string> = new Set([
42
+ "MO",
43
+ "TU",
44
+ "WE",
45
+ "TH",
46
+ "FR",
47
+ "SA",
48
+ "SU",
49
+ ]);
50
+ const BYDAY_TOKEN =
51
+ /^(?:[+-]?(?:[1-9]|[1-4]\d|5[0-3]))?(?:MO|TU|WE|TH|FR|SA|SU)$/;
52
+
53
+ /**
54
+ * The structured input is only typed, never trusted: a value that reaches the
55
+ * rule text unchecked (`byDay: ["MO;BYSECOND=0,0,…"]` from a JSON body) adds
56
+ * parts the caller never wrote.
57
+ */
58
+ function invalid(field: string, value: unknown): never {
59
+ throw new RangeError(`toRRuleString: invalid ${field} ${String(value)}`);
60
+ }
61
+
62
+ function checkInteger(
63
+ field: string,
64
+ value: unknown,
65
+ min: number,
66
+ max: number,
67
+ allowZero = true,
68
+ ): number {
69
+ if (
70
+ typeof value !== "number" ||
71
+ !Number.isInteger(value) ||
72
+ value < min ||
73
+ value > max ||
74
+ (value === 0 && !allowZero)
75
+ ) {
76
+ return invalid(field, value);
77
+ }
78
+ return value;
28
79
  }
29
80
 
30
81
  function pushNumericList(
31
82
  parts: string[],
32
83
  key: string,
33
- values: number[] | undefined,
84
+ field: string,
85
+ values: readonly unknown[] | undefined,
86
+ range: [min: number, max: number, allowZero: boolean],
34
87
  ): void {
35
- if (!values || values.length === 0) return;
36
- parts.push(`${key}=${values.join(",")}`);
88
+ if (values === undefined) return;
89
+ if (!Array.isArray(values)) invalid(field, values);
90
+ if (values.length === 0) return;
91
+ const checked = values.map((v) => checkInteger(field, v, ...range));
92
+ parts.push(`${key}=${checked.join(",")}`);
93
+ }
94
+
95
+ /**
96
+ * `until` goes through the same strict ISO 8601 door as every other date
97
+ * string: an offset-less value is UTC, and what V8's fallback parser would
98
+ * turn into a date (`"1"`, `"March 7"`) is refused instead of read in the
99
+ * host zone.
100
+ */
101
+ function readUntil(value: unknown): DateTime {
102
+ if (value instanceof DateTime) return value;
103
+ if (typeof value !== "string") return invalid("until", value);
104
+ try {
105
+ return DateTime.from(value);
106
+ } catch (cause) {
107
+ throw new RangeError(`toRRuleString: invalid until ${value}`, { cause });
108
+ }
37
109
  }
38
110
 
39
111
  export function toRRuleString(rule: RRuleBuild): string {
112
+ if (!FREQUENCIES.has(rule.freq)) invalid("freq", rule.freq);
40
113
  const parts: string[] = [`FREQ=${rule.freq}`];
41
114
 
42
- if (rule.interval && rule.interval !== 1)
43
- parts.push(`INTERVAL=${rule.interval}`);
44
- if (rule.wkst) parts.push(`WKST=${rule.wkst}`);
45
- if (rule.byDay?.length) parts.push(`BYDAY=${rule.byDay.join(",")}`);
46
-
47
- pushNumericList(parts, "BYMONTHDAY", rule.byMonthDay);
48
- pushNumericList(parts, "BYMONTH", rule.byMonth);
49
- pushNumericList(parts, "BYWEEKNO", rule.byWeekNo);
50
- pushNumericList(parts, "BYYEARDAY", rule.byYearDay);
51
- pushNumericList(parts, "BYSETPOS", rule.bySetPos);
52
- pushNumericList(parts, "BYHOUR", rule.byHour);
53
- pushNumericList(parts, "BYMINUTE", rule.byMinute);
54
- pushNumericList(parts, "BYSECOND", rule.bySecond);
55
-
56
- if (rule.count !== undefined) parts.push(`COUNT=${rule.count}`);
57
- if (rule.until) {
115
+ if (rule.interval !== undefined) {
116
+ const interval = checkInteger("interval", rule.interval, 1, 1_000_000_000);
117
+ if (interval !== 1) parts.push(`INTERVAL=${interval}`);
118
+ }
119
+ if (rule.wkst !== undefined) {
120
+ if (!WEEKDAYS.has(rule.wkst)) invalid("wkst", rule.wkst);
121
+ parts.push(`WKST=${rule.wkst}`);
122
+ }
123
+ if (rule.byDay !== undefined) {
124
+ if (!Array.isArray(rule.byDay)) invalid("byDay", rule.byDay);
125
+ for (const token of rule.byDay) {
126
+ if (typeof token !== "string" || !BYDAY_TOKEN.test(token))
127
+ invalid("byDay", token);
128
+ }
129
+ if (rule.byDay.length > 0) parts.push(`BYDAY=${rule.byDay.join(",")}`);
130
+ }
131
+
132
+ pushNumericList(parts, "BYMONTHDAY", "byMonthDay", rule.byMonthDay, [
133
+ -31,
134
+ 31,
135
+ false,
136
+ ]);
137
+ pushNumericList(parts, "BYMONTH", "byMonth", rule.byMonth, [1, 12, false]);
138
+ pushNumericList(parts, "BYWEEKNO", "byWeekNo", rule.byWeekNo, [
139
+ -53,
140
+ 53,
141
+ false,
142
+ ]);
143
+ pushNumericList(parts, "BYYEARDAY", "byYearDay", rule.byYearDay, [
144
+ -366,
145
+ 366,
146
+ false,
147
+ ]);
148
+ pushNumericList(parts, "BYSETPOS", "bySetPos", rule.bySetPos, [
149
+ -366,
150
+ 366,
151
+ false,
152
+ ]);
153
+ pushNumericList(parts, "BYHOUR", "byHour", rule.byHour, [0, 23, true]);
154
+ pushNumericList(parts, "BYMINUTE", "byMinute", rule.byMinute, [0, 59, true]);
155
+ pushNumericList(parts, "BYSECOND", "bySecond", rule.bySecond, [0, 59, true]);
156
+
157
+ if (rule.count !== undefined)
158
+ parts.push(`COUNT=${checkInteger("count", rule.count, 0, 1_000_000_000)}`);
159
+ if (rule.until !== undefined) {
58
160
  // RFC 5545 §3.3.10 UNTIL format: YYYYMMDDTHHMMSSZ (no hyphens/colons/ms).
59
161
  parts.push(
60
- `UNTIL=${new Date(rule.until)
61
- .toISOString()
162
+ `UNTIL=${readUntil(rule.until)
163
+ .toUTC()
164
+ .toISO()
62
165
  .replace(/[-:]/g, "")
63
166
  .replace(/\.\d+Z$/, "Z")}`,
64
167
  );
@@ -68,24 +171,56 @@ export function toRRuleString(rule: RRuleBuild): string {
68
171
  }
69
172
 
70
173
  /**
71
- * Expand an RRULE into concrete occurrence dates. **NAPI-only** — the Rust
72
- * engine handles the full RFC 5545 spec (BYDAY, BYSETPOS, BYMONTHDAY,
73
- * BYWEEKNO, BYYEARDAY, UNTIL, COUNT, INTERVAL, WKST). No TS fallback.
174
+ * Hard cap on the number of occurrences one call returns, so a caller passing
175
+ * an absurd limit (or one derived from user input) cannot ask for an unbounded
176
+ * result. 10 000 covers any realistic page; page through the series (start
177
+ * from the last occurrence) for more.
74
178
  */
179
+ const MAX_RRULE_EXPAND = 10_000;
180
+
181
+ export interface ExpandRRuleOptions {
182
+ /** Most occurrences to return (1 – 10 000, default 100). */
183
+ limit?: number;
184
+ /**
185
+ * IANA zone whose wall clock the rule runs on (RFC 5545 DTSTART;TZID): a
186
+ * weekly 09:00 series stays at 09:00 local across DST. Defaults to the zone
187
+ * of a zoned `DateTime` start, else UTC.
188
+ */
189
+ tzid?: string;
190
+ /**
191
+ * Occurrences the series does not have (RFC 5545 EXDATE): each removes the
192
+ * occurrence at that very instant, if there is one. COUNT still counts it.
193
+ */
194
+ exdates?: readonly DateInput[];
195
+ /** Occurrences added to the series (RFC 5545 RDATE), outside COUNT and UNTIL. */
196
+ rdates?: readonly DateInput[];
197
+ }
198
+
75
199
  /**
76
- * Hard cap on `expandRRule(... , limit)` so a caller passing an absurd
77
- * number (or one derived from user input) can't ask the Rust engine to
78
- * allocate gigabytes / run for seconds. 10_000 covers any realistic
79
- * pagination + cushion (a year of every-minute occurrences = ~525k, so
80
- * apps wanting that should iterate or stream, not call once).
200
+ * The EXDATE and RDATE lines for instants, in UTC: appended to the rule text,
201
+ * they are expanded with it (at most 10 000 of them, the text 256 KiB).
81
202
  */
82
- const MAX_RRULE_EXPAND = 10_000;
203
+ function dateLines(options: ExpandRRuleOptions): string {
204
+ const line = (property: string, dates: readonly DateInput[] | undefined) =>
205
+ dates === undefined || dates.length === 0
206
+ ? ""
207
+ : `\n${property}:${dates.map((date) => DateTime.from(date).toUTC().format("YYYYMMDD[T]HHmmss[Z]")).join(",")}`;
208
+ return line("EXDATE", options.exdates) + line("RDATE", options.rdates);
209
+ }
83
210
 
84
- export function expandRRule(
85
- startIso: string,
86
- rrule: string | RRuleBuild,
87
- limit = 100,
88
- ): string[] {
211
+ function isRRuleBuild(value: unknown): value is RRuleBuild {
212
+ return typeof value === "object" && value !== null && "freq" in value;
213
+ }
214
+
215
+ function readOptions(
216
+ options: number | ExpandRRuleOptions | undefined,
217
+ ): ExpandRRuleOptions {
218
+ if (options === undefined) return {};
219
+ if (typeof options === "number") return { limit: options };
220
+ return options;
221
+ }
222
+
223
+ function checkLimit(limit: number): number {
89
224
  if (!Number.isInteger(limit) || limit < 1) {
90
225
  throw new RangeError(
91
226
  `expandRRule(limit) must be a positive integer (got ${String(limit)})`,
@@ -97,6 +232,62 @@ export function expandRRule(
97
232
  "Page through the result set instead of asking for everything at once.",
98
233
  );
99
234
  }
100
- const built = typeof rrule === "string" ? rrule : toRRuleString(rrule);
101
- return nativeChronos().rruleExpand(startIso, built, limit);
235
+ return limit;
236
+ }
237
+
238
+ /**
239
+ * Expand an RRULE (RFC 5545) into occurrences, returned as UTC ISO strings.
240
+ *
241
+ * - `expandRRule(start, rule, limit | { limit, tzid })` — `start` is DTSTART;
242
+ * a zoned `DateTime` makes the rule run on its zone's wall clock.
243
+ * - `expandRRule("DTSTART;TZID=Europe/Paris:20260323T090000\nRRULE:…", options)`
244
+ * — the iCalendar form, DTSTART read from the text.
245
+ *
246
+ * The Rust engine bounds the work whatever the rule says (BY* lists are sets,
247
+ * the text is capped at 8 KB, iteration ends at year 9999), so a rule taken
248
+ * from user input or an imported .ics cannot exhaust memory or hold the thread.
249
+ */
250
+ export function expandRRule(
251
+ start: DateInput,
252
+ rrule: string | RRuleBuild,
253
+ options?: number | ExpandRRuleOptions,
254
+ ): string[];
255
+ export function expandRRule(
256
+ rule: string,
257
+ options?: number | ExpandRRuleOptions,
258
+ ): string[];
259
+ export function expandRRule(
260
+ start: DateInput,
261
+ rruleOrOptions?: string | RRuleBuild | number | ExpandRRuleOptions,
262
+ maybeOptions?: number | ExpandRRuleOptions,
263
+ ): string[] {
264
+ if (typeof rruleOrOptions === "string" || isRRuleBuild(rruleOrOptions)) {
265
+ const options = readOptions(maybeOptions);
266
+ const limit = checkLimit(options.limit ?? 100);
267
+ const from = DateTime.from(start);
268
+ const tzid =
269
+ options.tzid ?? (from.zoneName === "UTC" ? undefined : from.zoneName);
270
+ const rule =
271
+ typeof rruleOrOptions === "string"
272
+ ? rruleOrOptions
273
+ : toRRuleString(rruleOrOptions);
274
+ return nativeChronos().rruleExpand(
275
+ from.toISO(),
276
+ rule + dateLines(options),
277
+ limit,
278
+ tzid,
279
+ );
280
+ }
281
+ if (typeof start !== "string") {
282
+ throw new TypeError(
283
+ "expandRRule(rule, options) takes the rule text, with its DTSTART line, as the first argument",
284
+ );
285
+ }
286
+ const options = readOptions(rruleOrOptions);
287
+ return nativeChronos().rruleExpand(
288
+ undefined,
289
+ start + dateLines(options),
290
+ checkLimit(options.limit ?? 100),
291
+ options.tzid,
292
+ );
102
293
  }
@@ -11,6 +11,8 @@ export function diff(a_iso: string, b_iso: string, unit: string): number;
11
11
 
12
12
  export function diff_in_zone(a_utc: string, b_utc: string, unit: string, zone: string): number;
13
13
 
14
+ export function easter_date(year: number): string;
15
+
14
16
  export function end_of(iso: string, unit: string): string;
15
17
 
16
18
  export function end_of_in_zone(utc_iso: string, unit: string, zone: string): string;
@@ -19,13 +21,17 @@ export function format(iso: string, pattern: string): string;
19
21
 
20
22
  export function from_local(naive_iso: string, zone: string): string;
21
23
 
24
+ export function holidays(year: number, country: string, region?: string | null): any;
25
+
26
+ export function is_holiday(date: string, country: string, region?: string | null): boolean;
27
+
22
28
  export function parse_http(input: string): string;
23
29
 
24
30
  export function parse_rfc2822(input: string): string;
25
31
 
26
- export function parse_sql(input: string): string;
32
+ export function parse_sql(input: string, zone?: string | null): string;
27
33
 
28
- export function rrule_expand(start_iso: string, rrule: string, limit: number): any;
34
+ export function rrule_expand(start_iso: string | null | undefined, rrule: string, limit: number, tzid?: string | null): any;
29
35
 
30
36
  export function start_of(iso: string, unit: string): string;
31
37
 
@@ -46,14 +52,17 @@ export interface InitOutput {
46
52
  readonly calendar_parts: (a: number, b: number) => [number, number, number];
47
53
  readonly diff: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
48
54
  readonly diff_in_zone: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
55
+ readonly easter_date: (a: number) => [number, number, number, number];
49
56
  readonly end_of: (a: number, b: number, c: number, d: number) => [number, number, number, number];
50
57
  readonly end_of_in_zone: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
51
58
  readonly format: (a: number, b: number, c: number, d: number) => [number, number, number, number];
52
59
  readonly from_local: (a: number, b: number, c: number, d: number) => [number, number, number, number];
60
+ readonly holidays: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
61
+ readonly is_holiday: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
53
62
  readonly parse_http: (a: number, b: number) => [number, number, number, number];
54
63
  readonly parse_rfc2822: (a: number, b: number) => [number, number, number, number];
55
- readonly parse_sql: (a: number, b: number) => [number, number, number, number];
56
- readonly rrule_expand: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
64
+ readonly parse_sql: (a: number, b: number, c: number, d: number) => [number, number, number, number];
65
+ readonly rrule_expand: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
57
66
  readonly start_of: (a: number, b: number, c: number, d: number) => [number, number, number, number];
58
67
  readonly start_of_in_zone: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
59
68
  readonly to_zone: (a: number, b: number, c: number, d: number) => [number, number, number];
@@ -118,6 +118,29 @@ export function diff_in_zone(a_utc, b_utc, unit, zone) {
118
118
  return ret[0];
119
119
  }
120
120
 
121
+ /**
122
+ * @param {number} year
123
+ * @returns {string}
124
+ */
125
+ export function easter_date(year) {
126
+ let deferred2_0;
127
+ let deferred2_1;
128
+ try {
129
+ const ret = wasm.easter_date(year);
130
+ var ptr1 = ret[0];
131
+ var len1 = ret[1];
132
+ if (ret[3]) {
133
+ ptr1 = 0; len1 = 0;
134
+ throw takeFromExternrefTable0(ret[2]);
135
+ }
136
+ deferred2_0 = ptr1;
137
+ deferred2_1 = len1;
138
+ return getStringFromWasm0(ptr1, len1);
139
+ } finally {
140
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
141
+ }
142
+ }
143
+
121
144
  /**
122
145
  * @param {string} iso
123
146
  * @param {string} unit
@@ -233,6 +256,44 @@ export function from_local(naive_iso, zone) {
233
256
  }
234
257
  }
235
258
 
259
+ /**
260
+ * @param {number} year
261
+ * @param {string} country
262
+ * @param {string | null} [region]
263
+ * @returns {any}
264
+ */
265
+ export function holidays(year, country, region) {
266
+ const ptr0 = passStringToWasm0(country, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ var ptr1 = isLikeNone(region) ? 0 : passStringToWasm0(region, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
269
+ var len1 = WASM_VECTOR_LEN;
270
+ const ret = wasm.holidays(year, ptr0, len0, ptr1, len1);
271
+ if (ret[2]) {
272
+ throw takeFromExternrefTable0(ret[1]);
273
+ }
274
+ return takeFromExternrefTable0(ret[0]);
275
+ }
276
+
277
+ /**
278
+ * @param {string} date
279
+ * @param {string} country
280
+ * @param {string | null} [region]
281
+ * @returns {boolean}
282
+ */
283
+ export function is_holiday(date, country, region) {
284
+ const ptr0 = passStringToWasm0(date, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
285
+ const len0 = WASM_VECTOR_LEN;
286
+ const ptr1 = passStringToWasm0(country, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
287
+ const len1 = WASM_VECTOR_LEN;
288
+ var ptr2 = isLikeNone(region) ? 0 : passStringToWasm0(region, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
289
+ var len2 = WASM_VECTOR_LEN;
290
+ const ret = wasm.is_holiday(ptr0, len0, ptr1, len1, ptr2, len2);
291
+ if (ret[2]) {
292
+ throw takeFromExternrefTable0(ret[1]);
293
+ }
294
+ return ret[0] !== 0;
295
+ }
296
+
236
297
  /**
237
298
  * @param {string} input
238
299
  * @returns {string}
@@ -285,41 +346,47 @@ export function parse_rfc2822(input) {
285
346
 
286
347
  /**
287
348
  * @param {string} input
349
+ * @param {string | null} [zone]
288
350
  * @returns {string}
289
351
  */
290
- export function parse_sql(input) {
291
- let deferred3_0;
292
- let deferred3_1;
352
+ export function parse_sql(input, zone) {
353
+ let deferred4_0;
354
+ let deferred4_1;
293
355
  try {
294
356
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
295
357
  const len0 = WASM_VECTOR_LEN;
296
- const ret = wasm.parse_sql(ptr0, len0);
297
- var ptr2 = ret[0];
298
- var len2 = ret[1];
358
+ var ptr1 = isLikeNone(zone) ? 0 : passStringToWasm0(zone, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
359
+ var len1 = WASM_VECTOR_LEN;
360
+ const ret = wasm.parse_sql(ptr0, len0, ptr1, len1);
361
+ var ptr3 = ret[0];
362
+ var len3 = ret[1];
299
363
  if (ret[3]) {
300
- ptr2 = 0; len2 = 0;
364
+ ptr3 = 0; len3 = 0;
301
365
  throw takeFromExternrefTable0(ret[2]);
302
366
  }
303
- deferred3_0 = ptr2;
304
- deferred3_1 = len2;
305
- return getStringFromWasm0(ptr2, len2);
367
+ deferred4_0 = ptr3;
368
+ deferred4_1 = len3;
369
+ return getStringFromWasm0(ptr3, len3);
306
370
  } finally {
307
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
371
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
308
372
  }
309
373
  }
310
374
 
311
375
  /**
312
- * @param {string} start_iso
376
+ * @param {string | null | undefined} start_iso
313
377
  * @param {string} rrule
314
378
  * @param {number} limit
379
+ * @param {string | null} [tzid]
315
380
  * @returns {any}
316
381
  */
317
- export function rrule_expand(start_iso, rrule, limit) {
318
- const ptr0 = passStringToWasm0(start_iso, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
319
- const len0 = WASM_VECTOR_LEN;
382
+ export function rrule_expand(start_iso, rrule, limit, tzid) {
383
+ var ptr0 = isLikeNone(start_iso) ? 0 : passStringToWasm0(start_iso, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
384
+ var len0 = WASM_VECTOR_LEN;
320
385
  const ptr1 = passStringToWasm0(rrule, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
321
386
  const len1 = WASM_VECTOR_LEN;
322
- const ret = wasm.rrule_expand(ptr0, len0, ptr1, len1, limit);
387
+ var ptr2 = isLikeNone(tzid) ? 0 : passStringToWasm0(tzid, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
388
+ var len2 = WASM_VECTOR_LEN;
389
+ const ret = wasm.rrule_expand(ptr0, len0, ptr1, len1, limit, ptr2, len2);
323
390
  if (ret[2]) {
324
391
  throw takeFromExternrefTable0(ret[1]);
325
392
  }
@@ -518,6 +585,10 @@ function handleError(f, args) {
518
585
  }
519
586
  }
520
587
 
588
+ function isLikeNone(x) {
589
+ return x === undefined || x === null;
590
+ }
591
+
521
592
  function passStringToWasm0(arg, malloc, realloc) {
522
593
  if (realloc === undefined) {
523
594
  const buf = cachedTextEncoder.encode(arg);
Binary file
@@ -6,14 +6,17 @@ export const add_in_zone: (a: number, b: number, c: bigint, d: number, e: number
6
6
  export const calendar_parts: (a: number, b: number) => [number, number, number];
7
7
  export const diff: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
8
8
  export const diff_in_zone: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number];
9
+ export const easter_date: (a: number) => [number, number, number, number];
9
10
  export const end_of: (a: number, b: number, c: number, d: number) => [number, number, number, number];
10
11
  export const end_of_in_zone: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
11
12
  export const format: (a: number, b: number, c: number, d: number) => [number, number, number, number];
12
13
  export const from_local: (a: number, b: number, c: number, d: number) => [number, number, number, number];
14
+ export const holidays: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
15
+ export const is_holiday: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
13
16
  export const parse_http: (a: number, b: number) => [number, number, number, number];
14
17
  export const parse_rfc2822: (a: number, b: number) => [number, number, number, number];
15
- export const parse_sql: (a: number, b: number) => [number, number, number, number];
16
- export const rrule_expand: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
18
+ export const parse_sql: (a: number, b: number, c: number, d: number) => [number, number, number, number];
19
+ export const rrule_expand: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
17
20
  export const start_of: (a: number, b: number, c: number, d: number) => [number, number, number, number];
18
21
  export const start_of_in_zone: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
19
22
  export const to_zone: (a: number, b: number, c: number, d: number) => [number, number, number];
package/dist/utils.d.ts DELETED
@@ -1,15 +0,0 @@
1
- /**
2
- * Shared helpers for DateTime and RRule modules.
3
- */
4
- /**
5
- * Normalize an ISO 8601 string.
6
- *
7
- * Milliseconds are KEPT even when zero, so `toISO()` reads
8
- * `2026-07-15T10:00:00.000Z` — what Luxon's `toISO()` returns, and therefore
9
- * what `@adonisjs/lucid` puts in a serialized model. Chronos used to strip
10
- * `.000`, which is Luxon's opt-in `toISO({ suppressMilliseconds: true })`:
11
- * the same instant, a different literal, and a silent difference in every JSON
12
- * payload carrying a date.
13
- */
14
- export declare function normalizeIso(iso: string): string;
15
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
package/dist/utils.js DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * Shared helpers for DateTime and RRule modules.
3
- */
4
- /**
5
- * Normalize an ISO 8601 string.
6
- *
7
- * Milliseconds are KEPT even when zero, so `toISO()` reads
8
- * `2026-07-15T10:00:00.000Z` — what Luxon's `toISO()` returns, and therefore
9
- * what `@adonisjs/lucid` puts in a serialized model. Chronos used to strip
10
- * `.000`, which is Luxon's opt-in `toISO({ suppressMilliseconds: true })`:
11
- * the same instant, a different literal, and a silent difference in every JSON
12
- * payload carrying a date.
13
- */
14
- export function normalizeIso(iso) {
15
- return iso;
16
- }
17
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -1,69 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Regenerate `src/native/generated.ts` from the Rust.
4
- *
5
- * Node rather than a shell script because this runs inside `build:napi`, and
6
- * that runs on the Windows prebuild runner too: a bash `mktemp` there hands
7
- * cargo a `/tmp/...` path the native proc-macro cannot write to, so the
8
- * type-def file comes back empty and the build fails for no visible reason.
9
- *
10
- * One crate at a time on purpose: with napi-derive 2 the writes all went to a
11
- * single `TYPE_DEF_TMP_PATH` and a parallel build interleaved them
12
- * while cargo compiles, and a parallel build interleaves the writes —
13
- * definitions go missing, silently, and the generated file comes out short.
14
- */
15
-
16
- import { execFileSync } from 'node:child_process'
17
- import { createRequire } from 'node:module'
18
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
19
- import { tmpdir } from 'node:os'
20
- import { dirname, join } from 'node:path'
21
- import { fileURLToPath } from 'node:url'
22
-
23
- const CRATES = ['chronos-engine-napi']
24
-
25
- const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
26
- const output = join('src', 'native', 'generated.ts')
27
- const scratch = mkdtempSync(join(tmpdir(), 'napi-types-'))
28
-
29
- try {
30
- const lines = []
31
- for (const crate of CRATES) {
32
- const perCrate = join(scratch, crate)
33
- writeFileSync(perCrate, '')
34
- execFileSync('cargo', ['build', '-p', crate], {
35
- cwd: packageRoot,
36
- env: { ...process.env, NAPI_TYPE_DEF_TMP_FOLDER: scratch },
37
- stdio: ['ignore', 'ignore', 'inherit'],
38
- })
39
- const emitted = readFileSync(perCrate, 'utf8').split('\n').filter(Boolean)
40
- if (emitted.length === 0) {
41
- throw new Error(
42
- `[napi-types] ${crate} emitted nothing — is napi-derive's "type-def" feature on?`,
43
- )
44
- }
45
- lines.push(...emitted)
46
- }
47
-
48
- const combined = join(scratch, 'combined.jsonl')
49
- writeFileSync(combined, `${lines.join('\n')}\n`)
50
-
51
- execFileSync(
52
- process.execPath,
53
- [join('scripts', 'generate-napi-types.mjs'), combined, output],
54
- { cwd: packageRoot, stdio: 'inherit' },
55
- )
56
-
57
- // Formatted here rather than excluded from the linter: the file is checked
58
- // in, so it should read like the rest of the tree — and formatting it at
59
- // generation means it never shows up as a diff someone has to fix by hand.
60
- // Resolved through the package entry rather than `node_modules/.bin`, whose
61
- // shim is a shell script the Windows runner cannot execute directly.
62
- const biome = createRequire(import.meta.url).resolve('@biomejs/biome/bin/biome')
63
- execFileSync(process.execPath, [biome, 'format', '--write', output], {
64
- cwd: packageRoot,
65
- stdio: ['ignore', 'ignore', 'inherit'],
66
- })
67
- } finally {
68
- rmSync(scratch, { recursive: true, force: true })
69
- }
@@ -1,32 +0,0 @@
1
- import { existsSync, rmSync } from 'node:fs'
2
- import { dirname, join } from 'node:path'
3
- import { fileURLToPath } from 'node:url'
4
-
5
- // Removes the package metadata `wasm-pack` writes into its output directory.
6
- //
7
- // `wasm-pack build` treats its out-dir as a publishable package of its own and
8
- // scaffolds one: a `package.json`, and a `.gitignore` whose entire content is
9
- // `*`. Ours is not a package — it is a directory inside this one, listed in
10
- // `files`.
11
- //
12
- // The `.gitignore` is the damaging half. npm honours a .gitignore nested INSIDE
13
- // a published directory even when `files` lists that directory, so a single `*`
14
- // silently strips every artifact from the tarball — the built .js and .wasm, and
15
- // the committed .d.ts stub with them. The package then publishes green and every
16
- // browser consumer gets the engine-missing error. Measured here: with the file
17
- // present `npm pack --dry-run` reports zero wasm/ entries, without it, three.
18
- //
19
- // Runs right after wasm-pack, before anything packs.
20
-
21
- const wasmDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'wasm')
22
-
23
- // Only what wasm-pack scaffolds. The artifacts and the committed .d.ts stay.
24
- const generated = ['.gitignore', 'package.json', 'README.md', 'LICENSE']
25
-
26
- for (const name of generated) {
27
- const path = join(wasmDir, name)
28
- if (existsSync(path)) {
29
- rmSync(path)
30
- console.log(`[wasm] removed generated wasm/${name}`)
31
- }
32
- }