chronajs 0.0.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.
Files changed (57) hide show
  1. package/esm/core/dtf.d.ts +2 -0
  2. package/esm/core/dtf.d.ts.map +1 -0
  3. package/esm/core/dtf.js +20 -0
  4. package/esm/lib/add.d.ts +24 -0
  5. package/esm/lib/add.d.ts.map +1 -0
  6. package/esm/lib/add.js +47 -0
  7. package/esm/lib/end-of.d.ts +2 -0
  8. package/esm/lib/end-of.d.ts.map +1 -0
  9. package/esm/lib/end-of.js +35 -0
  10. package/esm/lib/format.d.ts +7 -0
  11. package/esm/lib/format.d.ts.map +1 -0
  12. package/esm/lib/format.js +170 -0
  13. package/esm/lib/months.d.ts +2 -0
  14. package/esm/lib/months.d.ts.map +1 -0
  15. package/esm/lib/months.js +14 -0
  16. package/esm/lib/start-of.d.ts +2 -0
  17. package/esm/lib/start-of.d.ts.map +1 -0
  18. package/esm/lib/start-of.js +32 -0
  19. package/esm/lib/sub.d.ts +23 -0
  20. package/esm/lib/sub.d.ts.map +1 -0
  21. package/esm/lib/sub.js +31 -0
  22. package/esm/lib/weekdays.d.ts +2 -0
  23. package/esm/lib/weekdays.d.ts.map +1 -0
  24. package/esm/lib/weekdays.js +14 -0
  25. package/esm/mod.d.ts +8 -0
  26. package/esm/mod.d.ts.map +1 -0
  27. package/esm/mod.js +7 -0
  28. package/esm/package.json +3 -0
  29. package/package.json +26 -0
  30. package/script/core/dtf.d.ts +2 -0
  31. package/script/core/dtf.d.ts.map +1 -0
  32. package/script/core/dtf.js +23 -0
  33. package/script/lib/add.d.ts +24 -0
  34. package/script/lib/add.d.ts.map +1 -0
  35. package/script/lib/add.js +50 -0
  36. package/script/lib/end-of.d.ts +2 -0
  37. package/script/lib/end-of.d.ts.map +1 -0
  38. package/script/lib/end-of.js +38 -0
  39. package/script/lib/format.d.ts +7 -0
  40. package/script/lib/format.d.ts.map +1 -0
  41. package/script/lib/format.js +173 -0
  42. package/script/lib/months.d.ts +2 -0
  43. package/script/lib/months.d.ts.map +1 -0
  44. package/script/lib/months.js +17 -0
  45. package/script/lib/start-of.d.ts +2 -0
  46. package/script/lib/start-of.d.ts.map +1 -0
  47. package/script/lib/start-of.js +35 -0
  48. package/script/lib/sub.d.ts +23 -0
  49. package/script/lib/sub.d.ts.map +1 -0
  50. package/script/lib/sub.js +34 -0
  51. package/script/lib/weekdays.d.ts +2 -0
  52. package/script/lib/weekdays.d.ts.map +1 -0
  53. package/script/lib/weekdays.js +17 -0
  54. package/script/mod.d.ts +8 -0
  55. package/script/mod.d.ts.map +1 -0
  56. package/script/mod.js +23 -0
  57. package/script/package.json +3 -0
@@ -0,0 +1,2 @@
1
+ export declare function getDTF(locale: string, tz: string): Intl.DateTimeFormat;
2
+ //# sourceMappingURL=dtf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dtf.d.ts","sourceRoot":"","sources":["../../src/core/dtf.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,uBAiBhD"}
@@ -0,0 +1,20 @@
1
+ const dtfCache = new Map();
2
+ export function getDTF(locale, tz) {
3
+ const key = `${locale}|${tz}`;
4
+ let dtf = dtfCache.get(key);
5
+ if (!dtf) {
6
+ dtf = new Intl.DateTimeFormat(locale, {
7
+ year: 'numeric',
8
+ month: '2-digit',
9
+ day: '2-digit',
10
+ hour: '2-digit',
11
+ minute: '2-digit',
12
+ second: '2-digit',
13
+ hour12: false,
14
+ timeZone: tz,
15
+ });
16
+ dtfCache.set(key, dtf);
17
+ }
18
+ return dtf;
19
+ }
20
+ ;
@@ -0,0 +1,24 @@
1
+ type AddOptions = {
2
+ years?: number;
3
+ months?: number;
4
+ weeks?: number;
5
+ days?: number;
6
+ hours?: number;
7
+ minutes?: number;
8
+ seconds?: number;
9
+ milliseconds?: number;
10
+ };
11
+ /**
12
+ * Adds specified time units to the given date.
13
+ *
14
+ * @param date - The original date.
15
+ * @param opt - The time units to add.
16
+ * @returns A new Date object with the specified time units added.
17
+ * @example
18
+ * const date = new Date('2024-01-31T12:00:00Z');
19
+ * const newDate = add(date, { years: 1, months: 2, days: 3 });
20
+ * console.log(newDate.toISOString()); // '2025-04-03T12:00:00.000Z'
21
+ */
22
+ export declare function add(date: Date, opt: AddOptions): Date;
23
+ export {};
24
+ //# sourceMappingURL=add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/lib/add.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AAEH,wBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA8CrD"}
package/esm/lib/add.js ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Adds specified time units to the given date.
3
+ *
4
+ * @param date - The original date.
5
+ * @param opt - The time units to add.
6
+ * @returns A new Date object with the specified time units added.
7
+ * @example
8
+ * const date = new Date('2024-01-31T12:00:00Z');
9
+ * const newDate = add(date, { years: 1, months: 2, days: 3 });
10
+ * console.log(newDate.toISOString()); // '2025-04-03T12:00:00.000Z'
11
+ */
12
+ export function add(date, opt) {
13
+ let d = new Date(date.getTime());
14
+ // ===== calendar-based (UTC-safe) =====
15
+ if (opt.years || opt.months) {
16
+ const years = opt.years ?? 0;
17
+ const months = opt.months ?? 0;
18
+ const year = d.getUTCFullYear();
19
+ const month = d.getUTCMonth(); // 0-based
20
+ const day = d.getUTCDate();
21
+ // target year/month (allow overflow, normalize manually)
22
+ let targetMonth = month + months;
23
+ const targetYear = year + years + Math.floor(targetMonth / 12);
24
+ targetMonth = ((targetMonth % 12) + 12) % 12;
25
+ // last valid day of target month
26
+ const lastDayOfTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();
27
+ const safeDay = Math.min(day, lastDayOfTargetMonth);
28
+ d = new Date(Date.UTC(targetYear, targetMonth, safeDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()));
29
+ }
30
+ // ===== time-based =====
31
+ let delta = 0;
32
+ if (opt.milliseconds)
33
+ delta += opt.milliseconds;
34
+ if (opt.seconds)
35
+ delta += opt.seconds * 1_000;
36
+ if (opt.minutes)
37
+ delta += opt.minutes * 60_000;
38
+ if (opt.hours)
39
+ delta += opt.hours * 3_600_000;
40
+ if (opt.days)
41
+ delta += opt.days * 86_400_000;
42
+ if (opt.weeks)
43
+ delta += opt.weeks * 604_800_000;
44
+ if (delta)
45
+ d = new Date(d.getTime() + delta);
46
+ return d;
47
+ }
@@ -0,0 +1,2 @@
1
+ export declare function endOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date;
2
+ //# sourceMappingURL=end-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"end-of.d.ts","sourceRoot":"","sources":["../../src/lib/end-of.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAoCrG"}
@@ -0,0 +1,35 @@
1
+ export function endOf(date, unit) {
2
+ const time = new Date(date.getTime());
3
+ switch (unit) {
4
+ case 'year': {
5
+ time.setUTCMonth(11, 31);
6
+ time.setUTCHours(23, 59, 59, 999);
7
+ break;
8
+ }
9
+ case 'month': {
10
+ const year = time.getUTCFullYear();
11
+ const month = time.getUTCMonth();
12
+ const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
13
+ time.setUTCDate(lastDay);
14
+ time.setUTCHours(23, 59, 59, 999);
15
+ break;
16
+ }
17
+ case 'day': {
18
+ time.setUTCHours(23, 59, 59, 999);
19
+ break;
20
+ }
21
+ case 'hour': {
22
+ time.setUTCMinutes(59, 59, 999);
23
+ break;
24
+ }
25
+ case 'minute': {
26
+ time.setUTCSeconds(59, 999);
27
+ break;
28
+ }
29
+ case 'second': {
30
+ time.setUTCMilliseconds(999);
31
+ break;
32
+ }
33
+ }
34
+ return time;
35
+ }
@@ -0,0 +1,7 @@
1
+ type FormatOptions = {
2
+ tz?: string;
3
+ locale?: string;
4
+ };
5
+ export declare function format(date: Date, fmt: string, options?: FormatOptions): string;
6
+ export {};
7
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/lib/format.ts"],"names":[],"mappings":"AAGA,KAAK,aAAa,GAAG;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAkLF,wBAAgB,MAAM,CACpB,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAqBR"}
@@ -0,0 +1,170 @@
1
+ import { getDTF } from "../core/dtf.js";
2
+ import { months } from "./months.js";
3
+ // Pre-compute pad functions to avoid repeated padStart calls
4
+ const pad2 = (n) => n < 10 ? '0' + n : String(n);
5
+ const tokenMap = {
6
+ YYYY: p => String(p.year),
7
+ YY: p => String(p.year).slice(-2),
8
+ M: p => String(p.month),
9
+ MM: p => pad2(p.month),
10
+ MMM: (p, l) => months(l, 'short')[p.month - 1],
11
+ MMMM: (p, l) => months(l, 'long')[p.month - 1],
12
+ D: p => String(p.day),
13
+ DD: p => pad2(p.day),
14
+ H: p => String(p.hour),
15
+ HH: p => pad2(p.hour),
16
+ m: p => String(p.minute),
17
+ mm: p => pad2(p.minute),
18
+ s: p => String(p.second),
19
+ ss: p => pad2(p.second),
20
+ };
21
+ const tokenRegex = /YYYY|MMMM|MMM|YY|MM|M|DD|D|HH|H|mm|m|ss|s/g;
22
+ const formatCache = new Map();
23
+ function compileFormat(fmt) {
24
+ const cached = formatCache.get(fmt);
25
+ if (cached)
26
+ return cached;
27
+ const hasLiterals = fmt.includes('[');
28
+ const parts = [];
29
+ if (!hasLiterals) {
30
+ // Fast path: no literals, just parse tokens
31
+ let lastIndex = 0;
32
+ tokenRegex.lastIndex = 0;
33
+ let match;
34
+ while ((match = tokenRegex.exec(fmt)) !== null) {
35
+ if (match.index > lastIndex) {
36
+ parts.push({ type: 'literal', value: fmt.slice(lastIndex, match.index) });
37
+ }
38
+ parts.push({ type: 'token', value: match[0] });
39
+ lastIndex = match.index + match[0].length;
40
+ }
41
+ if (lastIndex < fmt.length) {
42
+ parts.push({ type: 'literal', value: fmt.slice(lastIndex) });
43
+ }
44
+ }
45
+ else {
46
+ // Slow path: handle escaped literals
47
+ let i = 0;
48
+ let currentLiteral = '';
49
+ let inBracket = false;
50
+ while (i < fmt.length) {
51
+ if (fmt[i] === '[' && !inBracket) {
52
+ if (currentLiteral) {
53
+ // Process current literal for tokens
54
+ let lastIndex = 0;
55
+ tokenRegex.lastIndex = 0;
56
+ let match;
57
+ while ((match = tokenRegex.exec(currentLiteral)) !== null) {
58
+ if (match.index > lastIndex) {
59
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex, match.index) });
60
+ }
61
+ parts.push({ type: 'token', value: match[0] });
62
+ lastIndex = match.index + match[0].length;
63
+ }
64
+ if (lastIndex < currentLiteral.length) {
65
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex) });
66
+ }
67
+ currentLiteral = '';
68
+ }
69
+ inBracket = true;
70
+ i++;
71
+ }
72
+ else if (fmt[i] === ']' && inBracket) {
73
+ // Escaped literal content - add as-is
74
+ if (currentLiteral) {
75
+ parts.push({ type: 'literal', value: currentLiteral });
76
+ currentLiteral = '';
77
+ }
78
+ inBracket = false;
79
+ i++;
80
+ }
81
+ else {
82
+ currentLiteral += fmt[i];
83
+ i++;
84
+ }
85
+ }
86
+ if (currentLiteral) {
87
+ let lastIndex = 0;
88
+ tokenRegex.lastIndex = 0;
89
+ let match;
90
+ while ((match = tokenRegex.exec(currentLiteral)) !== null) {
91
+ if (match.index > lastIndex) {
92
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex, match.index) });
93
+ }
94
+ parts.push({ type: 'token', value: match[0] });
95
+ lastIndex = match.index + match[0].length;
96
+ }
97
+ if (lastIndex < currentLiteral.length) {
98
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex) });
99
+ }
100
+ }
101
+ }
102
+ const compiled = { hasLiterals, parts };
103
+ formatCache.set(fmt, compiled);
104
+ return compiled;
105
+ }
106
+ // Fast UTC date parts extraction
107
+ function getUTCParts(date) {
108
+ return {
109
+ year: date.getUTCFullYear(),
110
+ month: date.getUTCMonth() + 1,
111
+ day: date.getUTCDate(),
112
+ hour: date.getUTCHours(),
113
+ minute: date.getUTCMinutes(),
114
+ second: date.getUTCSeconds(),
115
+ };
116
+ }
117
+ // Fallback for non-UTC timezones
118
+ function getPartsWithTZ(date, locale, tz) {
119
+ const partsRaw = getDTF(locale, tz).formatToParts(date);
120
+ const p = {
121
+ year: 0,
122
+ month: 0,
123
+ day: 0,
124
+ hour: 0,
125
+ minute: 0,
126
+ second: 0,
127
+ };
128
+ for (const part of partsRaw) {
129
+ switch (part.type) {
130
+ case "year":
131
+ p.year = +part.value;
132
+ break;
133
+ case "month":
134
+ p.month = +part.value;
135
+ break;
136
+ case "day":
137
+ p.day = +part.value;
138
+ break;
139
+ case "hour":
140
+ p.hour = +part.value;
141
+ break;
142
+ case "minute":
143
+ p.minute = +part.value;
144
+ break;
145
+ case "second":
146
+ p.second = +part.value;
147
+ break;
148
+ }
149
+ }
150
+ return p;
151
+ }
152
+ export function format(date, fmt, options = {}) {
153
+ const locale = options.locale ?? "en-US";
154
+ const tz = options.tz ?? "UTC";
155
+ // Get compiled format (cached)
156
+ const compiled = compileFormat(fmt);
157
+ // Fast path for UTC
158
+ const p = tz === "UTC" ? getUTCParts(date) : getPartsWithTZ(date, locale, tz);
159
+ // Build result string from compiled parts
160
+ let result = '';
161
+ for (const part of compiled.parts) {
162
+ if (part.type === 'literal') {
163
+ result += part.value;
164
+ }
165
+ else {
166
+ result += tokenMap[part.value](p, locale);
167
+ }
168
+ }
169
+ return result;
170
+ }
@@ -0,0 +1,2 @@
1
+ export declare function months(locale?: string, format?: "long" | "short" | "narrow"): string[];
2
+ //# sourceMappingURL=months.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"months.d.ts","sourceRoot":"","sources":["../../src/lib/months.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CACpB,MAAM,SAAU,EAChB,MAAM,GAAE,MAAM,GAAG,OAAO,GAAG,QAAiB,GAC3C,MAAM,EAAE,CAiBV"}
@@ -0,0 +1,14 @@
1
+ const monthsCache = new Map();
2
+ export function months(locale = "en-US", format = "long") {
3
+ const key = `${locale}|${format}`;
4
+ const cached = monthsCache.get(key);
5
+ if (cached)
6
+ return cached;
7
+ const fmt = new Intl.DateTimeFormat(locale, {
8
+ month: format,
9
+ timeZone: "UTC",
10
+ });
11
+ const result = Array.from({ length: 12 }, (_, i) => fmt.format(new Date(Date.UTC(2024, i, 1))));
12
+ monthsCache.set(key, result);
13
+ return result;
14
+ }
@@ -0,0 +1,2 @@
1
+ export declare function startOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date;
2
+ //# sourceMappingURL=start-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-of.d.ts","sourceRoot":"","sources":["../../src/lib/start-of.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAiCvG"}
@@ -0,0 +1,32 @@
1
+ export function startOf(date, unit) {
2
+ const time = new Date(date.getTime());
3
+ switch (unit) {
4
+ case 'year': {
5
+ time.setUTCMonth(0, 1);
6
+ time.setUTCHours(0, 0, 0, 0);
7
+ break;
8
+ }
9
+ case 'month': {
10
+ time.setUTCDate(1);
11
+ time.setUTCHours(0, 0, 0, 0);
12
+ break;
13
+ }
14
+ case 'day': {
15
+ time.setUTCHours(0, 0, 0, 0);
16
+ break;
17
+ }
18
+ case 'hour': {
19
+ time.setUTCMinutes(0, 0, 0);
20
+ break;
21
+ }
22
+ case 'minute': {
23
+ time.setUTCSeconds(0, 0);
24
+ break;
25
+ }
26
+ case 'second': {
27
+ time.setUTCMilliseconds(0);
28
+ break;
29
+ }
30
+ }
31
+ return time;
32
+ }
@@ -0,0 +1,23 @@
1
+ type SubOptions = {
2
+ years?: number;
3
+ months?: number;
4
+ weeks?: number;
5
+ days?: number;
6
+ hours?: number;
7
+ minutes?: number;
8
+ seconds?: number;
9
+ milliseconds?: number;
10
+ };
11
+ /**
12
+ *
13
+ * @param date
14
+ * @param opt - The time units to subtract.
15
+ * @returns A new Date object with the specified time units subtracted.
16
+ * @example
17
+ * const date = new Date('2024-01-31T12:00:00Z');
18
+ * const newDate = sub(date, { years: 1, months: 2, days: 3 });
19
+ * console.log(newDate.toISOString()); // '2023-11-28T12:00:00.000Z'
20
+ */
21
+ export declare function sub(date: Date, opt: SubOptions): Date;
22
+ export {};
23
+ //# sourceMappingURL=sub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sub.d.ts","sourceRoot":"","sources":["../../src/lib/sub.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AAEH,wBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAarD"}
package/esm/lib/sub.js ADDED
@@ -0,0 +1,31 @@
1
+ import { add } from "./add.js";
2
+ /**
3
+ *
4
+ * @param date
5
+ * @param opt - The time units to subtract.
6
+ * @returns A new Date object with the specified time units subtracted.
7
+ * @example
8
+ * const date = new Date('2024-01-31T12:00:00Z');
9
+ * const newDate = sub(date, { years: 1, months: 2, days: 3 });
10
+ * console.log(newDate.toISOString()); // '2023-11-28T12:00:00.000Z'
11
+ */
12
+ export function sub(date, opt) {
13
+ const out = {};
14
+ if (opt.years)
15
+ out.years = -opt.years;
16
+ if (opt.months)
17
+ out.months = -opt.months;
18
+ if (opt.weeks)
19
+ out.weeks = -opt.weeks;
20
+ if (opt.days)
21
+ out.days = -opt.days;
22
+ if (opt.hours)
23
+ out.hours = -opt.hours;
24
+ if (opt.minutes)
25
+ out.minutes = -opt.minutes;
26
+ if (opt.seconds)
27
+ out.seconds = -opt.seconds;
28
+ if (opt.milliseconds)
29
+ out.milliseconds = -opt.milliseconds;
30
+ return add(date, out);
31
+ }
@@ -0,0 +1,2 @@
1
+ export declare function weekdays(locale?: string, format?: "long" | "short" | "narrow"): string[];
2
+ //# sourceMappingURL=weekdays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weekdays.d.ts","sourceRoot":"","sources":["../../src/lib/weekdays.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CACtB,MAAM,SAAU,EAChB,MAAM,GAAE,MAAM,GAAG,OAAO,GAAG,QAAiB,GAC3C,MAAM,EAAE,CAiBV"}
@@ -0,0 +1,14 @@
1
+ const daysCache = new Map();
2
+ export function weekdays(locale = "en-US", format = "long") {
3
+ const key = `${locale}|${format}`;
4
+ const cached = daysCache.get(key);
5
+ if (cached)
6
+ return cached;
7
+ const fmt = new Intl.DateTimeFormat(locale, {
8
+ weekday: format,
9
+ timeZone: "UTC",
10
+ });
11
+ const result = Array.from({ length: 7 }, (_, i) => fmt.format(new Date(Date.UTC(2024, 0, i + 1))));
12
+ daysCache.set(key, result);
13
+ return result;
14
+ }
package/esm/mod.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from "./lib/add.js";
2
+ export * from "./lib/sub.js";
3
+ export * from "./lib/months.js";
4
+ export * from "./lib/start-of.js";
5
+ export * from "./lib/end-of.js";
6
+ export * from "./lib/format.js";
7
+ export * from "./lib/weekdays.js";
8
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
package/esm/mod.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./lib/add.js";
2
+ export * from "./lib/sub.js";
3
+ export * from "./lib/months.js";
4
+ export * from "./lib/start-of.js";
5
+ export * from "./lib/end-of.js";
6
+ export * from "./lib/format.js";
7
+ export * from "./lib/weekdays.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "chronajs",
3
+ "version": "0.0.1-0",
4
+ "description": "A date utility library made with Deno",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/username/repo.git"
8
+ },
9
+ "license": "MIT",
10
+ "bugs": {
11
+ "url": "https://github.com/username/repo/issues"
12
+ },
13
+ "main": "./script/mod.js",
14
+ "module": "./esm/mod.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./esm/mod.js",
18
+ "require": "./script/mod.js"
19
+ }
20
+ },
21
+ "scripts": {},
22
+ "devDependencies": {
23
+ "@types/node": "^20.9.0"
24
+ },
25
+ "_generatedBy": "dnt@dev"
26
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getDTF(locale: string, tz: string): Intl.DateTimeFormat;
2
+ //# sourceMappingURL=dtf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dtf.d.ts","sourceRoot":"","sources":["../../src/core/dtf.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,uBAiBhD"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDTF = getDTF;
4
+ const dtfCache = new Map();
5
+ function getDTF(locale, tz) {
6
+ const key = `${locale}|${tz}`;
7
+ let dtf = dtfCache.get(key);
8
+ if (!dtf) {
9
+ dtf = new Intl.DateTimeFormat(locale, {
10
+ year: 'numeric',
11
+ month: '2-digit',
12
+ day: '2-digit',
13
+ hour: '2-digit',
14
+ minute: '2-digit',
15
+ second: '2-digit',
16
+ hour12: false,
17
+ timeZone: tz,
18
+ });
19
+ dtfCache.set(key, dtf);
20
+ }
21
+ return dtf;
22
+ }
23
+ ;
@@ -0,0 +1,24 @@
1
+ type AddOptions = {
2
+ years?: number;
3
+ months?: number;
4
+ weeks?: number;
5
+ days?: number;
6
+ hours?: number;
7
+ minutes?: number;
8
+ seconds?: number;
9
+ milliseconds?: number;
10
+ };
11
+ /**
12
+ * Adds specified time units to the given date.
13
+ *
14
+ * @param date - The original date.
15
+ * @param opt - The time units to add.
16
+ * @returns A new Date object with the specified time units added.
17
+ * @example
18
+ * const date = new Date('2024-01-31T12:00:00Z');
19
+ * const newDate = add(date, { years: 1, months: 2, days: 3 });
20
+ * console.log(newDate.toISOString()); // '2025-04-03T12:00:00.000Z'
21
+ */
22
+ export declare function add(date: Date, opt: AddOptions): Date;
23
+ export {};
24
+ //# sourceMappingURL=add.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add.d.ts","sourceRoot":"","sources":["../../src/lib/add.ts"],"names":[],"mappings":"AAAA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;GAUG;AAEH,wBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CA8CrD"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.add = add;
4
+ /**
5
+ * Adds specified time units to the given date.
6
+ *
7
+ * @param date - The original date.
8
+ * @param opt - The time units to add.
9
+ * @returns A new Date object with the specified time units added.
10
+ * @example
11
+ * const date = new Date('2024-01-31T12:00:00Z');
12
+ * const newDate = add(date, { years: 1, months: 2, days: 3 });
13
+ * console.log(newDate.toISOString()); // '2025-04-03T12:00:00.000Z'
14
+ */
15
+ function add(date, opt) {
16
+ let d = new Date(date.getTime());
17
+ // ===== calendar-based (UTC-safe) =====
18
+ if (opt.years || opt.months) {
19
+ const years = opt.years ?? 0;
20
+ const months = opt.months ?? 0;
21
+ const year = d.getUTCFullYear();
22
+ const month = d.getUTCMonth(); // 0-based
23
+ const day = d.getUTCDate();
24
+ // target year/month (allow overflow, normalize manually)
25
+ let targetMonth = month + months;
26
+ const targetYear = year + years + Math.floor(targetMonth / 12);
27
+ targetMonth = ((targetMonth % 12) + 12) % 12;
28
+ // last valid day of target month
29
+ const lastDayOfTargetMonth = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();
30
+ const safeDay = Math.min(day, lastDayOfTargetMonth);
31
+ d = new Date(Date.UTC(targetYear, targetMonth, safeDay, d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds()));
32
+ }
33
+ // ===== time-based =====
34
+ let delta = 0;
35
+ if (opt.milliseconds)
36
+ delta += opt.milliseconds;
37
+ if (opt.seconds)
38
+ delta += opt.seconds * 1_000;
39
+ if (opt.minutes)
40
+ delta += opt.minutes * 60_000;
41
+ if (opt.hours)
42
+ delta += opt.hours * 3_600_000;
43
+ if (opt.days)
44
+ delta += opt.days * 86_400_000;
45
+ if (opt.weeks)
46
+ delta += opt.weeks * 604_800_000;
47
+ if (delta)
48
+ d = new Date(d.getTime() + delta);
49
+ return d;
50
+ }
@@ -0,0 +1,2 @@
1
+ export declare function endOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date;
2
+ //# sourceMappingURL=end-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"end-of.d.ts","sourceRoot":"","sources":["../../src/lib/end-of.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAoCrG"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.endOf = endOf;
4
+ function endOf(date, unit) {
5
+ const time = new Date(date.getTime());
6
+ switch (unit) {
7
+ case 'year': {
8
+ time.setUTCMonth(11, 31);
9
+ time.setUTCHours(23, 59, 59, 999);
10
+ break;
11
+ }
12
+ case 'month': {
13
+ const year = time.getUTCFullYear();
14
+ const month = time.getUTCMonth();
15
+ const lastDay = new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
16
+ time.setUTCDate(lastDay);
17
+ time.setUTCHours(23, 59, 59, 999);
18
+ break;
19
+ }
20
+ case 'day': {
21
+ time.setUTCHours(23, 59, 59, 999);
22
+ break;
23
+ }
24
+ case 'hour': {
25
+ time.setUTCMinutes(59, 59, 999);
26
+ break;
27
+ }
28
+ case 'minute': {
29
+ time.setUTCSeconds(59, 999);
30
+ break;
31
+ }
32
+ case 'second': {
33
+ time.setUTCMilliseconds(999);
34
+ break;
35
+ }
36
+ }
37
+ return time;
38
+ }
@@ -0,0 +1,7 @@
1
+ type FormatOptions = {
2
+ tz?: string;
3
+ locale?: string;
4
+ };
5
+ export declare function format(date: Date, fmt: string, options?: FormatOptions): string;
6
+ export {};
7
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/lib/format.ts"],"names":[],"mappings":"AAGA,KAAK,aAAa,GAAG;IACnB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAkLF,wBAAgB,MAAM,CACpB,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,aAAkB,GAC1B,MAAM,CAqBR"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.format = format;
4
+ const dtf_js_1 = require("../core/dtf.js");
5
+ const months_js_1 = require("./months.js");
6
+ // Pre-compute pad functions to avoid repeated padStart calls
7
+ const pad2 = (n) => n < 10 ? '0' + n : String(n);
8
+ const tokenMap = {
9
+ YYYY: p => String(p.year),
10
+ YY: p => String(p.year).slice(-2),
11
+ M: p => String(p.month),
12
+ MM: p => pad2(p.month),
13
+ MMM: (p, l) => (0, months_js_1.months)(l, 'short')[p.month - 1],
14
+ MMMM: (p, l) => (0, months_js_1.months)(l, 'long')[p.month - 1],
15
+ D: p => String(p.day),
16
+ DD: p => pad2(p.day),
17
+ H: p => String(p.hour),
18
+ HH: p => pad2(p.hour),
19
+ m: p => String(p.minute),
20
+ mm: p => pad2(p.minute),
21
+ s: p => String(p.second),
22
+ ss: p => pad2(p.second),
23
+ };
24
+ const tokenRegex = /YYYY|MMMM|MMM|YY|MM|M|DD|D|HH|H|mm|m|ss|s/g;
25
+ const formatCache = new Map();
26
+ function compileFormat(fmt) {
27
+ const cached = formatCache.get(fmt);
28
+ if (cached)
29
+ return cached;
30
+ const hasLiterals = fmt.includes('[');
31
+ const parts = [];
32
+ if (!hasLiterals) {
33
+ // Fast path: no literals, just parse tokens
34
+ let lastIndex = 0;
35
+ tokenRegex.lastIndex = 0;
36
+ let match;
37
+ while ((match = tokenRegex.exec(fmt)) !== null) {
38
+ if (match.index > lastIndex) {
39
+ parts.push({ type: 'literal', value: fmt.slice(lastIndex, match.index) });
40
+ }
41
+ parts.push({ type: 'token', value: match[0] });
42
+ lastIndex = match.index + match[0].length;
43
+ }
44
+ if (lastIndex < fmt.length) {
45
+ parts.push({ type: 'literal', value: fmt.slice(lastIndex) });
46
+ }
47
+ }
48
+ else {
49
+ // Slow path: handle escaped literals
50
+ let i = 0;
51
+ let currentLiteral = '';
52
+ let inBracket = false;
53
+ while (i < fmt.length) {
54
+ if (fmt[i] === '[' && !inBracket) {
55
+ if (currentLiteral) {
56
+ // Process current literal for tokens
57
+ let lastIndex = 0;
58
+ tokenRegex.lastIndex = 0;
59
+ let match;
60
+ while ((match = tokenRegex.exec(currentLiteral)) !== null) {
61
+ if (match.index > lastIndex) {
62
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex, match.index) });
63
+ }
64
+ parts.push({ type: 'token', value: match[0] });
65
+ lastIndex = match.index + match[0].length;
66
+ }
67
+ if (lastIndex < currentLiteral.length) {
68
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex) });
69
+ }
70
+ currentLiteral = '';
71
+ }
72
+ inBracket = true;
73
+ i++;
74
+ }
75
+ else if (fmt[i] === ']' && inBracket) {
76
+ // Escaped literal content - add as-is
77
+ if (currentLiteral) {
78
+ parts.push({ type: 'literal', value: currentLiteral });
79
+ currentLiteral = '';
80
+ }
81
+ inBracket = false;
82
+ i++;
83
+ }
84
+ else {
85
+ currentLiteral += fmt[i];
86
+ i++;
87
+ }
88
+ }
89
+ if (currentLiteral) {
90
+ let lastIndex = 0;
91
+ tokenRegex.lastIndex = 0;
92
+ let match;
93
+ while ((match = tokenRegex.exec(currentLiteral)) !== null) {
94
+ if (match.index > lastIndex) {
95
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex, match.index) });
96
+ }
97
+ parts.push({ type: 'token', value: match[0] });
98
+ lastIndex = match.index + match[0].length;
99
+ }
100
+ if (lastIndex < currentLiteral.length) {
101
+ parts.push({ type: 'literal', value: currentLiteral.slice(lastIndex) });
102
+ }
103
+ }
104
+ }
105
+ const compiled = { hasLiterals, parts };
106
+ formatCache.set(fmt, compiled);
107
+ return compiled;
108
+ }
109
+ // Fast UTC date parts extraction
110
+ function getUTCParts(date) {
111
+ return {
112
+ year: date.getUTCFullYear(),
113
+ month: date.getUTCMonth() + 1,
114
+ day: date.getUTCDate(),
115
+ hour: date.getUTCHours(),
116
+ minute: date.getUTCMinutes(),
117
+ second: date.getUTCSeconds(),
118
+ };
119
+ }
120
+ // Fallback for non-UTC timezones
121
+ function getPartsWithTZ(date, locale, tz) {
122
+ const partsRaw = (0, dtf_js_1.getDTF)(locale, tz).formatToParts(date);
123
+ const p = {
124
+ year: 0,
125
+ month: 0,
126
+ day: 0,
127
+ hour: 0,
128
+ minute: 0,
129
+ second: 0,
130
+ };
131
+ for (const part of partsRaw) {
132
+ switch (part.type) {
133
+ case "year":
134
+ p.year = +part.value;
135
+ break;
136
+ case "month":
137
+ p.month = +part.value;
138
+ break;
139
+ case "day":
140
+ p.day = +part.value;
141
+ break;
142
+ case "hour":
143
+ p.hour = +part.value;
144
+ break;
145
+ case "minute":
146
+ p.minute = +part.value;
147
+ break;
148
+ case "second":
149
+ p.second = +part.value;
150
+ break;
151
+ }
152
+ }
153
+ return p;
154
+ }
155
+ function format(date, fmt, options = {}) {
156
+ const locale = options.locale ?? "en-US";
157
+ const tz = options.tz ?? "UTC";
158
+ // Get compiled format (cached)
159
+ const compiled = compileFormat(fmt);
160
+ // Fast path for UTC
161
+ const p = tz === "UTC" ? getUTCParts(date) : getPartsWithTZ(date, locale, tz);
162
+ // Build result string from compiled parts
163
+ let result = '';
164
+ for (const part of compiled.parts) {
165
+ if (part.type === 'literal') {
166
+ result += part.value;
167
+ }
168
+ else {
169
+ result += tokenMap[part.value](p, locale);
170
+ }
171
+ }
172
+ return result;
173
+ }
@@ -0,0 +1,2 @@
1
+ export declare function months(locale?: string, format?: "long" | "short" | "narrow"): string[];
2
+ //# sourceMappingURL=months.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"months.d.ts","sourceRoot":"","sources":["../../src/lib/months.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CACpB,MAAM,SAAU,EAChB,MAAM,GAAE,MAAM,GAAG,OAAO,GAAG,QAAiB,GAC3C,MAAM,EAAE,CAiBV"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.months = months;
4
+ const monthsCache = new Map();
5
+ function months(locale = "en-US", format = "long") {
6
+ const key = `${locale}|${format}`;
7
+ const cached = monthsCache.get(key);
8
+ if (cached)
9
+ return cached;
10
+ const fmt = new Intl.DateTimeFormat(locale, {
11
+ month: format,
12
+ timeZone: "UTC",
13
+ });
14
+ const result = Array.from({ length: 12 }, (_, i) => fmt.format(new Date(Date.UTC(2024, i, 1))));
15
+ monthsCache.set(key, result);
16
+ return result;
17
+ }
@@ -0,0 +1,2 @@
1
+ export declare function startOf(date: Date, unit: 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'): Date;
2
+ //# sourceMappingURL=start-of.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"start-of.d.ts","sourceRoot":"","sources":["../../src/lib/start-of.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,IAAI,CAiCvG"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startOf = startOf;
4
+ function startOf(date, unit) {
5
+ const time = new Date(date.getTime());
6
+ switch (unit) {
7
+ case 'year': {
8
+ time.setUTCMonth(0, 1);
9
+ time.setUTCHours(0, 0, 0, 0);
10
+ break;
11
+ }
12
+ case 'month': {
13
+ time.setUTCDate(1);
14
+ time.setUTCHours(0, 0, 0, 0);
15
+ break;
16
+ }
17
+ case 'day': {
18
+ time.setUTCHours(0, 0, 0, 0);
19
+ break;
20
+ }
21
+ case 'hour': {
22
+ time.setUTCMinutes(0, 0, 0);
23
+ break;
24
+ }
25
+ case 'minute': {
26
+ time.setUTCSeconds(0, 0);
27
+ break;
28
+ }
29
+ case 'second': {
30
+ time.setUTCMilliseconds(0);
31
+ break;
32
+ }
33
+ }
34
+ return time;
35
+ }
@@ -0,0 +1,23 @@
1
+ type SubOptions = {
2
+ years?: number;
3
+ months?: number;
4
+ weeks?: number;
5
+ days?: number;
6
+ hours?: number;
7
+ minutes?: number;
8
+ seconds?: number;
9
+ milliseconds?: number;
10
+ };
11
+ /**
12
+ *
13
+ * @param date
14
+ * @param opt - The time units to subtract.
15
+ * @returns A new Date object with the specified time units subtracted.
16
+ * @example
17
+ * const date = new Date('2024-01-31T12:00:00Z');
18
+ * const newDate = sub(date, { years: 1, months: 2, days: 3 });
19
+ * console.log(newDate.toISOString()); // '2023-11-28T12:00:00.000Z'
20
+ */
21
+ export declare function sub(date: Date, opt: SubOptions): Date;
22
+ export {};
23
+ //# sourceMappingURL=sub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sub.d.ts","sourceRoot":"","sources":["../../src/lib/sub.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,GAAG;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;;;;;;;;GASG;AAEH,wBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,IAAI,CAarD"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sub = sub;
4
+ const add_js_1 = require("./add.js");
5
+ /**
6
+ *
7
+ * @param date
8
+ * @param opt - The time units to subtract.
9
+ * @returns A new Date object with the specified time units subtracted.
10
+ * @example
11
+ * const date = new Date('2024-01-31T12:00:00Z');
12
+ * const newDate = sub(date, { years: 1, months: 2, days: 3 });
13
+ * console.log(newDate.toISOString()); // '2023-11-28T12:00:00.000Z'
14
+ */
15
+ function sub(date, opt) {
16
+ const out = {};
17
+ if (opt.years)
18
+ out.years = -opt.years;
19
+ if (opt.months)
20
+ out.months = -opt.months;
21
+ if (opt.weeks)
22
+ out.weeks = -opt.weeks;
23
+ if (opt.days)
24
+ out.days = -opt.days;
25
+ if (opt.hours)
26
+ out.hours = -opt.hours;
27
+ if (opt.minutes)
28
+ out.minutes = -opt.minutes;
29
+ if (opt.seconds)
30
+ out.seconds = -opt.seconds;
31
+ if (opt.milliseconds)
32
+ out.milliseconds = -opt.milliseconds;
33
+ return (0, add_js_1.add)(date, out);
34
+ }
@@ -0,0 +1,2 @@
1
+ export declare function weekdays(locale?: string, format?: "long" | "short" | "narrow"): string[];
2
+ //# sourceMappingURL=weekdays.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"weekdays.d.ts","sourceRoot":"","sources":["../../src/lib/weekdays.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CACtB,MAAM,SAAU,EAChB,MAAM,GAAE,MAAM,GAAG,OAAO,GAAG,QAAiB,GAC3C,MAAM,EAAE,CAiBV"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.weekdays = weekdays;
4
+ const daysCache = new Map();
5
+ function weekdays(locale = "en-US", format = "long") {
6
+ const key = `${locale}|${format}`;
7
+ const cached = daysCache.get(key);
8
+ if (cached)
9
+ return cached;
10
+ const fmt = new Intl.DateTimeFormat(locale, {
11
+ weekday: format,
12
+ timeZone: "UTC",
13
+ });
14
+ const result = Array.from({ length: 7 }, (_, i) => fmt.format(new Date(Date.UTC(2024, 0, i + 1))));
15
+ daysCache.set(key, result);
16
+ return result;
17
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./lib/add.js";
2
+ export * from "./lib/sub.js";
3
+ export * from "./lib/months.js";
4
+ export * from "./lib/start-of.js";
5
+ export * from "./lib/end-of.js";
6
+ export * from "./lib/format.js";
7
+ export * from "./lib/weekdays.js";
8
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC"}
package/script/mod.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lib/add.js"), exports);
18
+ __exportStar(require("./lib/sub.js"), exports);
19
+ __exportStar(require("./lib/months.js"), exports);
20
+ __exportStar(require("./lib/start-of.js"), exports);
21
+ __exportStar(require("./lib/end-of.js"), exports);
22
+ __exportStar(require("./lib/format.js"), exports);
23
+ __exportStar(require("./lib/weekdays.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }