@catbee/utils 0.0.8-next.0 → 0.0.8-rc.1

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