@catbee/utils 0.0.6 → 0.0.7

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 (122) hide show
  1. package/README.md +51 -1106
  2. package/build/esm/config.d.ts +5 -13
  3. package/build/esm/config.js +0 -12
  4. package/build/esm/config.js.map +1 -1
  5. package/build/esm/servers/server.builder.d.ts +1 -118
  6. package/build/esm/servers/server.builder.js +0 -20
  7. package/build/esm/servers/server.builder.js.map +1 -1
  8. package/build/esm/servers/server.d.ts +2 -2
  9. package/build/esm/servers/server.js +3 -13
  10. package/build/esm/servers/server.js.map +1 -1
  11. package/build/esm/types/api-response.d.ts +28 -0
  12. package/build/esm/types/api-response.js +10 -1
  13. package/build/esm/types/api-response.js.map +1 -1
  14. package/build/esm/types/server.d.ts +0 -17
  15. package/build/esm/types/server.js.map +1 -1
  16. package/build/esm/utils/async.utils.d.ts +91 -0
  17. package/build/esm/utils/async.utils.js +244 -0
  18. package/build/esm/utils/async.utils.js.map +1 -1
  19. package/build/esm/utils/context-store.utils.d.ts +3 -0
  20. package/build/esm/utils/context-store.utils.js +9 -6
  21. package/build/esm/utils/context-store.utils.js.map +1 -1
  22. package/build/esm/utils/date.utils.d.ts +159 -0
  23. package/build/esm/utils/date.utils.js +389 -0
  24. package/build/esm/utils/date.utils.js.map +1 -0
  25. package/build/esm/utils/logger.utils.d.ts +3 -9
  26. package/build/esm/utils/logger.utils.js +3 -9
  27. package/build/esm/utils/logger.utils.js.map +1 -1
  28. package/build/esm/utils/middleware.utils.js +2 -1
  29. package/build/esm/utils/middleware.utils.js.map +1 -1
  30. package/build/esm/utils/performance.utils.d.ts +136 -0
  31. package/build/esm/utils/performance.utils.js +376 -0
  32. package/build/esm/utils/performance.utils.js.map +1 -0
  33. package/build/esm/utils/request.utils.d.ts +9 -0
  34. package/build/esm/utils/request.utils.js +32 -5
  35. package/build/esm/utils/request.utils.js.map +1 -1
  36. package/build/esm/utils/stream.utils.d.ts +88 -0
  37. package/build/esm/utils/stream.utils.js +284 -0
  38. package/build/esm/utils/stream.utils.js.map +1 -0
  39. package/build/esm/utils/type.utils.d.ts +90 -0
  40. package/build/esm/utils/type.utils.js +190 -0
  41. package/build/esm/utils/type.utils.js.map +1 -0
  42. package/build/esnext/config.d.ts +5 -13
  43. package/build/esnext/config.js +0 -12
  44. package/build/esnext/config.js.map +1 -1
  45. package/build/esnext/servers/server.builder.d.ts +1 -118
  46. package/build/esnext/servers/server.builder.js +0 -20
  47. package/build/esnext/servers/server.builder.js.map +1 -1
  48. package/build/esnext/servers/server.d.ts +2 -2
  49. package/build/esnext/servers/server.js +3 -13
  50. package/build/esnext/servers/server.js.map +1 -1
  51. package/build/esnext/types/api-response.d.ts +28 -0
  52. package/build/esnext/types/api-response.js +10 -1
  53. package/build/esnext/types/api-response.js.map +1 -1
  54. package/build/esnext/types/server.d.ts +0 -17
  55. package/build/esnext/types/server.js.map +1 -1
  56. package/build/esnext/utils/async.utils.d.ts +91 -0
  57. package/build/esnext/utils/async.utils.js +190 -0
  58. package/build/esnext/utils/async.utils.js.map +1 -1
  59. package/build/esnext/utils/context-store.utils.d.ts +3 -0
  60. package/build/esnext/utils/context-store.utils.js +9 -6
  61. package/build/esnext/utils/context-store.utils.js.map +1 -1
  62. package/build/esnext/utils/date.utils.d.ts +159 -0
  63. package/build/esnext/utils/date.utils.js +384 -0
  64. package/build/esnext/utils/date.utils.js.map +1 -0
  65. package/build/esnext/utils/logger.utils.d.ts +3 -9
  66. package/build/esnext/utils/logger.utils.js +3 -9
  67. package/build/esnext/utils/logger.utils.js.map +1 -1
  68. package/build/esnext/utils/middleware.utils.js +2 -1
  69. package/build/esnext/utils/middleware.utils.js.map +1 -1
  70. package/build/esnext/utils/performance.utils.d.ts +136 -0
  71. package/build/esnext/utils/performance.utils.js +271 -0
  72. package/build/esnext/utils/performance.utils.js.map +1 -0
  73. package/build/esnext/utils/request.utils.d.ts +9 -0
  74. package/build/esnext/utils/request.utils.js +23 -5
  75. package/build/esnext/utils/request.utils.js.map +1 -1
  76. package/build/esnext/utils/stream.utils.d.ts +88 -0
  77. package/build/esnext/utils/stream.utils.js +210 -0
  78. package/build/esnext/utils/stream.utils.js.map +1 -0
  79. package/build/esnext/utils/type.utils.d.ts +90 -0
  80. package/build/esnext/utils/type.utils.js +187 -0
  81. package/build/esnext/utils/type.utils.js.map +1 -0
  82. package/build/src/config.d.ts +5 -13
  83. package/build/src/config.js +0 -12
  84. package/build/src/config.js.map +1 -1
  85. package/build/src/servers/server.builder.d.ts +1 -118
  86. package/build/src/servers/server.builder.js +0 -20
  87. package/build/src/servers/server.builder.js.map +1 -1
  88. package/build/src/servers/server.d.ts +2 -2
  89. package/build/src/servers/server.js +2 -12
  90. package/build/src/servers/server.js.map +1 -1
  91. package/build/src/types/api-response.d.ts +28 -0
  92. package/build/src/types/api-response.js +11 -0
  93. package/build/src/types/api-response.js.map +1 -1
  94. package/build/src/types/server.d.ts +0 -17
  95. package/build/src/types/server.js.map +1 -1
  96. package/build/src/utils/async.utils.d.ts +91 -0
  97. package/build/src/utils/async.utils.js +194 -0
  98. package/build/src/utils/async.utils.js.map +1 -1
  99. package/build/src/utils/context-store.utils.d.ts +3 -0
  100. package/build/src/utils/context-store.utils.js +9 -6
  101. package/build/src/utils/context-store.utils.js.map +1 -1
  102. package/build/src/utils/date.utils.d.ts +159 -0
  103. package/build/src/utils/date.utils.js +396 -0
  104. package/build/src/utils/date.utils.js.map +1 -0
  105. package/build/src/utils/logger.utils.d.ts +3 -9
  106. package/build/src/utils/logger.utils.js +4 -10
  107. package/build/src/utils/logger.utils.js.map +1 -1
  108. package/build/src/utils/middleware.utils.js +2 -1
  109. package/build/src/utils/middleware.utils.js.map +1 -1
  110. package/build/src/utils/performance.utils.d.ts +136 -0
  111. package/build/src/utils/performance.utils.js +278 -0
  112. package/build/src/utils/performance.utils.js.map +1 -0
  113. package/build/src/utils/request.utils.d.ts +9 -0
  114. package/build/src/utils/request.utils.js +25 -5
  115. package/build/src/utils/request.utils.js.map +1 -1
  116. package/build/src/utils/stream.utils.d.ts +88 -0
  117. package/build/src/utils/stream.utils.js +218 -0
  118. package/build/src/utils/stream.utils.js.map +1 -0
  119. package/build/src/utils/type.utils.d.ts +90 -0
  120. package/build/src/utils/type.utils.js +196 -0
  121. package/build/src/utils/type.utils.js.map +1 -0
  122. package/package.json +6 -2
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Format options for the formatDate function
3
+ */
4
+ export interface DateFormatOptions {
5
+ /** Date format pattern (default: 'yyyy-MM-dd') */
6
+ format?: string;
7
+ /** Locale to use for formatting (default: system locale) */
8
+ locale?: string | string[];
9
+ /** Time zone to use (default: system time zone) */
10
+ timeZone?: string;
11
+ }
12
+ /**
13
+ * Format a date according to the specified format pattern.
14
+ *
15
+ * @param date - Date to format
16
+ * @param options - Formatting options
17
+ * @returns Formatted date string
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * // Format as ISO date
22
+ * formatDate(new Date(), { format: 'yyyy-MM-dd' }); // '2023-05-15'
23
+ *
24
+ * // Format with time
25
+ * formatDate(new Date(), { format: 'yyyy-MM-dd HH:mm:ss' }); // '2023-05-15 14:30:22'
26
+ *
27
+ * // Format with locale
28
+ * formatDate(new Date(), { format: 'PPPP', locale: 'fr-FR' }); // 'lundi 15 mai 2023'
29
+ * ```
30
+ */
31
+ export declare function formatDate(date: Date | number, options?: DateFormatOptions): string;
32
+ /**
33
+ * Format a date as relative time (e.g., "5 minutes ago", "in 3 days").
34
+ *
35
+ * @param date - Date to format
36
+ * @param now - Reference date (default: current time)
37
+ * @param locale - Locale to use for formatting
38
+ * @returns Formatted relative time string
39
+ */
40
+ export declare function formatRelativeTime(date: Date | number, now?: Date | number, locale?: string | string[]): string;
41
+ /**
42
+ * Parse a date string or timestamp into a Date object.
43
+ *
44
+ * @param input - Date string or timestamp to parse
45
+ * @param fallback - Fallback date if parsing fails
46
+ * @returns Parsed Date object or fallback
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * parseDate('2023-05-15'); // Date object for May 15, 2023
51
+ * parseDate('invalid', new Date()); // Returns current date as fallback
52
+ * ```
53
+ */
54
+ export declare function parseDate(input: string | number, fallback?: Date): Date | null;
55
+ /**
56
+ * Calculate the difference between two dates in the specified unit.
57
+ *
58
+ * @param date1 - First date
59
+ * @param date2 - Second date (default: current time)
60
+ * @param unit - Unit of time for the difference
61
+ * @returns Difference in the specified unit
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // Get difference in days
66
+ * dateDiff(new Date('2023-05-15'), new Date('2023-05-10'), 'days'); // 5
67
+ *
68
+ * // Get difference in hours
69
+ * dateDiff(new Date('2023-05-15T10:00:00'), new Date('2023-05-15T06:00:00'), 'hours'); // 4
70
+ * ```
71
+ */
72
+ export declare function dateDiff(date1: Date | number, date2?: Date | number, unit?: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): number;
73
+ /**
74
+ * Add a specified amount of time to a date.
75
+ *
76
+ * @param date - Base date
77
+ * @param amount - Amount to add (can be negative)
78
+ * @param unit - Unit of time to add
79
+ * @returns New date with the addition
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * // Add 5 days
84
+ * addToDate(new Date('2023-05-15'), 5, 'days'); // Date for May 20, 2023
85
+ *
86
+ * // Subtract 2 hours
87
+ * addToDate(new Date('2023-05-15T10:00:00'), -2, 'hours'); // Date for May 15, 2023 08:00:00
88
+ * ```
89
+ */
90
+ export declare function addToDate(date: Date | number, amount: number, unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'): Date;
91
+ /**
92
+ * Get the start of a time period containing the specified date.
93
+ *
94
+ * @param date - Date to get the start from
95
+ * @param unit - Time unit
96
+ * @returns Date object representing the start of the time unit
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * // Get start of day (midnight)
101
+ * startOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 00:00:00
102
+ *
103
+ * // Get start of month
104
+ * startOf(new Date('2023-05-15'), 'month'); // Date for May 1, 2023
105
+ * ```
106
+ */
107
+ export declare function startOf(date: Date | number, unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'): Date;
108
+ /**
109
+ * Get the end of a time period containing the specified date.
110
+ *
111
+ * @param date - Date to get the end from
112
+ * @param unit - Time unit
113
+ * @returns Date object representing the end of the time unit
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Get end of day (23:59:59.999)
118
+ * endOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 23:59:59.999
119
+ *
120
+ * // Get end of month
121
+ * endOf(new Date('2023-05-15'), 'month'); // Date for May 31, 2023 23:59:59.999
122
+ * ```
123
+ */
124
+ export declare function endOf(date: Date | number, unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'): Date;
125
+ /**
126
+ * Check if a date is between two other dates.
127
+ *
128
+ * @param date - Date to check
129
+ * @param start - Start date of the range
130
+ * @param end - End date of the range
131
+ * @param inclusive - Whether the comparison should be inclusive of start/end
132
+ * @returns True if the date is within the range
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * const date = new Date('2023-05-15');
137
+ * const start = new Date('2023-05-10');
138
+ * const end = new Date('2023-05-20');
139
+ *
140
+ * isBetween(date, start, end); // true
141
+ * ```
142
+ */
143
+ export declare function isBetween(date: Date | number, start: Date | number, end: Date | number, inclusive?: boolean): boolean;
144
+ /**
145
+ * Check if a year is a leap year.
146
+ *
147
+ * @param year - Year to check (or date object)
148
+ * @returns True if the year is a leap year
149
+ */
150
+ export declare function isLeapYear(year: number | Date): boolean;
151
+ /**
152
+ * Get the number of days in a month.
153
+ *
154
+ * @param year - Year
155
+ * @param month - Month (0-11)
156
+ * @returns Number of days in the month
157
+ */
158
+ export declare function daysInMonth(year: number | Date, month?: number): number;
159
+ //# sourceMappingURL=date.utils.d.ts.map
@@ -0,0 +1,389 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ /**
25
+ * Format a date according to the specified format pattern.
26
+ *
27
+ * @param date - Date to format
28
+ * @param options - Formatting options
29
+ * @returns Formatted date string
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * // Format as ISO date
34
+ * formatDate(new Date(), { format: 'yyyy-MM-dd' }); // '2023-05-15'
35
+ *
36
+ * // Format with time
37
+ * formatDate(new Date(), { format: 'yyyy-MM-dd HH:mm:ss' }); // '2023-05-15 14:30:22'
38
+ *
39
+ * // Format with locale
40
+ * formatDate(new Date(), { format: 'PPPP', locale: 'fr-FR' }); // 'lundi 15 mai 2023'
41
+ * ```
42
+ */
43
+ export function formatDate(date, options) {
44
+ if (options === void 0) { options = {}; }
45
+ var _a = options.format, format = _a === void 0 ? 'yyyy-MM-dd' : _a, locale = options.locale, timeZone = options.timeZone;
46
+ var d = date instanceof Date ? date : new Date(date);
47
+ // Custom formatter for common patterns
48
+ if (format === 'yyyy-MM-dd') {
49
+ var yyyy = d.getFullYear();
50
+ var mm = String(d.getMonth() + 1).padStart(2, '0');
51
+ var dd = String(d.getDate()).padStart(2, '0');
52
+ return "".concat(yyyy, "-").concat(mm, "-").concat(dd);
53
+ }
54
+ if (format === 'yyyy-MM-dd HH:mm:ss') {
55
+ var yyyy = d.getFullYear();
56
+ var mm = String(d.getMonth() + 1).padStart(2, '0');
57
+ var dd = String(d.getDate()).padStart(2, '0');
58
+ var HH = String(d.getHours()).padStart(2, '0');
59
+ var MM = String(d.getMinutes()).padStart(2, '0');
60
+ var SS = String(d.getSeconds()).padStart(2, '0');
61
+ return "".concat(yyyy, "-").concat(mm, "-").concat(dd, " ").concat(HH, ":").concat(MM, ":").concat(SS);
62
+ }
63
+ if (format === 'relative') {
64
+ return formatRelativeTime(date);
65
+ }
66
+ // Fallback to Intl.DateTimeFormat for other formats
67
+ return new Intl.DateTimeFormat(locale, {
68
+ timeZone: timeZone,
69
+ year: format.includes('yyyy') || format.includes('y') ? 'numeric' : undefined,
70
+ month: format.includes('MM') || format.includes('M') ? 'numeric' : undefined,
71
+ day: format.includes('dd') || format.includes('d') ? 'numeric' : undefined,
72
+ hour: format.includes('HH') || format.includes('H') ? 'numeric' : undefined,
73
+ minute: format.includes('mm') || format.includes('m') ? 'numeric' : undefined,
74
+ second: format.includes('ss') || format.includes('s') ? 'numeric' : undefined,
75
+ hour12: !format.includes('HH') && !format.includes('H')
76
+ }).format(d);
77
+ }
78
+ /**
79
+ * Format a date as relative time (e.g., "5 minutes ago", "in 3 days").
80
+ *
81
+ * @param date - Date to format
82
+ * @param now - Reference date (default: current time)
83
+ * @param locale - Locale to use for formatting
84
+ * @returns Formatted relative time string
85
+ */
86
+ export function formatRelativeTime(date, now, locale) {
87
+ if (now === void 0) { now = new Date(); }
88
+ var d1 = date instanceof Date ? date : new Date(date);
89
+ var d2 = now instanceof Date ? now : new Date(now);
90
+ var diffMs = d1.getTime() - d2.getTime();
91
+ var diffSecs = Math.round(diffMs / 1000);
92
+ var diffMins = Math.round(diffSecs / 60);
93
+ var diffHours = Math.round(diffMins / 60);
94
+ var diffDays = Math.round(diffHours / 24);
95
+ var diffMonths = Math.round(diffDays / 30);
96
+ var diffYears = Math.round(diffDays / 365);
97
+ var formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
98
+ if (Math.abs(diffSecs) < 60)
99
+ return formatter.format(diffSecs, 'second');
100
+ if (Math.abs(diffMins) < 60)
101
+ return formatter.format(diffMins, 'minute');
102
+ if (Math.abs(diffHours) < 24)
103
+ return formatter.format(diffHours, 'hour');
104
+ if (Math.abs(diffDays) < 30)
105
+ return formatter.format(diffDays, 'day');
106
+ if (Math.abs(diffMonths) < 12)
107
+ return formatter.format(diffMonths, 'month');
108
+ return formatter.format(diffYears, 'year');
109
+ }
110
+ /**
111
+ * Parse a date string or timestamp into a Date object.
112
+ *
113
+ * @param input - Date string or timestamp to parse
114
+ * @param fallback - Fallback date if parsing fails
115
+ * @returns Parsed Date object or fallback
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * parseDate('2023-05-15'); // Date object for May 15, 2023
120
+ * parseDate('invalid', new Date()); // Returns current date as fallback
121
+ * ```
122
+ */
123
+ export function parseDate(input, fallback) {
124
+ if (typeof input === 'number') {
125
+ return new Date(input);
126
+ }
127
+ try {
128
+ var date = new Date(input);
129
+ // Check if date is valid
130
+ if (isNaN(date.getTime())) {
131
+ return fallback || null;
132
+ }
133
+ return date;
134
+ }
135
+ catch (_a) {
136
+ return fallback || null;
137
+ }
138
+ }
139
+ /**
140
+ * Calculate the difference between two dates in the specified unit.
141
+ *
142
+ * @param date1 - First date
143
+ * @param date2 - Second date (default: current time)
144
+ * @param unit - Unit of time for the difference
145
+ * @returns Difference in the specified unit
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * // Get difference in days
150
+ * dateDiff(new Date('2023-05-15'), new Date('2023-05-10'), 'days'); // 5
151
+ *
152
+ * // Get difference in hours
153
+ * dateDiff(new Date('2023-05-15T10:00:00'), new Date('2023-05-15T06:00:00'), 'hours'); // 4
154
+ * ```
155
+ */
156
+ export function dateDiff(date1, date2, unit) {
157
+ if (date2 === void 0) { date2 = new Date(); }
158
+ if (unit === void 0) { unit = 'days'; }
159
+ var d1 = date1 instanceof Date ? date1 : new Date(date1);
160
+ var d2 = date2 instanceof Date ? date2 : new Date(date2);
161
+ var diffMs = d1.getTime() - d2.getTime();
162
+ switch (unit) {
163
+ case 'milliseconds':
164
+ return diffMs;
165
+ case 'seconds':
166
+ return diffMs / 1000;
167
+ case 'minutes':
168
+ return diffMs / (1000 * 60);
169
+ case 'hours':
170
+ return diffMs / (1000 * 60 * 60);
171
+ case 'days':
172
+ return diffMs / (1000 * 60 * 60 * 24);
173
+ case 'months':
174
+ return (d1.getFullYear() - d2.getFullYear()) * 12 + d1.getMonth() - d2.getMonth();
175
+ case 'years':
176
+ return d1.getFullYear() - d2.getFullYear();
177
+ default:
178
+ throw new Error("Unsupported unit: ".concat(unit));
179
+ }
180
+ }
181
+ /**
182
+ * Add a specified amount of time to a date.
183
+ *
184
+ * @param date - Base date
185
+ * @param amount - Amount to add (can be negative)
186
+ * @param unit - Unit of time to add
187
+ * @returns New date with the addition
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * // Add 5 days
192
+ * addToDate(new Date('2023-05-15'), 5, 'days'); // Date for May 20, 2023
193
+ *
194
+ * // Subtract 2 hours
195
+ * addToDate(new Date('2023-05-15T10:00:00'), -2, 'hours'); // Date for May 15, 2023 08:00:00
196
+ * ```
197
+ */
198
+ export function addToDate(date, amount, unit) {
199
+ var d = date instanceof Date ? new Date(date) : new Date(date);
200
+ switch (unit) {
201
+ case 'milliseconds':
202
+ d.setMilliseconds(d.getMilliseconds() + amount);
203
+ break;
204
+ case 'seconds':
205
+ d.setSeconds(d.getSeconds() + amount);
206
+ break;
207
+ case 'minutes':
208
+ d.setMinutes(d.getMinutes() + amount);
209
+ break;
210
+ case 'hours':
211
+ d.setHours(d.getHours() + amount);
212
+ break;
213
+ case 'days':
214
+ d.setDate(d.getDate() + amount);
215
+ break;
216
+ case 'months': {
217
+ var origDate = d.getDate();
218
+ var origMonth = d.getMonth();
219
+ d.setDate(1); // Prevent overflow
220
+ d.setMonth(origMonth + amount);
221
+ var lastDay = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
222
+ d.setDate(Math.min(origDate, lastDay));
223
+ break;
224
+ }
225
+ case 'years':
226
+ d.setFullYear(d.getFullYear() + amount);
227
+ break;
228
+ default:
229
+ throw new Error("Unsupported unit: ".concat(unit));
230
+ }
231
+ return d;
232
+ }
233
+ /**
234
+ * Get the start of a time period containing the specified date.
235
+ *
236
+ * @param date - Date to get the start from
237
+ * @param unit - Time unit
238
+ * @returns Date object representing the start of the time unit
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * // Get start of day (midnight)
243
+ * startOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 00:00:00
244
+ *
245
+ * // Get start of month
246
+ * startOf(new Date('2023-05-15'), 'month'); // Date for May 1, 2023
247
+ * ```
248
+ */
249
+ export function startOf(date, unit) {
250
+ var d = date instanceof Date ? new Date(date) : new Date(date);
251
+ switch (unit) {
252
+ case 'second':
253
+ d.setMilliseconds(0);
254
+ break;
255
+ case 'minute':
256
+ d.setSeconds(0, 0);
257
+ break;
258
+ case 'hour':
259
+ d.setMinutes(0, 0, 0);
260
+ break;
261
+ case 'day':
262
+ d.setHours(0, 0, 0, 0);
263
+ break;
264
+ case 'week':
265
+ d.setHours(0, 0, 0, 0);
266
+ d.setDate(d.getDate() - d.getDay());
267
+ break;
268
+ case 'month':
269
+ d.setDate(1);
270
+ d.setHours(0, 0, 0, 0);
271
+ break;
272
+ case 'quarter':
273
+ d.setMonth(Math.floor(d.getMonth() / 3) * 3, 1);
274
+ d.setHours(0, 0, 0, 0);
275
+ break;
276
+ case 'year':
277
+ d.setMonth(0, 1);
278
+ d.setHours(0, 0, 0, 0);
279
+ break;
280
+ default:
281
+ throw new Error("Unsupported unit: ".concat(unit));
282
+ }
283
+ return d;
284
+ }
285
+ /**
286
+ * Get the end of a time period containing the specified date.
287
+ *
288
+ * @param date - Date to get the end from
289
+ * @param unit - Time unit
290
+ * @returns Date object representing the end of the time unit
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * // Get end of day (23:59:59.999)
295
+ * endOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 23:59:59.999
296
+ *
297
+ * // Get end of month
298
+ * endOf(new Date('2023-05-15'), 'month'); // Date for May 31, 2023 23:59:59.999
299
+ * ```
300
+ */
301
+ export function endOf(date, unit) {
302
+ var d = date instanceof Date ? new Date(date) : new Date(date);
303
+ switch (unit) {
304
+ case 'second':
305
+ d.setMilliseconds(999);
306
+ break;
307
+ case 'minute':
308
+ d.setSeconds(59, 999);
309
+ break;
310
+ case 'hour':
311
+ d.setMinutes(59, 59, 999);
312
+ break;
313
+ case 'day':
314
+ d.setHours(23, 59, 59, 999);
315
+ break;
316
+ case 'week':
317
+ d.setDate(d.getDate() - d.getDay() + 6);
318
+ d.setHours(23, 59, 59, 999);
319
+ break;
320
+ case 'month':
321
+ d.setMonth(d.getMonth() + 1, 0);
322
+ d.setHours(23, 59, 59, 999);
323
+ break;
324
+ case 'quarter':
325
+ d.setMonth(Math.floor(d.getMonth() / 3) * 3 + 3, 0);
326
+ d.setHours(23, 59, 59, 999);
327
+ break;
328
+ case 'year':
329
+ d.setMonth(11, 31);
330
+ d.setHours(23, 59, 59, 999);
331
+ break;
332
+ default:
333
+ throw new Error("Unsupported unit: ".concat(unit));
334
+ }
335
+ return d;
336
+ }
337
+ /**
338
+ * Check if a date is between two other dates.
339
+ *
340
+ * @param date - Date to check
341
+ * @param start - Start date of the range
342
+ * @param end - End date of the range
343
+ * @param inclusive - Whether the comparison should be inclusive of start/end
344
+ * @returns True if the date is within the range
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * const date = new Date('2023-05-15');
349
+ * const start = new Date('2023-05-10');
350
+ * const end = new Date('2023-05-20');
351
+ *
352
+ * isBetween(date, start, end); // true
353
+ * ```
354
+ */
355
+ export function isBetween(date, start, end, inclusive) {
356
+ if (inclusive === void 0) { inclusive = true; }
357
+ var d = date instanceof Date ? date.getTime() : date;
358
+ var s = start instanceof Date ? start.getTime() : start;
359
+ var e = end instanceof Date ? end.getTime() : end;
360
+ return inclusive ? d >= s && d <= e : d > s && d < e;
361
+ }
362
+ /**
363
+ * Check if a year is a leap year.
364
+ *
365
+ * @param year - Year to check (or date object)
366
+ * @returns True if the year is a leap year
367
+ */
368
+ export function isLeapYear(year) {
369
+ var y = year instanceof Date ? year.getFullYear() : year;
370
+ return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;
371
+ }
372
+ /**
373
+ * Get the number of days in a month.
374
+ *
375
+ * @param year - Year
376
+ * @param month - Month (0-11)
377
+ * @returns Number of days in the month
378
+ */
379
+ export function daysInMonth(year, month) {
380
+ if (year instanceof Date) {
381
+ month = year.getMonth();
382
+ year = year.getFullYear();
383
+ }
384
+ if (month === undefined) {
385
+ throw new Error('Month is required when year is a number');
386
+ }
387
+ return new Date(year, month + 1, 0).getDate();
388
+ }
389
+ //# sourceMappingURL=date.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"date.utils.js","sourceRoot":"","sources":["../../../src/utils/date.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAcH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,UAAU,CAAC,IAAmB,EAAE,OAA+B;IAA/B,wBAAA,EAAA,YAA+B;IACrE,IAAA,KAA4C,OAAO,OAA9B,EAArB,MAAM,mBAAG,YAAY,KAAA,EAAE,MAAM,GAAe,OAAO,OAAtB,EAAE,QAAQ,GAAK,OAAO,SAAZ,CAAa;IAC5D,IAAM,CAAC,GAAG,IAAI,YAAY,I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AC,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,IAAM,CAAC,GAAG,GAAG,YAAY,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IAEpD,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,IAAmB;IAC5C,IAAM,CAAC,GAAG,IAAI,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3D,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC;AACzD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,IAAmB,EAAE,KAAc;IAC7D,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACzB,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACxB,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAChD,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\n/**\n * Format options for the formatDate function\n */\nexport interface DateFormatOptions {\n /** Date format pattern (default: 'yyyy-MM-dd') */\n format?: string;\n /** Locale to use for formatting (default: system locale) */\n locale?: string | string[];\n /** Time zone to use (default: system time zone) */\n timeZone?: string;\n}\n\n/**\n * Format a date according to the specified format pattern.\n *\n * @param date - Date to format\n * @param options - Formatting options\n * @returns Formatted date string\n *\n * @example\n * ```typescript\n * // Format as ISO date\n * formatDate(new Date(), { format: 'yyyy-MM-dd' }); // '2023-05-15'\n *\n * // Format with time\n * formatDate(new Date(), { format: 'yyyy-MM-dd HH:mm:ss' }); // '2023-05-15 14:30:22'\n *\n * // Format with locale\n * formatDate(new Date(), { format: 'PPPP', locale: 'fr-FR' }); // 'lundi 15 mai 2023'\n * ```\n */\nexport function formatDate(date: Date | number, options: DateFormatOptions = {}): string {\n const { format = 'yyyy-MM-dd', locale, timeZone } = options;\n const d = date instanceof Date ? date : new Date(date);\n\n // Custom formatter for common patterns\n if (format === 'yyyy-MM-dd') {\n const yyyy = d.getFullYear();\n const mm = String(d.getMonth() + 1).padStart(2, '0');\n const dd = String(d.getDate()).padStart(2, '0');\n return `${yyyy}-${mm}-${dd}`;\n }\n if (format === 'yyyy-MM-dd HH:mm:ss') {\n const yyyy = d.getFullYear();\n const mm = String(d.getMonth() + 1).padStart(2, '0');\n const dd = String(d.getDate()).padStart(2, '0');\n const HH = String(d.getHours()).padStart(2, '0');\n const MM = String(d.getMinutes()).padStart(2, '0');\n const SS = String(d.getSeconds()).padStart(2, '0');\n return `${yyyy}-${mm}-${dd} ${HH}:${MM}:${SS}`;\n }\n if (format === 'relative') {\n return formatRelativeTime(date);\n }\n\n // Fallback to Intl.DateTimeFormat for other formats\n return new Intl.DateTimeFormat(locale, {\n timeZone,\n year: format.includes('yyyy') || format.includes('y') ? 'numeric' : undefined,\n month: format.includes('MM') || format.includes('M') ? 'numeric' : undefined,\n day: format.includes('dd') || format.includes('d') ? 'numeric' : undefined,\n hour: format.includes('HH') || format.includes('H') ? 'numeric' : undefined,\n minute: format.includes('mm') || format.includes('m') ? 'numeric' : undefined,\n second: format.includes('ss') || format.includes('s') ? 'numeric' : undefined,\n hour12: !format.includes('HH') && !format.includes('H')\n }).format(d);\n}\n\n/**\n * Format a date as relative time (e.g., \"5 minutes ago\", \"in 3 days\").\n *\n * @param date - Date to format\n * @param now - Reference date (default: current time)\n * @param locale - Locale to use for formatting\n * @returns Formatted relative time string\n */\nexport function formatRelativeTime(\n date: Date | number,\n now: Date | number = new Date(),\n locale?: string | string[]\n): string {\n const d1 = date instanceof Date ? date : new Date(date);\n const d2 = now instanceof Date ? now : new Date(now);\n\n const diffMs = d1.getTime() - d2.getTime();\n const diffSecs = Math.round(diffMs / 1000);\n const diffMins = Math.round(diffSecs / 60);\n const diffHours = Math.round(diffMins / 60);\n const diffDays = Math.round(diffHours / 24);\n const diffMonths = Math.round(diffDays / 30);\n const diffYears = Math.round(diffDays / 365);\n\n const formatter = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n\n if (Math.abs(diffSecs) < 60) return formatter.format(diffSecs, 'second');\n if (Math.abs(diffMins) < 60) return formatter.format(diffMins, 'minute');\n if (Math.abs(diffHours) < 24) return formatter.format(diffHours, 'hour');\n if (Math.abs(diffDays) < 30) return formatter.format(diffDays, 'day');\n if (Math.abs(diffMonths) < 12) return formatter.format(diffMonths, 'month');\n return formatter.format(diffYears, 'year');\n}\n\n/**\n * Parse a date string or timestamp into a Date object.\n *\n * @param input - Date string or timestamp to parse\n * @param fallback - Fallback date if parsing fails\n * @returns Parsed Date object or fallback\n *\n * @example\n * ```typescript\n * parseDate('2023-05-15'); // Date object for May 15, 2023\n * parseDate('invalid', new Date()); // Returns current date as fallback\n * ```\n */\nexport function parseDate(input: string | number, fallback?: Date): Date | null {\n if (typeof input === 'number') {\n return new Date(input);\n }\n\n try {\n const date = new Date(input);\n // Check if date is valid\n if (isNaN(date.getTime())) {\n return fallback || null;\n }\n return date;\n } catch {\n return fallback || null;\n }\n}\n\n/**\n * Calculate the difference between two dates in the specified unit.\n *\n * @param date1 - First date\n * @param date2 - Second date (default: current time)\n * @param unit - Unit of time for the difference\n * @returns Difference in the specified unit\n *\n * @example\n * ```typescript\n * // Get difference in days\n * dateDiff(new Date('2023-05-15'), new Date('2023-05-10'), 'days'); // 5\n *\n * // Get difference in hours\n * dateDiff(new Date('2023-05-15T10:00:00'), new Date('2023-05-15T06:00:00'), 'hours'); // 4\n * ```\n */\nexport function dateDiff(\n date1: Date | number,\n date2: Date | number = new Date(),\n unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' = 'days'\n): number {\n const d1 = date1 instanceof Date ? date1 : new Date(date1);\n const d2 = date2 instanceof Date ? date2 : new Date(date2);\n\n const diffMs = d1.getTime() - d2.getTime();\n\n switch (unit) {\n case 'milliseconds':\n return diffMs;\n case 'seconds':\n return diffMs / 1000;\n case 'minutes':\n return diffMs / (1000 * 60);\n case 'hours':\n return diffMs / (1000 * 60 * 60);\n case 'days':\n return diffMs / (1000 * 60 * 60 * 24);\n case 'months':\n return (d1.getFullYear() - d2.getFullYear()) * 12 + d1.getMonth() - d2.getMonth();\n case 'years':\n return d1.getFullYear() - d2.getFullYear();\n default:\n throw new Error(`Unsupported unit: ${unit}`);\n }\n}\n\n/**\n * Add a specified amount of time to a date.\n *\n * @param date - Base date\n * @param amount - Amount to add (can be negative)\n * @param unit - Unit of time to add\n * @returns New date with the addition\n *\n * @example\n * ```typescript\n * // Add 5 days\n * addToDate(new Date('2023-05-15'), 5, 'days'); // Date for May 20, 2023\n *\n * // Subtract 2 hours\n * addToDate(new Date('2023-05-15T10:00:00'), -2, 'hours'); // Date for May 15, 2023 08:00:00\n * ```\n */\nexport function addToDate(\n date: Date | number,\n amount: number,\n unit: 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years'\n): Date {\n const d = date instanceof Date ? new Date(date) : new Date(date);\n\n switch (unit) {\n case 'milliseconds':\n d.setMilliseconds(d.getMilliseconds() + amount);\n break;\n case 'seconds':\n d.setSeconds(d.getSeconds() + amount);\n break;\n case 'minutes':\n d.setMinutes(d.getMinutes() + amount);\n break;\n case 'hours':\n d.setHours(d.getHours() + amount);\n break;\n case 'days':\n d.setDate(d.getDate() + amount);\n break;\n case 'months': {\n const origDate = d.getDate();\n const origMonth = d.getMonth();\n d.setDate(1); // Prevent overflow\n d.setMonth(origMonth + amount);\n const lastDay = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();\n d.setDate(Math.min(origDate, lastDay));\n break;\n }\n case 'years':\n d.setFullYear(d.getFullYear() + amount);\n break;\n default:\n throw new Error(`Unsupported unit: ${unit}`);\n }\n\n return d;\n}\n\n/**\n * Get the start of a time period containing the specified date.\n *\n * @param date - Date to get the start from\n * @param unit - Time unit\n * @returns Date object representing the start of the time unit\n *\n * @example\n * ```typescript\n * // Get start of day (midnight)\n * startOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 00:00:00\n *\n * // Get start of month\n * startOf(new Date('2023-05-15'), 'month'); // Date for May 1, 2023\n * ```\n */\nexport function startOf(\n date: Date | number,\n unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'\n): Date {\n const d = date instanceof Date ? new Date(date) : new Date(date);\n\n switch (unit) {\n case 'second':\n d.setMilliseconds(0);\n break;\n case 'minute':\n d.setSeconds(0, 0);\n break;\n case 'hour':\n d.setMinutes(0, 0, 0);\n break;\n case 'day':\n d.setHours(0, 0, 0, 0);\n break;\n case 'week':\n d.setHours(0, 0, 0, 0);\n d.setDate(d.getDate() - d.getDay());\n break;\n case 'month':\n d.setDate(1);\n d.setHours(0, 0, 0, 0);\n break;\n case 'quarter':\n d.setMonth(Math.floor(d.getMonth() / 3) * 3, 1);\n d.setHours(0, 0, 0, 0);\n break;\n case 'year':\n d.setMonth(0, 1);\n d.setHours(0, 0, 0, 0);\n break;\n default:\n throw new Error(`Unsupported unit: ${unit}`);\n }\n\n return d;\n}\n\n/**\n * Get the end of a time period containing the specified date.\n *\n * @param date - Date to get the end from\n * @param unit - Time unit\n * @returns Date object representing the end of the time unit\n *\n * @example\n * ```typescript\n * // Get end of day (23:59:59.999)\n * endOf(new Date('2023-05-15T14:30:00'), 'day'); // Date for May 15, 2023 23:59:59.999\n *\n * // Get end of month\n * endOf(new Date('2023-05-15'), 'month'); // Date for May 31, 2023 23:59:59.999\n * ```\n */\nexport function endOf(\n date: Date | number,\n unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'\n): Date {\n const d = date instanceof Date ? new Date(date) : new Date(date);\n\n switch (unit) {\n case 'second':\n d.setMilliseconds(999);\n break;\n case 'minute':\n d.setSeconds(59, 999);\n break;\n case 'hour':\n d.setMinutes(59, 59, 999);\n break;\n case 'day':\n d.setHours(23, 59, 59, 999);\n break;\n case 'week':\n d.setDate(d.getDate() - d.getDay() + 6);\n d.setHours(23, 59, 59, 999);\n break;\n case 'month':\n d.setMonth(d.getMonth() + 1, 0);\n d.setHours(23, 59, 59, 999);\n break;\n case 'quarter':\n d.setMonth(Math.floor(d.getMonth() / 3) * 3 + 3, 0);\n d.setHours(23, 59, 59, 999);\n break;\n case 'year':\n d.setMonth(11, 31);\n d.setHours(23, 59, 59, 999);\n break;\n default:\n throw new Error(`Unsupported unit: ${unit}`);\n }\n\n return d;\n}\n\n/**\n * Check if a date is between two other dates.\n *\n * @param date - Date to check\n * @param start - Start date of the range\n * @param end - End date of the range\n * @param inclusive - Whether the comparison should be inclusive of start/end\n * @returns True if the date is within the range\n *\n * @example\n * ```typescript\n * const date = new Date('2023-05-15');\n * const start = new Date('2023-05-10');\n * const end = new Date('2023-05-20');\n *\n * isBetween(date, start, end); // true\n * ```\n */\nexport function isBetween(\n date: Date | number,\n start: Date | number,\n end: Date | number,\n inclusive: boolean = true\n): boolean {\n const d = date instanceof Date ? date.getTime() : date;\n const s = start instanceof Date ? start.getTime() : start;\n const e = end instanceof Date ? end.getTime() : end;\n\n return inclusive ? d >= s && d <= e : d > s && d < e;\n}\n\n/**\n * Check if a year is a leap year.\n *\n * @param year - Year to check (or date object)\n * @returns True if the year is a leap year\n */\nexport function isLeapYear(year: number | Date): boolean {\n const y = year instanceof Date ? year.getFullYear() : year;\n return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;\n}\n\n/**\n * Get the number of days in a month.\n *\n * @param year - Year\n * @param month - Month (0-11)\n * @returns Number of days in the month\n */\nexport function daysInMonth(year: number | Date, month?: number): number {\n if (year instanceof Date) {\n month = year.getMonth();\n year = year.getFullYear();\n }\n\n if (month === undefined) {\n throw new Error('Month is required when year is a number');\n }\n\n return new Date(year, month + 1, 0).getDate();\n}\n"]}
@@ -129,16 +129,10 @@ export declare const _globalThis: typeof globalThis;
129
129
  */
130
130
  export declare function getLogger(): PinoLogger;
131
131
  /**
132
- * Alias for the current logger instance.
133
- * - Returns a request-scoped logger from AsyncLocalStorage if available
134
- * - Falls back to the global (singleton) logger
135
- * - Initializes the global logger if not created yet
136
- */
137
- export declare const logger: typeof getLogger;
138
- /**
139
- * Global logger instance.
132
+ * Logger instance for the global context.
133
+ * This logger is used for logging messages that are not tied to a specific request.
140
134
  */
141
- export declare const globalLogger: PinoLogger;
135
+ export declare const logger: PinoLogger;
142
136
  /**
143
137
  * Creates a child logger with additional context.
144
138
  *
@@ -291,16 +291,10 @@ export function getLogger() {
291
291
  return _global[GLOBAL_LOGGER_KEY];
292
292
  }
293
293
  /**
294
- * Alias for the current logger instance.
295
- * - Returns a request-scoped logger from AsyncLocalStorage if available
296
- * - Falls back to the global (singleton) logger
297
- * - Initializes the global logger if not created yet
298
- */
299
- export var logger = getLogger;
300
- /**
301
- * Global logger instance.
294
+ * Logger instance for the global context.
295
+ * This logger is used for logging messages that are not tied to a specific request.
302
296
  */
303
- export var globalLogger = getLogger();
297
+ export var logger = getLogger();
304
298
  /**
305
299
  * Creates a child logger with additional context.
306
300
  *