@catbee/utils 0.0.8-next.0 → 0.0.8-rc.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 (284) hide show
  1. package/README.md +1 -26
  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 +315 -0
  42. package/build/esm/utils/decorators.utils.js +666 -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 +315 -0
  135. package/build/esnext/utils/decorators.utils.js +504 -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 +315 -0
  228. package/build/src/utils/decorators.utils.js +516 -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,873 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
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
+ var __read = (this && this.__read) || function (o, n) {
25
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
26
+ if (!m) return o;
27
+ var i = m.call(o), r, ar = [], e;
28
+ try {
29
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
+ }
31
+ catch (error) { e = { error: error }; }
32
+ finally {
33
+ try {
34
+ if (r && !r.done && (m = i["return"])) m.call(i);
35
+ }
36
+ finally { if (e) throw e.error; }
37
+ }
38
+ return ar;
39
+ };
40
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
41
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
42
+ if (ar || !(i in from)) {
43
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
44
+ ar[i] = from[i];
45
+ }
46
+ }
47
+ return to.concat(ar || Array.prototype.slice.call(from));
48
+ };
49
+ var __values = (this && this.__values) || function(o) {
50
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
51
+ if (m) return m.call(o);
52
+ if (o && typeof o.length === "number") return {
53
+ next: function () {
54
+ if (o && i >= o.length) o = void 0;
55
+ return { value: o && o[i++], done: !o };
56
+ }
57
+ };
58
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
+ };
60
+ /* eslint-disable n/no-process-env */
61
+ import { existsSync, readFileSync } from 'fs';
62
+ import { isAbsolute, resolve } from 'path';
63
+ /**
64
+ * Enum representing valid application environments.
65
+ */
66
+ export var Environment;
67
+ (function (Environment) {
68
+ Environment["PRODUCTION"] = "production";
69
+ Environment["DEVELOPMENT"] = "development";
70
+ Environment["STAGING"] = "staging";
71
+ Environment["TESTING"] = "testing";
72
+ })(Environment || (Environment = {}));
73
+ /**
74
+ * Utility class for accessing and managing environment variables.
75
+ * Provides typed getters with fallback defaults and validation.
76
+ */
77
+ var Env = /** @class */ (function () {
78
+ function Env() {
79
+ }
80
+ /**
81
+ * Checks if the current NODE_ENV is 'development'.
82
+ *
83
+ * @returns {boolean} `true` if NODE_ENV is 'development', else `false`.
84
+ */
85
+ Env.isDev = function () {
86
+ return Env.get('NODE_ENV', Environment.DEVELOPMENT) === Environment.DEVELOPMENT;
87
+ };
88
+ /**
89
+ * Checks if the current NODE_ENV is 'production'.
90
+ *
91
+ * @returns {boolean} `true` if NODE_ENV is 'production', else `false`.
92
+ */
93
+ Env.isProd = function () {
94
+ return Env.get('NODE_ENV', Environment.DEVELOPMENT) === Environment.PRODUCTION;
95
+ };
96
+ /**
97
+ * Checks if the current NODE_ENV is 'testing'.
98
+ *
99
+ * @returns {boolean} `true` if NODE_ENV is 'testing', else `false`.
100
+ */
101
+ Env.isTest = function () {
102
+ return Env.get('NODE_ENV', Environment.DEVELOPMENT) === Environment.TESTING;
103
+ };
104
+ /**
105
+ * Checks if the current NODE_ENV is 'staging'.
106
+ *
107
+ * @returns {boolean} `true` if NODE_ENV is 'staging', else `false`.
108
+ */
109
+ Env.isStaging = function () {
110
+ return Env.get('NODE_ENV', Environment.DEVELOPMENT) === Environment.STAGING;
111
+ };
112
+ /**
113
+ * Sets an environment variable (only affects runtime memory).
114
+ *
115
+ * @param {string} key - The environment variable key.
116
+ * @param {string} value - The value to set.
117
+ */
118
+ Env.set = function (key, value) {
119
+ var e_1, _a;
120
+ process.env[key] = value;
121
+ // Clear all cached values for this key with any prefix
122
+ this.cache.delete(key);
123
+ try {
124
+ for (var _b = __values(__spreadArray([], __read(this.cache.keys()), false)), _c = _b.next(); !_c.done; _c = _b.next()) {
125
+ var cacheKey = _c.value;
126
+ if (cacheKey.includes(":".concat(key))) {
127
+ this.cache.delete(cacheKey);
128
+ }
129
+ }
130
+ }
131
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
132
+ finally {
133
+ try {
134
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
135
+ }
136
+ finally { if (e_1) throw e_1.error; }
137
+ }
138
+ };
139
+ /**
140
+ * Returns all environment variables as an object.
141
+ *
142
+ * @returns {object} The current `process.env` object.
143
+ */
144
+ Env.getAll = function () {
145
+ return process.env;
146
+ };
147
+ /**
148
+ * Retrieves a string environment variable with a fallback default.
149
+ * Supports variable expansion with ${VAR_NAME} syntax.
150
+ *
151
+ * @param {string} key - The environment variable key.
152
+ * @param {string} [defaultValue] - Value to return if the key is missing.
153
+ * @returns {string} The env value or the fallback.
154
+ *
155
+ * @example
156
+ * // If DATABASE_URL is "postgres://localhost:5432/${DB_NAME}"
157
+ * // and DB_NAME is "myapp"
158
+ * const url = Env.get('DATABASE_URL', ''); // "postgres://localhost:5432/myapp"
159
+ */
160
+ Env.get = function (key, defaultValue) {
161
+ var _a;
162
+ var value = (_a = process.env[key]) !== null && _a !== void 0 ? _a : defaultValue;
163
+ // Expand ${VAR} references
164
+ if (value && value.includes('${')) {
165
+ value = value.replace(/\${([A-Za-z0-9_]+)}/g, function (_, varName) {
166
+ var _a;
167
+ return (_a = process.env[varName]) !== null && _a !== void 0 ? _a : '';
168
+ });
169
+ }
170
+ return value;
171
+ };
172
+ /**
173
+ * Retrieves a string environment variable and throws if it's missing.
174
+ *
175
+ * @param {string} key - The environment variable key.
176
+ * @returns {string} The environment variable's value.
177
+ * @throws {Error} If the variable is not defined.
178
+ */
179
+ Env.getRequired = function (key) {
180
+ var value = process.env[key];
181
+ if (value === undefined) {
182
+ throw new Error("Required environment variable '".concat(key, "' is missing"));
183
+ }
184
+ return Env.get(key, ''); // Use get to handle variable expansion
185
+ };
186
+ /**
187
+ * Retrieves a value using a default generating function if the key doesn't exist.
188
+ * Useful for expensive default calculations.
189
+ *
190
+ * @param {string} key - The environment variable key.
191
+ * @param {() => string} defaultFn - Function that generates default value.
192
+ * @returns {string} The environment value or generated default.
193
+ *
194
+ * @example
195
+ * const hostname = Env.getWithDefault('HOSTNAME', () => {
196
+ * // Only called if HOSTNAME is not set
197
+ * return require('os').hostname();
198
+ * });
199
+ */
200
+ Env.getWithDefault = function (key, defaultFn) {
201
+ if (Env.has(key)) {
202
+ return Env.get(key, '');
203
+ }
204
+ return defaultFn();
205
+ };
206
+ /**
207
+ * Retrieves an environment variable as a number, or returns a default.
208
+ *
209
+ * @param {string} key - The environment variable key.
210
+ * @param {number} defaultValue - Fallback number if key is not present.
211
+ * @returns {number} Parsed numeric value or default.
212
+ * @throws {Error} If the value is not a valid number.
213
+ */
214
+ Env.getNumber = function (key, defaultValue) {
215
+ if (this.cache.has("number:".concat(key))) {
216
+ return this.cache.get("number:".concat(key));
217
+ }
218
+ var value = process.env[key];
219
+ if (value === undefined) {
220
+ return defaultValue;
221
+ }
222
+ var numberValue = Number(value);
223
+ if (isNaN(numberValue)) {
224
+ throw new Error("Environment variable '".concat(key, "' is not a valid number, got: \"").concat(value, "\""));
225
+ }
226
+ this.cache.set("number:".concat(key), numberValue);
227
+ return numberValue;
228
+ };
229
+ /**
230
+ * Retrieves a required environment variable as a number.
231
+ *
232
+ * @param {string} key - The environment variable key.
233
+ * @returns {number} Parsed number.
234
+ * @throws {Error} If the value is missing or not a number.
235
+ */
236
+ Env.getNumberRequired = function (key) {
237
+ var value = process.env[key];
238
+ if (value === undefined) {
239
+ throw new Error("Required environment variable '".concat(key, "' is missing"));
240
+ }
241
+ return Env.getNumber(key, 0); // The default is ignored since we know the key exists
242
+ };
243
+ /**
244
+ * Retrieves an integer environment variable and validates it.
245
+ *
246
+ * @param {string} key - The environment variable key.
247
+ * @param {number} defaultValue - Fallback number if key is not present.
248
+ * @param {object} [options] - Validation options.
249
+ * @param {number} [options.min] - Minimum allowed value.
250
+ * @param {number} [options.max] - Maximum allowed value.
251
+ * @returns {number} The parsed integer.
252
+ *
253
+ * @example
254
+ * // Require PORT to be between 1000 and 9999
255
+ * const port = Env.getInteger('PORT', 3000, { min: 1000, max: 9999 });
256
+ */
257
+ Env.getInteger = function (key, defaultValue, options) {
258
+ if (options === void 0) { options = {}; }
259
+ var num = Env.getNumber(key, defaultValue);
260
+ var intValue = Math.floor(num);
261
+ if (intValue !== num) {
262
+ throw new Error("Environment variable '".concat(key, "' must be an integer, got: ").concat(num));
263
+ }
264
+ if (options.min !== undefined && intValue < options.min) {
265
+ throw new Error("Environment variable '".concat(key, "' must be at least ").concat(options.min, ", got: ").concat(intValue));
266
+ }
267
+ if (options.max !== undefined && intValue > options.max) {
268
+ throw new Error("Environment variable '".concat(key, "' must be at most ").concat(options.max, ", got: ").concat(intValue));
269
+ }
270
+ return intValue;
271
+ };
272
+ /**
273
+ * Retrieves an environment variable as a boolean.
274
+ * Accepts `true`, `1`, `yes`, `on` as true; `false`, `0`, `no`, `off` as false.
275
+ *
276
+ * @param {string} key - The environment variable key.
277
+ * @param {boolean} [defaultValue=false] - Optional fallback value if key is missing.
278
+ * @returns {boolean} Parsed boolean.
279
+ * @throws {Error} If the value is not a recognized boolean string.
280
+ *
281
+ * @example
282
+ * // If DEBUG=yes
283
+ * const isDebug = Env.getBoolean('DEBUG', false); // true
284
+ */
285
+ Env.getBoolean = function (key, defaultValue) {
286
+ if (defaultValue === void 0) { defaultValue = false; }
287
+ if (this.cache.has("bool:".concat(key))) {
288
+ return this.cache.get("bool:".concat(key));
289
+ }
290
+ var value = process.env[key];
291
+ if (value === undefined) {
292
+ return defaultValue;
293
+ }
294
+ var lowerValue = value.toLowerCase();
295
+ if (['true', '1', 'yes', 'on'].includes(lowerValue)) {
296
+ this.cache.set("bool:".concat(key), true);
297
+ return true;
298
+ }
299
+ if (['false', '0', 'no', 'off'].includes(lowerValue)) {
300
+ this.cache.set("bool:".concat(key), false);
301
+ return false;
302
+ }
303
+ throw new Error("Environment variable '".concat(key, "' is not a valid boolean, got: \"").concat(value, "\". Use true/false, yes/no, 1/0, or on/off."));
304
+ };
305
+ /**
306
+ * Retrieves a required environment variable as a boolean.
307
+ *
308
+ * @param {string} key - The environment variable key.
309
+ * @returns {boolean} Parsed boolean value.
310
+ * @throws {Error} If missing or invalid.
311
+ */
312
+ Env.getBooleanRequired = function (key) {
313
+ var value = process.env[key];
314
+ if (value === undefined) {
315
+ throw new Error("Required environment variable '".concat(key, "' is missing"));
316
+ }
317
+ return Env.getBoolean(key);
318
+ };
319
+ /**
320
+ * Parses a stringified JSON object from an environment variable.
321
+ *
322
+ * @typeParam T - The type to parse as (defaults to `object`).
323
+ * @param {string} key - The environment variable key.
324
+ * @param {T} defaultValue - Value to return if key is missing.
325
+ * @returns {T} Parsed object or default.
326
+ * @throws {Error} If the value is not valid JSON.
327
+ *
328
+ * @example
329
+ * // If CONFIG='{"debug":true,"api":{"url":"https://api.example.com"}}'
330
+ * const config = Env.getJSON('CONFIG', { debug: false });
331
+ * // { debug: true, api: { url: "https://api.example.com" }}
332
+ */
333
+ Env.getJSON = function (key, defaultValue) {
334
+ if (this.cache.has("json:".concat(key))) {
335
+ return this.cache.get("json:".concat(key));
336
+ }
337
+ var v = process.env[key];
338
+ if (v === undefined) {
339
+ return defaultValue;
340
+ }
341
+ try {
342
+ var parsed = JSON.parse(v);
343
+ this.cache.set("json:".concat(key), parsed);
344
+ return parsed;
345
+ }
346
+ catch (error) {
347
+ throw new Error("Environment variable '".concat(key, "' is not valid JSON: ").concat(error.message));
348
+ }
349
+ };
350
+ /**
351
+ * Parses a comma-separated string as an array.
352
+ *
353
+ * @typeParam T - The item type (optional, defaults to string).
354
+ * @param {string} key - The environment variable key.
355
+ * @param {T[]} [defaultValue=[]] - Array to return if value is empty or missing.
356
+ * @param {string} [splitter=','] - Delimiter to split on.
357
+ * @param {(item: string) => T} [transform] - Optional function to transform each item.
358
+ * @returns {T[]} An array of items.
359
+ *
360
+ * @example
361
+ * // If ALLOWED_IPS=127.0.0.1,192.168.1.1,10.0.0.1
362
+ * const ips = Env.getArray('ALLOWED_IPS');
363
+ * // ["127.0.0.1", "192.168.1.1", "10.0.0.1"]
364
+ *
365
+ * // With transformation function
366
+ * const ports = Env.getArray('PORTS', [], ',', (p) => parseInt(p, 10));
367
+ */
368
+ Env.getArray = function (key, defaultValue, splitter, transform) {
369
+ if (defaultValue === void 0) { defaultValue = []; }
370
+ if (splitter === void 0) { splitter = ','; }
371
+ var cacheKey = "array:".concat(key, ":").concat(splitter, ":").concat(transform ? 'transformed' : 'raw');
372
+ if (this.cache.has(cacheKey)) {
373
+ return this.cache.get(cacheKey);
374
+ }
375
+ var value = process.env[key];
376
+ if (!value || value.trim() === '') {
377
+ return defaultValue;
378
+ }
379
+ var items = value
380
+ .split(splitter)
381
+ .map(function (item) { return item.trim(); })
382
+ .filter(function (item) { return item.length > 0; });
383
+ if (transform) {
384
+ try {
385
+ var result_1 = items.map(transform);
386
+ this.cache.set(cacheKey, result_1);
387
+ return result_1;
388
+ }
389
+ catch (error) {
390
+ throw new Error("Failed to transform items in '".concat(key, "': ").concat(error.message));
391
+ }
392
+ }
393
+ var result = items;
394
+ this.cache.set(cacheKey, result);
395
+ return result;
396
+ };
397
+ /**
398
+ * Parses a comma-separated list of numbers.
399
+ *
400
+ * @param {string} key - The environment variable key.
401
+ * @param {number[]} [defaultValue=[]] - Default value if not present.
402
+ * @param {string} [splitter=','] - Delimiter to split on.
403
+ * @returns {number[]} Array of parsed numbers.
404
+ *
405
+ * @example
406
+ * // If ALLOWED_PORTS=80,443,3000,8080
407
+ * const ports = Env.getNumberArray('ALLOWED_PORTS');
408
+ * // [80, 443, 3000, 8080]
409
+ */
410
+ Env.getNumberArray = function (key, defaultValue, splitter) {
411
+ if (defaultValue === void 0) { defaultValue = []; }
412
+ if (splitter === void 0) { splitter = ','; }
413
+ return Env.getArray(key, defaultValue, splitter, function (item) {
414
+ var num = Number(item);
415
+ if (isNaN(num)) {
416
+ throw new Error("Value \"".concat(item, "\" in array '").concat(key, "' is not a valid number"));
417
+ }
418
+ return num;
419
+ });
420
+ };
421
+ /**
422
+ * Retrieves an enum-like environment variable value, validating against allowed values.
423
+ *
424
+ * @typeParam T - The allowed value type (string literal types).
425
+ * @param {string} key - The environment variable key.
426
+ * @param {T[]} allowedValues - Array of accepted string values.
427
+ * @param {T} [defaultValue] - Optional fallback value.
428
+ * @returns {T} The validated environment value.
429
+ * @throws {Error} If missing or invalid.
430
+ *
431
+ * @example
432
+ * // If LOG_LEVEL=debug
433
+ * const level = Env.getEnum('LOG_LEVEL', ['debug', 'info', 'warn', 'error'] as const, 'info');
434
+ * // 'debug' (typed as 'debug' | 'info' | 'warn' | 'error')
435
+ */
436
+ Env.getEnum = function (key, allowedValues, defaultValue) {
437
+ var value = process.env[key];
438
+ if (!value) {
439
+ return defaultValue;
440
+ }
441
+ if (!allowedValues.includes(value)) {
442
+ throw new Error("Environment variable '".concat(key, "' must be one of: ").concat(allowedValues.join(', '), ". Received: \"").concat(value, "\""));
443
+ }
444
+ return value;
445
+ };
446
+ /**
447
+ * Retrieves an enum-like numeric environment variable.
448
+ *
449
+ * @param {string} key - The environment variable key.
450
+ * @param {number[]} allowedValues - Array of accepted values.
451
+ * @param {number} defaultValue - Default value if not present.
452
+ * @returns {number} The validated value.
453
+ *
454
+ * @example
455
+ * // If NODE_VERSION=16
456
+ * const version = Env.getNumberEnum('NODE_VERSION', [14, 16, 18], 16);
457
+ */
458
+ Env.getNumberEnum = function (key, allowedValues, defaultValue) {
459
+ var value = Env.getNumber(key, defaultValue);
460
+ if (!allowedValues.includes(value)) {
461
+ throw new Error("Environment variable '".concat(key, "' must be one of: ").concat(allowedValues.join(', '), ". Received: ").concat(value));
462
+ }
463
+ return value;
464
+ };
465
+ /**
466
+ * Retrieves a URL environment variable and validates it.
467
+ *
468
+ * @param {string} key - The environment variable key.
469
+ * @param {string} [defaultValue] - Optional fallback value.
470
+ * @param {UrlOptions} [options] - Validation options.
471
+ * @returns {string} The validated URL.
472
+ * @throws {Error} If URL is invalid.
473
+ *
474
+ * @example
475
+ * // Validate API URL requires HTTPS
476
+ * const apiUrl = Env.getUrl('API_URL', 'https://api.example.com', {
477
+ * protocols: ['https'],
478
+ * requireTld: true,
479
+ * allowIp: false
480
+ * });
481
+ */
482
+ Env.getUrl = function (key, defaultValue, options) {
483
+ if (options === void 0) { options = {}; }
484
+ var cacheKey = "url:".concat(key, ":").concat(JSON.stringify(options));
485
+ if (this.cache.has(cacheKey)) {
486
+ return this.cache.get(cacheKey);
487
+ }
488
+ var value = Env.get(key, defaultValue);
489
+ if (!value) {
490
+ throw new Error("URL environment variable '".concat(key, "' is missing or empty"));
491
+ }
492
+ var url;
493
+ try {
494
+ url = new URL(value);
495
+ }
496
+ catch (_a) {
497
+ throw new Error("Environment variable '".concat(key, "' is not a valid URL: \"").concat(value, "\""));
498
+ }
499
+ // Validate protocol
500
+ if (options.protocols && options.protocols.length > 0) {
501
+ var protocol = url.protocol.replace(':', '');
502
+ if (!options.protocols.includes(protocol)) {
503
+ throw new Error("Environment variable '".concat(key, "' must use one of the protocols: ").concat(options.protocols.join(', '), ". Got: ").concat(protocol));
504
+ }
505
+ }
506
+ // Validate hostname
507
+ var hostname = url.hostname;
508
+ var isIp = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/.test(hostname);
509
+ var isLocalhost = hostname === 'localhost';
510
+ // Check if hostname is an IP address when not allowed
511
+ if (isIp && options.allowIp === false) {
512
+ throw new Error("Environment variable '".concat(key, "' cannot be an IP address: \"").concat(hostname, "\""));
513
+ }
514
+ // Check if hostname is localhost when not allowed
515
+ if (isLocalhost && options.allowLocalhost === false) {
516
+ throw new Error("Environment variable '".concat(key, "' cannot be localhost"));
517
+ }
518
+ // Check for TLD requirement - include localhost in check if requireTld is true and allowLocalhost is false
519
+ if (options.requireTld === true) {
520
+ if (isLocalhost && options.allowLocalhost !== false) {
521
+ // Localhost is allowed, so no TLD check needed for it
522
+ }
523
+ else if (isIp && options.allowIp !== false) {
524
+ // IP is allowed, so no TLD check needed for it
525
+ }
526
+ else if (!hostname.includes('.') || hostname.endsWith('.')) {
527
+ throw new Error("Environment variable '".concat(key, "' must have a valid host with TLD: \"").concat(hostname, "\""));
528
+ }
529
+ }
530
+ this.cache.set(cacheKey, value);
531
+ return value;
532
+ };
533
+ /**
534
+ * Retrieves an email environment variable and validates it.
535
+ *
536
+ * @param {string} key - The environment variable key.
537
+ * @param {string} [defaultValue] - Optional fallback value.
538
+ * @returns {string} The validated email address.
539
+ * @throws {Error} If email is invalid.
540
+ *
541
+ * @example
542
+ * const supportEmail = Env.getEmail('SUPPORT_EMAIL', 'support@example.com');
543
+ */
544
+ Env.getEmail = function (key, defaultValue) {
545
+ if (this.cache.has("email:".concat(key))) {
546
+ return this.cache.get("email:".concat(key));
547
+ }
548
+ var value = Env.get(key, defaultValue);
549
+ if (!value) {
550
+ if (defaultValue === undefined) {
551
+ throw new Error("Email environment variable '".concat(key, "' is missing"));
552
+ }
553
+ return defaultValue;
554
+ }
555
+ // More comprehensive email validation regex
556
+ var emailRegex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
557
+ if (!emailRegex.test(value)) {
558
+ throw new Error("Environment variable '".concat(key, "' is not a valid email address: \"").concat(value, "\""));
559
+ }
560
+ this.cache.set("email:".concat(key), value);
561
+ return value;
562
+ };
563
+ /**
564
+ * Retrieves a path environment variable and validates it exists.
565
+ *
566
+ * @param {string} key - The environment variable key.
567
+ * @param {string} [defaultValue] - Optional fallback value.
568
+ * @param {PathOptions} [options] - Validation options.
569
+ * @returns {string} The validated path.
570
+ * @throws {Error} If path is invalid.
571
+ *
572
+ * @example
573
+ * // Require that the path exists and is a .json file
574
+ * const configPath = Env.getPath('CONFIG_PATH', './config.json', {
575
+ * mustExist: true,
576
+ * allowedExtensions: ['.json', '.yaml']
577
+ * });
578
+ */
579
+ Env.getPath = function (key, defaultValue, options) {
580
+ if (options === void 0) { options = {}; }
581
+ var cacheKey = "path:".concat(key, ":").concat(JSON.stringify(options));
582
+ if (this.cache.has(cacheKey)) {
583
+ return this.cache.get(cacheKey);
584
+ }
585
+ var value = Env.get(key, defaultValue);
586
+ if (!value) {
587
+ if (defaultValue === undefined) {
588
+ throw new Error("Path environment variable '".concat(key, "' is missing"));
589
+ }
590
+ return defaultValue;
591
+ }
592
+ var path = options.makeAbsolute !== false && !isAbsolute(value) ? resolve(process.cwd(), value) : value;
593
+ // Validate path exists if required
594
+ if (options.mustExist && !existsSync(path)) {
595
+ throw new Error("Path in environment variable '".concat(key, "' does not exist: \"").concat(path, "\""));
596
+ }
597
+ // Validate file extension if specified
598
+ if (options.allowedExtensions && options.allowedExtensions.length > 0) {
599
+ var hasValidExtension = options.allowedExtensions.some(function (ext) { return path.toLowerCase().endsWith(ext.toLowerCase()); });
600
+ if (!hasValidExtension) {
601
+ throw new Error("Path in environment variable '".concat(key, "' must have one of these extensions: ").concat(options.allowedExtensions.join(', '), ". Got: \"").concat(path, "\""));
602
+ }
603
+ }
604
+ this.cache.set(cacheKey, path);
605
+ return path;
606
+ };
607
+ /**
608
+ * Retrieves a port environment variable and validates it.
609
+ *
610
+ * @param {string} key - The environment variable key.
611
+ * @param {number} [defaultValue] - Optional fallback value.
612
+ * @returns {number} The validated port number.
613
+ * @throws {Error} If port is invalid.
614
+ *
615
+ * @example
616
+ * const serverPort = Env.getPort('PORT', 3000);
617
+ */
618
+ Env.getPort = function (key, defaultValue) {
619
+ try {
620
+ return Env.getInteger(key, defaultValue, { min: 0, max: 65535 });
621
+ }
622
+ catch (error) {
623
+ // Rewrite the error message to match the expected pattern
624
+ if (error.message.includes('must be at most 65535')) {
625
+ throw new Error("Environment variable '".concat(key, "' must be a valid port number (0-65535)"));
626
+ }
627
+ throw error;
628
+ }
629
+ };
630
+ /**
631
+ * Retrieves an ISO date string and converts it to a Date object.
632
+ *
633
+ * @param {string} key - The environment variable key.
634
+ * @param {string|Date} [defaultValue] - Optional fallback value.
635
+ * @returns {Date} The parsed Date object.
636
+ *
637
+ * @example
638
+ * // If EXPIRY_DATE=2023-12-31T23:59:59Z
639
+ * const expiryDate = Env.getDate('EXPIRY_DATE', new Date());
640
+ */
641
+ Env.getDate = function (key, defaultValue) {
642
+ if (defaultValue === void 0) { defaultValue = new Date(); }
643
+ var value = Env.get(key, defaultValue instanceof Date ? defaultValue.toISOString() : defaultValue);
644
+ if (!value) {
645
+ return defaultValue instanceof Date ? defaultValue : new Date();
646
+ }
647
+ var date = new Date(value);
648
+ if (isNaN(date.getTime())) {
649
+ throw new Error("Environment variable '".concat(key, "' is not a valid date: \"").concat(value, "\""));
650
+ }
651
+ return date;
652
+ };
653
+ /**
654
+ * Retrieves a duration string and converts it to milliseconds.
655
+ * Supports formats like "1d", "2h", "30m", "45s", "100ms" or combinations like "1h30m".
656
+ *
657
+ * @param {string} key - The environment variable key.
658
+ * @param {string|number} [defaultValue='0'] - Optional fallback value.
659
+ * @returns {number} The duration in milliseconds.
660
+ * @throws {Error} If duration format is invalid.
661
+ *
662
+ * @example
663
+ * // If CACHE_TTL=2h30m
664
+ * const cacheTtlMs = Env.getDuration('CACHE_TTL', '1h');
665
+ * // 9000000 (2.5 hours in milliseconds)
666
+ */
667
+ Env.getDuration = function (key, defaultValue) {
668
+ if (defaultValue === void 0) { defaultValue = '0'; }
669
+ var cacheKey = "duration:".concat(key);
670
+ if (this.cache.has(cacheKey)) {
671
+ return this.cache.get(cacheKey);
672
+ }
673
+ var value = Env.get(key, String(defaultValue));
674
+ if (!value)
675
+ return 0;
676
+ // Handle plain number input (assume milliseconds)
677
+ if (/^\d+$/.test(value)) {
678
+ var ms_1 = parseInt(value, 10);
679
+ this.cache.set(cacheKey, ms_1);
680
+ return ms_1;
681
+ }
682
+ // Enhanced duration parsing with more precise regex
683
+ var durationRegex = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?(?:(\d+)ms)?$/;
684
+ var matches = value.match(durationRegex);
685
+ if (!matches || matches[0] === '') {
686
+ throw new Error("Environment variable '".concat(key, "' has invalid duration format: \"").concat(value, "\". ") +
687
+ "Use formats like 1y, 2w, 3d, 4h, 5m, 6s, or 7ms.");
688
+ }
689
+ var ms = 0;
690
+ if (matches[1])
691
+ ms += parseInt(matches[1], 10) * 31536000000; // years (approximate)
692
+ if (matches[2])
693
+ ms += parseInt(matches[2], 10) * 604800000; // weeks
694
+ if (matches[3])
695
+ ms += parseInt(matches[3], 10) * 86400000; // days
696
+ if (matches[4])
697
+ ms += parseInt(matches[4], 10) * 3600000; // hours
698
+ if (matches[5])
699
+ ms += parseInt(matches[5], 10) * 60000; // minutes
700
+ if (matches[6])
701
+ ms += parseInt(matches[6], 10) * 1000; // seconds
702
+ if (matches[7])
703
+ ms += parseInt(matches[7], 10); // milliseconds
704
+ this.cache.set(cacheKey, ms);
705
+ return ms;
706
+ };
707
+ /**
708
+ * Gets all environment variables with sensitive values masked for safe logging.
709
+ *
710
+ * @param {string[]} [sensitiveKeys=['password', 'secret', 'key', 'token', 'auth']] - Keys to mask.
711
+ * @returns {Record<string, string>} Environment variables with sensitive values masked.
712
+ *
713
+ * @example
714
+ * console.log(Env.getSafeEnv(['password', 'secret', 'key']));
715
+ * // { DATABASE_URL: "postgres://...", API_KEY: "******", ... }
716
+ */
717
+ Env.getSafeEnv = function (sensitiveKeys) {
718
+ var e_2, _a;
719
+ if (sensitiveKeys === void 0) { sensitiveKeys = ['password', 'secret', 'key', 'token', 'auth']; }
720
+ var safeEnv = {};
721
+ var _loop_1 = function (key, value) {
722
+ if (!value)
723
+ return "continue";
724
+ var isSensitive = sensitiveKeys.some(function (sensitiveKey) { return key.toLowerCase().includes(sensitiveKey.toLowerCase()); });
725
+ safeEnv[key] = isSensitive ? '******' : value;
726
+ };
727
+ try {
728
+ for (var _b = __values(Object.entries(process.env)), _c = _b.next(); !_c.done; _c = _b.next()) {
729
+ var _d = __read(_c.value, 2), key = _d[0], value = _d[1];
730
+ _loop_1(key, value);
731
+ }
732
+ }
733
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
734
+ finally {
735
+ try {
736
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
737
+ }
738
+ finally { if (e_2) throw e_2.error; }
739
+ }
740
+ return safeEnv;
741
+ };
742
+ /**
743
+ * Loads environment variables from a .env file.
744
+ * Does not override existing variables.
745
+ *
746
+ * @param {string} [path='.env'] - Path to the .env file.
747
+ * @returns {Record<string, string>} Loaded environment variables.
748
+ *
749
+ * @example
750
+ * // Load variables from .env.development
751
+ * Env.loadFromFile('.env.development');
752
+ */
753
+ Env.loadFromFile = function (path) {
754
+ if (path === void 0) { path = '.env'; }
755
+ if (!existsSync(path)) {
756
+ throw new Error("Environment file not found: \"".concat(path, "\""));
757
+ }
758
+ var content = readFileSync(path, 'utf8');
759
+ var variables = {};
760
+ var lines = content.split(/\r?\n/);
761
+ var i = 0;
762
+ while (i < lines.length) {
763
+ var line = lines[i].trim();
764
+ // Skip empty lines or comment-only lines
765
+ if (!line || line.startsWith('#')) {
766
+ i++;
767
+ continue;
768
+ }
769
+ var match = line.match(/^([^=]+)=(.*)$/);
770
+ if (!match) {
771
+ i++;
772
+ continue;
773
+ }
774
+ var key = match[1].trim();
775
+ var value = match[2].trim();
776
+ // Remove inline comment for unquoted values
777
+ if (!/^['"]/.test(value)) {
778
+ var hashIndex = value.indexOf(' #');
779
+ if (hashIndex !== -1) {
780
+ value = value.slice(0, hashIndex).trim();
781
+ }
782
+ }
783
+ // Handle quoted values
784
+ if ((value.startsWith('"') || value.startsWith("'")) && value.length > 1) {
785
+ var quote = value[0];
786
+ if (!value.endsWith(quote) || value.length === 1) {
787
+ // multiline quoted
788
+ var multilineValue = value.slice(1);
789
+ i++;
790
+ while (i < lines.length) {
791
+ var nextLine = lines[i];
792
+ if (nextLine.endsWith(quote)) {
793
+ multilineValue += '\n' + nextLine.slice(0, -1);
794
+ break;
795
+ }
796
+ else {
797
+ multilineValue += '\n' + nextLine;
798
+ }
799
+ i++;
800
+ }
801
+ value = multilineValue;
802
+ }
803
+ else {
804
+ // single-line quoted
805
+ value = value.slice(1, -1);
806
+ }
807
+ }
808
+ else {
809
+ // Handle unquoted multiline: continue collecting until next key=value or empty line
810
+ i++;
811
+ while (i < lines.length && !lines[i].includes('=') && lines[i].trim() !== '') {
812
+ value += '\n' + lines[i];
813
+ i++;
814
+ }
815
+ i--; // adjust for outer loop
816
+ }
817
+ if (!process.env[key]) {
818
+ process.env[key] = value;
819
+ variables[key] = value;
820
+ }
821
+ i++;
822
+ }
823
+ return variables;
824
+ };
825
+ /**
826
+ * Checks whether the specified environment variable exists.
827
+ *
828
+ * @param {string} key - The environment variable key.
829
+ * @returns {boolean} `true` if the variable is defined, otherwise `false`.
830
+ */
831
+ Env.has = function (key) {
832
+ return process.env[key] !== undefined;
833
+ };
834
+ /**
835
+ * Deletes the given environment variable (useful in tests).
836
+ *
837
+ * @param {string} key - The environment variable key to delete.
838
+ * @returns {void}
839
+ */
840
+ Env.delete = function (key) {
841
+ var e_3, _a;
842
+ delete process.env[key];
843
+ this.cache.delete(key);
844
+ try {
845
+ // Also clear all cached variations of this key
846
+ for (var _b = __values(this.cache.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
847
+ var cacheKey = _c.value;
848
+ if (cacheKey.includes(":".concat(key))) {
849
+ this.cache.delete(cacheKey);
850
+ }
851
+ }
852
+ }
853
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
854
+ finally {
855
+ try {
856
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
857
+ }
858
+ finally { if (e_3) throw e_3.error; }
859
+ }
860
+ };
861
+ /**
862
+ * Clears the internal cache of parsed environment values.
863
+ * Useful for testing or when environment variables might change.
864
+ */
865
+ Env.clearCache = function () {
866
+ this.cache.clear();
867
+ };
868
+ // Cache for parsed values to avoid repeated parsing of complex values
869
+ Env.cache = new Map();
870
+ return Env;
871
+ }());
872
+ export { Env };
873
+ //# sourceMappingURL=env.utils.js.map