speexjs-core 0.7.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/CONTRIBUTING.md +55 -0
  3. package/PUBLISH.md +45 -0
  4. package/README.md +174 -0
  5. package/ROADMAP.md +72 -0
  6. package/SECURITY.md +35 -0
  7. package/SUMMARY.md +321 -0
  8. package/dist/async/index.d.ts +232 -0
  9. package/dist/async/index.js +366 -0
  10. package/dist/async/index.js.map +1 -0
  11. package/dist/collection/index.d.ts +230 -0
  12. package/dist/collection/index.js +375 -0
  13. package/dist/collection/index.js.map +1 -0
  14. package/dist/color/index.d.ts +128 -0
  15. package/dist/color/index.js +167 -0
  16. package/dist/color/index.js.map +1 -0
  17. package/dist/core/index.d.ts +119 -0
  18. package/dist/core/index.js +324 -0
  19. package/dist/core/index.js.map +1 -0
  20. package/dist/crypto/index.d.ts +84 -0
  21. package/dist/crypto/index.js +144 -0
  22. package/dist/crypto/index.js.map +1 -0
  23. package/dist/date/index.d.ts +588 -0
  24. package/dist/date/index.js +737 -0
  25. package/dist/date/index.js.map +1 -0
  26. package/dist/dep-exray/analyzer/index.d.ts +7 -0
  27. package/dist/dep-exray/analyzer/index.js +68 -0
  28. package/dist/dep-exray/analyzer/index.js.map +1 -0
  29. package/dist/dep-exray/cli.d.ts +1 -0
  30. package/dist/dep-exray/cli.js +441 -0
  31. package/dist/dep-exray/cli.js.map +1 -0
  32. package/dist/dep-exray/index.d.ts +5 -0
  33. package/dist/dep-exray/index.js +454 -0
  34. package/dist/dep-exray/index.js.map +1 -0
  35. package/dist/dep-exray/known-mappings.d.ts +17 -0
  36. package/dist/dep-exray/known-mappings.js +122 -0
  37. package/dist/dep-exray/known-mappings.js.map +1 -0
  38. package/dist/dep-exray/reporter/index.d.ts +5 -0
  39. package/dist/dep-exray/reporter/index.js +89 -0
  40. package/dist/dep-exray/reporter/index.js.map +1 -0
  41. package/dist/dep-exray/scanner/index.d.ts +5 -0
  42. package/dist/dep-exray/scanner/index.js +299 -0
  43. package/dist/dep-exray/scanner/index.js.map +1 -0
  44. package/dist/dep-exray/types.d.ts +38 -0
  45. package/dist/dep-exray/types.js +1 -0
  46. package/dist/dep-exray/types.js.map +1 -0
  47. package/dist/error/index.d.ts +148 -0
  48. package/dist/error/index.js +115 -0
  49. package/dist/error/index.js.map +1 -0
  50. package/dist/index-BgG21uJC.d.ts +166 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +4378 -0
  53. package/dist/index.js.map +1 -0
  54. package/dist/io/index.d.ts +39 -0
  55. package/dist/io/index.js +111 -0
  56. package/dist/io/index.js.map +1 -0
  57. package/dist/logger/index.d.ts +1 -0
  58. package/dist/logger/index.js +214 -0
  59. package/dist/logger/index.js.map +1 -0
  60. package/dist/logger/transports.d.ts +1 -0
  61. package/dist/logger/transports.js +122 -0
  62. package/dist/logger/transports.js.map +1 -0
  63. package/dist/math/index.d.ts +362 -0
  64. package/dist/math/index.js +372 -0
  65. package/dist/math/index.js.map +1 -0
  66. package/dist/path/index.d.ts +81 -0
  67. package/dist/path/index.js +134 -0
  68. package/dist/path/index.js.map +1 -0
  69. package/dist/string/index.d.ts +234 -0
  70. package/dist/string/index.js +411 -0
  71. package/dist/string/index.js.map +1 -0
  72. package/dist/type/index.d.ts +85 -0
  73. package/dist/type/index.js +107 -0
  74. package/dist/type/index.js.map +1 -0
  75. package/dist/validation/index.d.ts +203 -0
  76. package/dist/validation/index.js +402 -0
  77. package/dist/validation/index.js.map +1 -0
  78. package/package.json +172 -0
@@ -0,0 +1,737 @@
1
+ // src/date/index.ts
2
+ var InvalidDateError = class extends Error {
3
+ constructor(input) {
4
+ super(`Invalid date: ${String(input)}`);
5
+ this.name = "InvalidDateError";
6
+ }
7
+ };
8
+ var MONTH_NAMES_SHORT = [
9
+ "Jan",
10
+ "Feb",
11
+ "Mar",
12
+ "Apr",
13
+ "May",
14
+ "Jun",
15
+ "Jul",
16
+ "Aug",
17
+ "Sep",
18
+ "Oct",
19
+ "Nov",
20
+ "Dec"
21
+ ];
22
+ var MONTH_NAMES_FULL = [
23
+ "January",
24
+ "February",
25
+ "March",
26
+ "April",
27
+ "May",
28
+ "June",
29
+ "July",
30
+ "August",
31
+ "September",
32
+ "October",
33
+ "November",
34
+ "December"
35
+ ];
36
+ var MONTH_MAP = {
37
+ jan: 0,
38
+ january: 0,
39
+ feb: 1,
40
+ february: 1,
41
+ mar: 2,
42
+ march: 2,
43
+ apr: 3,
44
+ april: 3,
45
+ may: 4,
46
+ jun: 5,
47
+ june: 5,
48
+ jul: 6,
49
+ july: 6,
50
+ aug: 7,
51
+ august: 7,
52
+ sep: 8,
53
+ september: 8,
54
+ oct: 9,
55
+ october: 9,
56
+ nov: 10,
57
+ november: 10,
58
+ dec: 11,
59
+ december: 11
60
+ };
61
+ function formatDate(date, format = "YYYY-MM-DD") {
62
+ const year = date.getFullYear();
63
+ const month = date.getMonth();
64
+ const day = date.getDate();
65
+ const hours = date.getHours();
66
+ const minutes = date.getMinutes();
67
+ const seconds = date.getSeconds();
68
+ const ms = date.getMilliseconds();
69
+ const pad = (n, len = 2) => String(n).padStart(len, "0");
70
+ return format.replace(/YYYY/g, String(year)).replace(/YY/g, String(year).slice(-2)).replace(/MMMM/g, MONTH_NAMES_FULL[month]).replace(/MMM/g, MONTH_NAMES_SHORT[month]).replace(/MM/g, pad(month + 1)).replace(/DD/g, pad(day)).replace(/HH/g, pad(hours)).replace(/mm/g, pad(minutes)).replace(/ss/g, pad(seconds)).replace(/SSS/g, pad(ms, 3));
71
+ }
72
+ function parseDate(input) {
73
+ if (input instanceof Date) {
74
+ if (isNaN(input.getTime())) throw new InvalidDateError(input);
75
+ return new Date(input.getTime());
76
+ }
77
+ if (typeof input === "number") {
78
+ const d = new Date(input);
79
+ if (isNaN(d.getTime())) throw new InvalidDateError(input);
80
+ return d;
81
+ }
82
+ const trimmed = input.trim();
83
+ const isoMatch = trimmed.match(/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?(?:Z|[+-]\d{2}:?\d{2})?$/);
84
+ if (isoMatch) {
85
+ const d = new Date(
86
+ parseInt(isoMatch[1], 10),
87
+ parseInt(isoMatch[2], 10) - 1,
88
+ parseInt(isoMatch[3], 10),
89
+ isoMatch[4] ? parseInt(isoMatch[4], 10) : 0,
90
+ isoMatch[5] ? parseInt(isoMatch[5], 10) : 0,
91
+ isoMatch[6] ? parseInt(isoMatch[6], 10) : 0,
92
+ isoMatch[7] ? parseInt(isoMatch[7].padEnd(3, "0"), 10) : 0
93
+ );
94
+ if (!isNaN(d.getTime())) return d;
95
+ }
96
+ const dmyMatch = trimmed.match(/^(\d{1,2})[\/-](\d{1,2})[\/-](\d{4})$/);
97
+ if (dmyMatch) {
98
+ const year = parseInt(dmyMatch[3], 10);
99
+ const month = parseInt(dmyMatch[2], 10) - 1;
100
+ const day = parseInt(dmyMatch[1], 10);
101
+ const d = new Date(year, month, day);
102
+ if (!isNaN(d.getTime()) && d.getMonth() === month && d.getDate() === day) return d;
103
+ }
104
+ const textMatch = trimmed.match(/^(\d{1,2})\s+([a-zA-Z]+)\s+(\d{4})$/);
105
+ if (textMatch) {
106
+ const monthIndex = MONTH_MAP[textMatch[2].toLowerCase()];
107
+ if (monthIndex !== void 0) {
108
+ const year = parseInt(textMatch[3], 10);
109
+ const day = parseInt(textMatch[1], 10);
110
+ const d = new Date(year, monthIndex, day);
111
+ if (!isNaN(d.getTime()) && d.getMonth() === monthIndex && d.getDate() === day) return d;
112
+ }
113
+ }
114
+ const numMatch = trimmed.match(/^-?\d+$/);
115
+ if (numMatch) {
116
+ const d = new Date(parseInt(numMatch[0], 10));
117
+ if (!isNaN(d.getTime())) return d;
118
+ }
119
+ const fallback = new Date(trimmed);
120
+ if (!isNaN(fallback.getTime())) return fallback;
121
+ throw new InvalidDateError(input);
122
+ }
123
+ function isValidDate(d) {
124
+ return d instanceof Date && !isNaN(d.getTime());
125
+ }
126
+ var MS_IN_SECOND = 1e3;
127
+ var MS_IN_MINUTE = 60 * MS_IN_SECOND;
128
+ var MS_IN_HOUR = 60 * MS_IN_MINUTE;
129
+ var MS_IN_DAY = 24 * MS_IN_HOUR;
130
+ function dateDiff(date1, date2) {
131
+ if (!isValidDate(date1) || !isValidDate(date2)) {
132
+ throw new InvalidDateError("Invalid date provided to dateDiff");
133
+ }
134
+ let years = date2.getFullYear() - date1.getFullYear();
135
+ let months = date2.getMonth() - date1.getMonth();
136
+ let days = date2.getDate() - date1.getDate();
137
+ if (days < 0) {
138
+ months -= 1;
139
+ const prevMonth = new Date(date2.getFullYear(), date2.getMonth(), 0);
140
+ days += prevMonth.getDate();
141
+ }
142
+ if (months < 0) {
143
+ years -= 1;
144
+ months += 12;
145
+ }
146
+ const msDiff = Math.abs(date2.getTime() - date1.getTime());
147
+ const totalSeconds = Math.floor(msDiff / MS_IN_SECOND);
148
+ const hours = Math.floor(msDiff % MS_IN_DAY / MS_IN_HOUR);
149
+ const minutes = Math.floor(msDiff % MS_IN_HOUR / MS_IN_MINUTE);
150
+ const seconds = totalSeconds % 60;
151
+ return { years, months, days, hours, minutes, seconds };
152
+ }
153
+ function addDays(date, days) {
154
+ if (!isValidDate(date)) throw new InvalidDateError(date);
155
+ const result = new Date(date.getTime());
156
+ result.setDate(result.getDate() + days);
157
+ return result;
158
+ }
159
+ function addMonths(date, months) {
160
+ if (!isValidDate(date)) throw new InvalidDateError(date);
161
+ const result = new Date(date.getTime());
162
+ const targetMonth = result.getMonth() + months;
163
+ result.setMonth(targetMonth);
164
+ if (result.getMonth() !== (targetMonth % 12 + 12) % 12) {
165
+ result.setDate(0);
166
+ }
167
+ return result;
168
+ }
169
+ function addYears(date, years) {
170
+ if (!isValidDate(date)) throw new InvalidDateError(date);
171
+ const result = new Date(date.getTime());
172
+ const targetYear = result.getFullYear() + years;
173
+ result.setFullYear(targetYear);
174
+ if (result.getFullYear() !== targetYear) {
175
+ result.setDate(0);
176
+ }
177
+ return result;
178
+ }
179
+ function startOfDay(date) {
180
+ if (!isValidDate(date)) throw new InvalidDateError(date);
181
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
182
+ }
183
+ function endOfDay(date) {
184
+ if (!isValidDate(date)) throw new InvalidDateError(date);
185
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
186
+ }
187
+ function startOfMonth(date) {
188
+ if (!isValidDate(date)) throw new InvalidDateError(date);
189
+ return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
190
+ }
191
+ function endOfMonth(date) {
192
+ if (!isValidDate(date)) throw new InvalidDateError(date);
193
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 999);
194
+ }
195
+ function startOfYear(date) {
196
+ if (!isValidDate(date)) throw new InvalidDateError(date);
197
+ return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);
198
+ }
199
+ function endOfYear(date) {
200
+ if (!isValidDate(date)) throw new InvalidDateError(date);
201
+ return new Date(date.getFullYear(), 12, 0, 23, 59, 59, 999);
202
+ }
203
+ function isWeekend(date) {
204
+ if (!isValidDate(date)) throw new InvalidDateError(date);
205
+ const day = date.getDay();
206
+ return day === 0 || day === 6;
207
+ }
208
+ function isLeapYear(year) {
209
+ return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
210
+ }
211
+ function isBefore(date1, date2) {
212
+ if (!isValidDate(date1) || !isValidDate(date2)) {
213
+ throw new InvalidDateError("Invalid date provided to isBefore");
214
+ }
215
+ return date1.getTime() < date2.getTime();
216
+ }
217
+ function isAfter(date1, date2) {
218
+ if (!isValidDate(date1) || !isValidDate(date2)) {
219
+ throw new InvalidDateError("Invalid date provided to isAfter");
220
+ }
221
+ return date1.getTime() > date2.getTime();
222
+ }
223
+ function isBetween(date, start, end) {
224
+ if (!isValidDate(date) || !isValidDate(start) || !isValidDate(end)) {
225
+ throw new InvalidDateError("Invalid date provided to isBetween");
226
+ }
227
+ return date.getTime() >= start.getTime() && date.getTime() <= end.getTime();
228
+ }
229
+ function isBusinessDay(date) {
230
+ return isValidDate(date) && !isWeekend(date);
231
+ }
232
+ function addBusinessDays(date, days) {
233
+ if (!isValidDate(date)) throw new InvalidDateError(date);
234
+ const result = new Date(date.getTime());
235
+ let remaining = Math.abs(days);
236
+ const step = days >= 0 ? 1 : -1;
237
+ while (remaining > 0) {
238
+ result.setDate(result.getDate() + step);
239
+ const day = result.getDay();
240
+ if (day !== 0 && day !== 6) {
241
+ remaining--;
242
+ }
243
+ }
244
+ return result;
245
+ }
246
+ function calculateAge(birthDate) {
247
+ if (!isValidDate(birthDate)) throw new InvalidDateError(birthDate);
248
+ const today = /* @__PURE__ */ new Date();
249
+ let age = today.getFullYear() - birthDate.getFullYear();
250
+ const monthDiff = today.getMonth() - birthDate.getMonth();
251
+ if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
252
+ age--;
253
+ }
254
+ return age;
255
+ }
256
+ var LOCALE_LABELS = {
257
+ id: {
258
+ years: { single: "tahun", plural: "tahun" },
259
+ months: { single: "bulan", plural: "bulan" },
260
+ weeks: { single: "minggu", plural: "minggu" },
261
+ days: { single: "hari", plural: "hari" },
262
+ hours: { single: "jam", plural: "jam" },
263
+ minutes: { single: "menit", plural: "menit" },
264
+ seconds: { single: "detik", plural: "detik" }
265
+ },
266
+ en: {
267
+ years: { single: "year", plural: "years" },
268
+ months: { single: "month", plural: "months" },
269
+ weeks: { single: "week", plural: "weeks" },
270
+ days: { single: "day", plural: "days" },
271
+ hours: { single: "hour", plural: "hours" },
272
+ minutes: { single: "minute", plural: "minutes" },
273
+ seconds: { single: "second", plural: "seconds" }
274
+ }
275
+ };
276
+ function getSuffix(diffMs, kind, locale) {
277
+ if (diffMs < 0) {
278
+ return locale === "en" ? "ago" : "yang lalu";
279
+ }
280
+ if (kind === "remaining") {
281
+ return locale === "en" ? "remaining" : "lagi";
282
+ }
283
+ return locale === "en" ? "ago" : "yang lalu";
284
+ }
285
+ function formatRelativeTime(absDiffMs, suffix, locale) {
286
+ const labels = LOCALE_LABELS[locale] ?? LOCALE_LABELS.id;
287
+ const seconds = Math.floor(absDiffMs / 1e3);
288
+ const minutes = Math.floor(seconds / 60);
289
+ const hours = Math.floor(minutes / 60);
290
+ const days = Math.floor(hours / 24);
291
+ const weeks = Math.floor(days / 7);
292
+ const months = Math.floor(days / 30.4375);
293
+ const years = Math.floor(days / 365.25);
294
+ let count;
295
+ let unit;
296
+ if (years >= 1) {
297
+ count = years;
298
+ unit = "years";
299
+ } else if (months >= 1) {
300
+ count = months;
301
+ unit = "months";
302
+ } else if (weeks >= 1) {
303
+ count = weeks;
304
+ unit = "weeks";
305
+ } else if (days >= 1) {
306
+ count = days;
307
+ unit = "days";
308
+ } else if (hours >= 1) {
309
+ count = hours;
310
+ unit = "hours";
311
+ } else if (minutes >= 1) {
312
+ count = minutes;
313
+ unit = "minutes";
314
+ } else {
315
+ count = Math.max(1, seconds);
316
+ unit = "seconds";
317
+ }
318
+ const label = count === 1 ? labels[unit].single : labels[unit].plural;
319
+ return `${count} ${label} ${suffix}`;
320
+ }
321
+ function timeAgo(date, options) {
322
+ const diff = Date.now() - date.getTime();
323
+ const locale = options?.locale ?? "id";
324
+ const suffix = getSuffix(diff, "ago", locale);
325
+ return formatRelativeTime(Math.abs(diff), suffix, locale);
326
+ }
327
+ function timeRemaining(target, options) {
328
+ const diff = target.getTime() - Date.now();
329
+ const locale = options?.locale ?? "id";
330
+ const suffix = getSuffix(diff, "remaining", locale);
331
+ return formatRelativeTime(Math.abs(diff), suffix, locale);
332
+ }
333
+ function formatDuration(duration, options) {
334
+ const locale = options?.locale ?? "id";
335
+ const labels = LOCALE_LABELS[locale] ?? LOCALE_LABELS.id;
336
+ const parts = [];
337
+ const entries = [
338
+ ["years", duration.years],
339
+ ["months", duration.months],
340
+ ["days", duration.days],
341
+ ["hours", duration.hours],
342
+ ["minutes", duration.minutes],
343
+ ["seconds", duration.seconds]
344
+ ];
345
+ for (const [key, value] of entries) {
346
+ if (value > 0) {
347
+ const label = value === 1 ? labels[key].single : labels[key].plural;
348
+ parts.push(`${value} ${label}`);
349
+ }
350
+ }
351
+ if (parts.length === 0) {
352
+ const label = labels.seconds.plural;
353
+ return `0 ${label}`;
354
+ }
355
+ return parts.join(" ");
356
+ }
357
+ var TIMEZONE_WIB = 7;
358
+ var TIMEZONE_WITA = 8;
359
+ var TIMEZONE_WIT = 9;
360
+ function toTimezone(date, offsetHours) {
361
+ if (!isValidDate(date)) throw new InvalidDateError(date);
362
+ const utcMs = date.getTime() + date.getTimezoneOffset() * 6e4;
363
+ return new Date(utcMs + offsetHours * 36e5);
364
+ }
365
+ function formatInTimezone(date, format, offsetHours) {
366
+ return formatDate(toTimezone(date, offsetHours), format);
367
+ }
368
+ function isToday(date) {
369
+ if (!isValidDate(date)) throw new InvalidDateError(date);
370
+ const now = /* @__PURE__ */ new Date();
371
+ return date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
372
+ }
373
+ function isYesterday(date) {
374
+ if (!isValidDate(date)) throw new InvalidDateError(date);
375
+ const yesterday = /* @__PURE__ */ new Date();
376
+ yesterday.setDate(yesterday.getDate() - 1);
377
+ return date.getFullYear() === yesterday.getFullYear() && date.getMonth() === yesterday.getMonth() && date.getDate() === yesterday.getDate();
378
+ }
379
+ function isTomorrow(date) {
380
+ if (!isValidDate(date)) throw new InvalidDateError(date);
381
+ const tomorrow = /* @__PURE__ */ new Date();
382
+ tomorrow.setDate(tomorrow.getDate() + 1);
383
+ return date.getFullYear() === tomorrow.getFullYear() && date.getMonth() === tomorrow.getMonth() && date.getDate() === tomorrow.getDate();
384
+ }
385
+ function isPast(date) {
386
+ if (!isValidDate(date)) throw new InvalidDateError(date);
387
+ return date.getTime() < Date.now();
388
+ }
389
+ function isFuture(date) {
390
+ if (!isValidDate(date)) throw new InvalidDateError(date);
391
+ return date.getTime() > Date.now();
392
+ }
393
+ function isSameDay(date1, date2) {
394
+ if (!isValidDate(date1) || !isValidDate(date2)) {
395
+ throw new InvalidDateError("Invalid date provided to isSameDay");
396
+ }
397
+ return date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate();
398
+ }
399
+ function daysInMonth(date) {
400
+ if (!isValidDate(date)) throw new InvalidDateError(date);
401
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
402
+ }
403
+ function dayOfYear(date) {
404
+ if (!isValidDate(date)) throw new InvalidDateError(date);
405
+ const start = new Date(date.getFullYear(), 0, 0);
406
+ return Math.floor((date.getTime() - start.getTime()) / MS_IN_DAY);
407
+ }
408
+ function weekOfYear(date) {
409
+ if (!isValidDate(date)) throw new InvalidDateError(date);
410
+ const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
411
+ const dayNum = d.getUTCDay() || 7;
412
+ d.setUTCDate(d.getUTCDate() + 4 - dayNum);
413
+ const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
414
+ const weekNum = Math.ceil(((d.getTime() - yearStart.getTime()) / 864e5 + 1) / 7);
415
+ return weekNum;
416
+ }
417
+ function quarter(date) {
418
+ if (!isValidDate(date)) throw new InvalidDateError(date);
419
+ return Math.floor(date.getMonth() / 3) + 1;
420
+ }
421
+ function maxDate(dates) {
422
+ if (dates.length === 0) throw new Error("maxDate requires at least one date");
423
+ const ms = Math.max(...dates.map((d) => {
424
+ if (!isValidDate(d)) throw new InvalidDateError(d);
425
+ return d.getTime();
426
+ }));
427
+ return new Date(ms);
428
+ }
429
+ function minDate(dates) {
430
+ if (dates.length === 0) throw new Error("minDate requires at least one date");
431
+ const ms = Math.min(...dates.map((d) => {
432
+ if (!isValidDate(d)) throw new InvalidDateError(d);
433
+ return d.getTime();
434
+ }));
435
+ return new Date(ms);
436
+ }
437
+ function getNextWeekday(date, targetDay) {
438
+ if (!isValidDate(date)) throw new InvalidDateError(date);
439
+ const result = new Date(date);
440
+ const currentDay = result.getDay();
441
+ let diff = targetDay - currentDay;
442
+ if (diff <= 0) diff += 7;
443
+ result.setDate(result.getDate() + diff);
444
+ return result;
445
+ }
446
+ function getLastWeekday(date, targetDay) {
447
+ if (!isValidDate(date)) throw new InvalidDateError(date);
448
+ const result = new Date(date);
449
+ const currentDay = result.getDay();
450
+ let diff = currentDay - targetDay;
451
+ if (diff <= 0) diff += 7;
452
+ result.setDate(result.getDate() - diff);
453
+ return result;
454
+ }
455
+ function nextMonday(date) {
456
+ return getNextWeekday(date, 1);
457
+ }
458
+ function nextTuesday(date) {
459
+ return getNextWeekday(date, 2);
460
+ }
461
+ function nextWednesday(date) {
462
+ return getNextWeekday(date, 3);
463
+ }
464
+ function nextThursday(date) {
465
+ return getNextWeekday(date, 4);
466
+ }
467
+ function nextFriday(date) {
468
+ return getNextWeekday(date, 5);
469
+ }
470
+ function nextSaturday(date) {
471
+ return getNextWeekday(date, 6);
472
+ }
473
+ function nextSunday(date) {
474
+ return getNextWeekday(date, 0);
475
+ }
476
+ function lastMonday(date) {
477
+ return getLastWeekday(date, 1);
478
+ }
479
+ function lastTuesday(date) {
480
+ return getLastWeekday(date, 2);
481
+ }
482
+ function lastWednesday(date) {
483
+ return getLastWeekday(date, 3);
484
+ }
485
+ function lastThursday(date) {
486
+ return getLastWeekday(date, 4);
487
+ }
488
+ function lastFriday(date) {
489
+ return getLastWeekday(date, 5);
490
+ }
491
+ function lastSaturday(date) {
492
+ return getLastWeekday(date, 6);
493
+ }
494
+ function lastSunday(date) {
495
+ return getLastWeekday(date, 0);
496
+ }
497
+ function parseDuration(input) {
498
+ const regex = /(\d+)\s*([wdhms])/g;
499
+ let ms = 0;
500
+ let match;
501
+ while ((match = regex.exec(input)) !== null) {
502
+ const val = parseInt(match[1], 10);
503
+ switch (match[2]) {
504
+ case "w":
505
+ ms += val * 7 * MS_IN_DAY;
506
+ break;
507
+ case "d":
508
+ ms += val * MS_IN_DAY;
509
+ break;
510
+ case "h":
511
+ ms += val * MS_IN_HOUR;
512
+ break;
513
+ case "m":
514
+ ms += val * MS_IN_MINUTE;
515
+ break;
516
+ case "s":
517
+ ms += val * MS_IN_SECOND;
518
+ break;
519
+ }
520
+ }
521
+ return ms;
522
+ }
523
+ var INDONESIAN_FIXED_HOLIDAYS = [
524
+ { name: "New Year", month: 0, day: 1 },
525
+ { name: "Labor Day", month: 4, day: 1 },
526
+ { name: "Pancasila Day", month: 5, day: 1 },
527
+ { name: "Independence Day", month: 7, day: 17 },
528
+ { name: "National Awakening Day", month: 4, day: 20 },
529
+ { name: "National Heroes Day", month: 10, day: 10 },
530
+ { name: "Christmas", month: 11, day: 25 }
531
+ ];
532
+ function computeEaster(year) {
533
+ const a = year % 19;
534
+ const b = Math.floor(year / 100);
535
+ const c = year % 100;
536
+ const d = Math.floor(b / 4);
537
+ const e = b % 4;
538
+ const f = Math.floor((b + 8) / 25);
539
+ const g = Math.floor((b - f + 1) / 3);
540
+ const h = (19 * a + b - d - g + 15) % 30;
541
+ const i = Math.floor(c / 4);
542
+ const k = c % 4;
543
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
544
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
545
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
546
+ const day = (h + l - 7 * m + 114) % 31 + 1;
547
+ return new Date(year, month - 1, day);
548
+ }
549
+ var CHINESE_NEW_YEAR = {
550
+ 2024: { month: 1, day: 10 },
551
+ 2025: { month: 0, day: 29 },
552
+ 2026: { month: 1, day: 17 },
553
+ 2027: { month: 1, day: 6 },
554
+ 2028: { month: 0, day: 26 },
555
+ 2029: { month: 1, day: 13 },
556
+ 2030: { month: 2, day: 3 }
557
+ };
558
+ var NYEPI = {
559
+ 2024: { month: 2, day: 11 },
560
+ 2025: { month: 2, day: 29 },
561
+ 2026: { month: 2, day: 19 },
562
+ 2027: { month: 2, day: 7 },
563
+ 2028: { month: 2, day: 26 },
564
+ 2029: { month: 2, day: 15 },
565
+ 2030: { month: 2, day: 5 }
566
+ };
567
+ var VESAK = {
568
+ 2024: { month: 4, day: 23 },
569
+ 2025: { month: 4, day: 12 },
570
+ 2026: { month: 4, day: 31 },
571
+ 2027: { month: 4, day: 20 },
572
+ 2028: { month: 4, day: 9 },
573
+ 2029: { month: 4, day: 28 },
574
+ 2030: { month: 4, day: 18 }
575
+ };
576
+ var EID_AL_FITR = {
577
+ 2024: [{ month: 3, day: 10 }, { month: 3, day: 11 }],
578
+ 2025: [{ month: 2, day: 31 }, { month: 3, day: 1 }],
579
+ 2026: [{ month: 2, day: 21 }, { month: 2, day: 22 }],
580
+ 2027: [{ month: 2, day: 10 }, { month: 2, day: 11 }],
581
+ 2028: [{ month: 2, day: 28 }, { month: 2, day: 29 }],
582
+ 2029: [{ month: 2, day: 17 }, { month: 2, day: 18 }],
583
+ 2030: [{ month: 2, day: 7 }, { month: 2, day: 8 }]
584
+ };
585
+ var EID_AL_ADHA = {
586
+ 2024: { month: 5, day: 17 },
587
+ 2025: { month: 5, day: 7 },
588
+ 2026: { month: 4, day: 27 },
589
+ 2027: { month: 4, day: 17 },
590
+ 2028: { month: 5, day: 5 },
591
+ 2029: { month: 4, day: 25 },
592
+ 2030: { month: 4, day: 15 }
593
+ };
594
+ var ISLAMIC_NEW_YEAR = {
595
+ 2024: { month: 6, day: 7 },
596
+ 2025: { month: 5, day: 27 },
597
+ 2026: { month: 5, day: 16 },
598
+ 2027: { month: 5, day: 6 },
599
+ 2028: { month: 6, day: 24 },
600
+ 2029: { month: 6, day: 13 },
601
+ 2030: { month: 6, day: 3 }
602
+ };
603
+ var PROPHETS_BIRTHDAY = {
604
+ 2024: { month: 8, day: 16 },
605
+ 2025: { month: 8, day: 5 },
606
+ 2026: { month: 7, day: 26 },
607
+ 2027: { month: 7, day: 16 },
608
+ 2028: { month: 8, day: 3 },
609
+ 2029: { month: 7, day: 23 },
610
+ 2030: { month: 7, day: 13 }
611
+ };
612
+ var ISRA_MIRAJ = {
613
+ 2024: { month: 1, day: 8 },
614
+ 2025: { month: 0, day: 28 },
615
+ 2026: { month: 0, day: 17 },
616
+ 2027: { month: 0, day: 6 },
617
+ 2028: { month: 0, day: 26 },
618
+ 2029: { month: 1, day: 14 },
619
+ 2030: { month: 1, day: 3 }
620
+ };
621
+ function addHolidayEntry(entries, name, month, day) {
622
+ entries.push({ name, month, day });
623
+ }
624
+ function getIndonesianHolidaysForYear(year) {
625
+ const holidays = [...INDONESIAN_FIXED_HOLIDAYS];
626
+ const easter = computeEaster(year);
627
+ addHolidayEntry(holidays, "Good Friday", easter.getMonth(), easter.getDate() - 2);
628
+ addHolidayEntry(holidays, "Easter", easter.getMonth(), easter.getDate());
629
+ const ascension = new Date(easter);
630
+ ascension.setDate(ascension.getDate() + 39);
631
+ addHolidayEntry(holidays, "Ascension of Jesus Christ", ascension.getMonth(), ascension.getDate());
632
+ const cny = CHINESE_NEW_YEAR[year];
633
+ if (cny) addHolidayEntry(holidays, "Chinese New Year", cny.month, cny.day);
634
+ const nyepi = NYEPI[year];
635
+ if (nyepi) addHolidayEntry(holidays, "Nyepi (Day of Silence)", nyepi.month, nyepi.day);
636
+ const vesak = VESAK[year];
637
+ if (vesak) addHolidayEntry(holidays, "Vesak (Buddha's Birthday)", vesak.month, vesak.day);
638
+ const eidDays = EID_AL_FITR[year];
639
+ if (eidDays) {
640
+ eidDays.forEach((entry, idx) => {
641
+ addHolidayEntry(holidays, idx === 0 ? "Eid al-Fitr" : "Eid al-Fitr (Day 2)", entry.month, entry.day);
642
+ });
643
+ }
644
+ const eidAdha = EID_AL_ADHA[year];
645
+ if (eidAdha) addHolidayEntry(holidays, "Eid al-Adha", eidAdha.month, eidAdha.day);
646
+ const islNewYear = ISLAMIC_NEW_YEAR[year];
647
+ if (islNewYear) addHolidayEntry(holidays, "Islamic New Year", islNewYear.month, islNewYear.day);
648
+ const prophetBday = PROPHETS_BIRTHDAY[year];
649
+ if (prophetBday) addHolidayEntry(holidays, "Prophet Muhammad's Birthday", prophetBday.month, prophetBday.day);
650
+ const isra = ISRA_MIRAJ[year];
651
+ if (isra) addHolidayEntry(holidays, "Isra' Mi'raj (Ascension of Prophet Muhammad)", isra.month, isra.day);
652
+ return holidays;
653
+ }
654
+ function isHolidayIndonesia(date) {
655
+ if (!isValidDate(date)) throw new InvalidDateError(date);
656
+ const year = date.getFullYear();
657
+ const holidays = getIndonesianHolidaysForYear(year);
658
+ for (const h of holidays) {
659
+ if (h.month === date.getMonth() && h.day === date.getDate()) {
660
+ return true;
661
+ }
662
+ }
663
+ return false;
664
+ }
665
+ function getIndonesianHolidayNames(date) {
666
+ if (!isValidDate(date)) throw new InvalidDateError(date);
667
+ const year = date.getFullYear();
668
+ const holidays = getIndonesianHolidaysForYear(year);
669
+ const names = [];
670
+ for (const h of holidays) {
671
+ if (h.month === date.getMonth() && h.day === date.getDate()) {
672
+ names.push(h.name);
673
+ }
674
+ }
675
+ return names;
676
+ }
677
+ export {
678
+ InvalidDateError,
679
+ TIMEZONE_WIB,
680
+ TIMEZONE_WIT,
681
+ TIMEZONE_WITA,
682
+ addBusinessDays,
683
+ addDays,
684
+ addMonths,
685
+ addYears,
686
+ calculateAge,
687
+ dateDiff,
688
+ dayOfYear,
689
+ daysInMonth,
690
+ endOfDay,
691
+ endOfMonth,
692
+ endOfYear,
693
+ formatDate,
694
+ formatDuration,
695
+ formatInTimezone,
696
+ getIndonesianHolidayNames,
697
+ isAfter,
698
+ isBefore,
699
+ isBetween,
700
+ isBusinessDay,
701
+ isFuture,
702
+ isHolidayIndonesia,
703
+ isLeapYear,
704
+ isPast,
705
+ isSameDay,
706
+ isToday,
707
+ isTomorrow,
708
+ isWeekend,
709
+ isYesterday,
710
+ lastFriday,
711
+ lastMonday,
712
+ lastSaturday,
713
+ lastSunday,
714
+ lastThursday,
715
+ lastTuesday,
716
+ lastWednesday,
717
+ maxDate,
718
+ minDate,
719
+ nextFriday,
720
+ nextMonday,
721
+ nextSaturday,
722
+ nextSunday,
723
+ nextThursday,
724
+ nextTuesday,
725
+ nextWednesday,
726
+ parseDate,
727
+ parseDuration,
728
+ quarter,
729
+ startOfDay,
730
+ startOfMonth,
731
+ startOfYear,
732
+ timeAgo,
733
+ timeRemaining,
734
+ toTimezone,
735
+ weekOfYear
736
+ };
737
+ //# sourceMappingURL=index.js.map