@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.2

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