envapt 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +206 -0
- package/README.md +3 -3
- package/dist/index.cjs +104 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +104 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -30
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ var __defProp = Object.defineProperty;
|
|
|
13
13
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
14
14
|
|
|
15
15
|
// src/Error.ts
|
|
16
|
-
var EnvaptErrorCodes = /* @__PURE__ */ ((EnvaptErrorCodes2)
|
|
16
|
+
var EnvaptErrorCodes = /* @__PURE__ */ (function(EnvaptErrorCodes2) {
|
|
17
17
|
EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidFallback"] = 101] = "InvalidFallback";
|
|
18
18
|
EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidFallbackType"] = 102] = "InvalidFallbackType";
|
|
19
19
|
EnvaptErrorCodes2[EnvaptErrorCodes2["ArrayFallbackElementTypeMismatch"] = 103] = "ArrayFallbackElementTypeMismatch";
|
|
@@ -28,7 +28,7 @@ var EnvaptErrorCodes = /* @__PURE__ */ ((EnvaptErrorCodes2) => {
|
|
|
28
28
|
EnvaptErrorCodes2[EnvaptErrorCodes2["EnvFilesNotFound"] = 303] = "EnvFilesNotFound";
|
|
29
29
|
EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidKeyInput"] = 304] = "InvalidKeyInput";
|
|
30
30
|
return EnvaptErrorCodes2;
|
|
31
|
-
})(
|
|
31
|
+
})({});
|
|
32
32
|
var EnvaptError = class extends Error {
|
|
33
33
|
static {
|
|
34
34
|
__name(this, "EnvaptError");
|
|
@@ -103,19 +103,18 @@ var Validator = class {
|
|
|
103
103
|
*/
|
|
104
104
|
static isValidArrayConverterType(value) {
|
|
105
105
|
if (typeof value !== "string") return false;
|
|
106
|
-
const invalidTypes = [
|
|
106
|
+
const invalidTypes = [
|
|
107
|
+
"array",
|
|
108
|
+
"json",
|
|
109
|
+
"regexp"
|
|
110
|
+
];
|
|
107
111
|
if (invalidTypes.includes(value)) return false;
|
|
108
|
-
const validTypes = ListOfBuiltInConverters.filter(
|
|
109
|
-
(type) => !invalidTypes.includes(type)
|
|
110
|
-
);
|
|
112
|
+
const validTypes = ListOfBuiltInConverters.filter((type) => !invalidTypes.includes(type));
|
|
111
113
|
return validTypes.includes(value);
|
|
112
114
|
}
|
|
113
115
|
static customConvertor(converter) {
|
|
114
116
|
if (typeof converter !== "function") {
|
|
115
|
-
throw new EnvaptError(
|
|
116
|
-
203 /* InvalidCustomConverter */,
|
|
117
|
-
`Custom converter must be a function, got ${typeof converter}.`
|
|
118
|
-
);
|
|
117
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidCustomConverter, `Custom converter must be a function, got ${typeof converter}.`);
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
/**
|
|
@@ -123,13 +122,10 @@ var Validator = class {
|
|
|
123
122
|
*/
|
|
124
123
|
static arrayConverter(value) {
|
|
125
124
|
if (!this.isArrayConverter(value)) {
|
|
126
|
-
throw new EnvaptError(
|
|
125
|
+
throw new EnvaptError(EnvaptErrorCodes.MissingDelimiter, "Must have delimiter property");
|
|
127
126
|
}
|
|
128
127
|
if (value.type !== void 0 && !this.isValidArrayConverterType(value.type)) {
|
|
129
|
-
throw new EnvaptError(
|
|
130
|
-
201 /* InvalidArrayConverterType */,
|
|
131
|
-
`"${value.type}" is not a valid converter type`
|
|
132
|
-
);
|
|
128
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidArrayConverterType, `"${value.type}" is not a valid converter type`);
|
|
133
129
|
}
|
|
134
130
|
}
|
|
135
131
|
/**
|
|
@@ -137,13 +133,10 @@ var Validator = class {
|
|
|
137
133
|
*/
|
|
138
134
|
static builtInConverter(value) {
|
|
139
135
|
if (typeof value !== "string") {
|
|
140
|
-
throw new EnvaptError(
|
|
136
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);
|
|
141
137
|
}
|
|
142
138
|
if (!ListOfBuiltInConverters.includes(value)) {
|
|
143
|
-
throw new EnvaptError(
|
|
144
|
-
202 /* InvalidBuiltInConverter */,
|
|
145
|
-
`"${value}" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(",")}`
|
|
146
|
-
);
|
|
139
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidBuiltInConverter, `"${value}" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(",")}`);
|
|
147
140
|
}
|
|
148
141
|
}
|
|
149
142
|
/**
|
|
@@ -152,10 +145,7 @@ var Validator = class {
|
|
|
152
145
|
static validateBuiltInConverterFallback(converter, fallback) {
|
|
153
146
|
const typeChecker = BuiltInConverterTypeCheckers[converter];
|
|
154
147
|
if (!typeChecker(fallback)) {
|
|
155
|
-
throw new EnvaptError(
|
|
156
|
-
104 /* FallbackConverterTypeMismatch */,
|
|
157
|
-
`Fallback type does not match converter "${converter}". Expected ${converter} compatible type.`
|
|
158
|
-
);
|
|
148
|
+
throw new EnvaptError(EnvaptErrorCodes.FallbackConverterTypeMismatch, `Fallback type does not match converter "${converter}". Expected ${converter} compatible type.`);
|
|
159
149
|
}
|
|
160
150
|
}
|
|
161
151
|
/**
|
|
@@ -169,10 +159,7 @@ var Validator = class {
|
|
|
169
159
|
return typeof element !== firstElementType;
|
|
170
160
|
});
|
|
171
161
|
if (hasInconsistentTypes) {
|
|
172
|
-
throw new EnvaptError(
|
|
173
|
-
103 /* ArrayFallbackElementTypeMismatch */,
|
|
174
|
-
`All elements in array fallback must have the same type. Found mixed types.`
|
|
175
|
-
);
|
|
162
|
+
throw new EnvaptError(EnvaptErrorCodes.ArrayFallbackElementTypeMismatch, `All elements in array fallback must have the same type. Found mixed types.`);
|
|
176
163
|
}
|
|
177
164
|
}
|
|
178
165
|
/**
|
|
@@ -183,10 +170,7 @@ var Validator = class {
|
|
|
183
170
|
const firstElement = fallback[0];
|
|
184
171
|
const typeChecker = BuiltInConverterTypeCheckers[converterType];
|
|
185
172
|
if (!typeChecker(firstElement)) {
|
|
186
|
-
throw new EnvaptError(
|
|
187
|
-
103 /* ArrayFallbackElementTypeMismatch */,
|
|
188
|
-
`Array converter type "${converterType}" does not match fallback element type. Expected ${converterType} compatible elements.`
|
|
189
|
-
);
|
|
173
|
+
throw new EnvaptError(EnvaptErrorCodes.ArrayFallbackElementTypeMismatch, `Array converter type "${converterType}" does not match fallback element type. Expected ${converterType} compatible elements.`);
|
|
190
174
|
}
|
|
191
175
|
}
|
|
192
176
|
/**
|
|
@@ -224,33 +208,27 @@ var Validator = class {
|
|
|
224
208
|
if (converter === BigInt) return BigInt(fallback);
|
|
225
209
|
if (converter === Symbol) return Symbol.for(String(fallback));
|
|
226
210
|
} catch (error) {
|
|
227
|
-
throw new EnvaptError(
|
|
228
|
-
205 /* PrimitiveCoercionFailed */,
|
|
229
|
-
`Failed to coerce fallback value using ${converter.name}: ${error.message}`
|
|
230
|
-
);
|
|
211
|
+
throw new EnvaptError(EnvaptErrorCodes.PrimitiveCoercionFailed, `Failed to coerce fallback value using ${converter.name}: ${error.message}`);
|
|
231
212
|
}
|
|
232
|
-
throw new EnvaptError(
|
|
233
|
-
205 /* PrimitiveCoercionFailed */,
|
|
234
|
-
`Unknown primitive converter: ${converter.name}`
|
|
235
|
-
);
|
|
213
|
+
throw new EnvaptError(EnvaptErrorCodes.PrimitiveCoercionFailed, `Unknown primitive converter: ${converter.name}`);
|
|
236
214
|
}
|
|
237
215
|
/**
|
|
238
216
|
* Make sure the user hasn't provided prohibited options in their dotenv config
|
|
239
217
|
*/
|
|
240
218
|
static validateDotenvConfig(config2) {
|
|
241
219
|
if ("path" in config2 || "processEnv" in config2) {
|
|
242
|
-
throw new EnvaptError(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
220
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidUserDefinedConfig, 'Custom dotenvConfig should not include "path" or "processEnv" options. Those are managed by Envapter.');
|
|
221
|
+
}
|
|
222
|
+
const validKeys = /* @__PURE__ */ new Set([
|
|
223
|
+
"encoding",
|
|
224
|
+
"quiet",
|
|
225
|
+
"debug",
|
|
226
|
+
"override",
|
|
227
|
+
"DOTENV_KEY"
|
|
228
|
+
]);
|
|
248
229
|
const invalidKeys = Object.keys(config2).filter((key) => !validKeys.has(key));
|
|
249
230
|
if (invalidKeys.length > 0) {
|
|
250
|
-
throw new EnvaptError(
|
|
251
|
-
302 /* InvalidUserDefinedConfig */,
|
|
252
|
-
`Invalid dotenvConfig options: ${invalidKeys.join(", ")}. Allowed options: ${Array.from(validKeys).join(", ")}`
|
|
253
|
-
);
|
|
231
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidUserDefinedConfig, `Invalid dotenvConfig options: ${invalidKeys.join(", ")}. Allowed options: ${Array.from(validKeys).join(", ")}`);
|
|
254
232
|
}
|
|
255
233
|
return true;
|
|
256
234
|
}
|
|
@@ -267,10 +245,7 @@ var Validator = class {
|
|
|
267
245
|
}
|
|
268
246
|
});
|
|
269
247
|
if (missing.length > 0) {
|
|
270
|
-
throw new EnvaptError(
|
|
271
|
-
303 /* EnvFilesNotFound */,
|
|
272
|
-
`Environment file not found at path: ${missing.join(", ")}`
|
|
273
|
-
);
|
|
248
|
+
throw new EnvaptError(EnvaptErrorCodes.EnvFilesNotFound, `Environment file not found at path: ${missing.join(", ")}`);
|
|
274
249
|
}
|
|
275
250
|
}
|
|
276
251
|
};
|
|
@@ -281,15 +256,20 @@ var EnvapterBase = class _EnvapterBase {
|
|
|
281
256
|
static {
|
|
282
257
|
__name(this, "EnvapterBase");
|
|
283
258
|
}
|
|
284
|
-
static _envPaths = [
|
|
285
|
-
|
|
286
|
-
|
|
259
|
+
static _envPaths = [
|
|
260
|
+
".env"
|
|
261
|
+
];
|
|
262
|
+
static _userDefinedDotenvConfig = {
|
|
263
|
+
quiet: true
|
|
264
|
+
};
|
|
287
265
|
/**
|
|
288
266
|
* Set custom .env file paths. Accepts either a single path or array of paths.
|
|
289
267
|
* Setting new paths clears the cache and reloads environment variables.
|
|
290
268
|
*/
|
|
291
269
|
static set envPaths(paths) {
|
|
292
|
-
const newPaths = Array.isArray(paths) ? paths : [
|
|
270
|
+
const newPaths = Array.isArray(paths) ? paths : [
|
|
271
|
+
paths
|
|
272
|
+
];
|
|
293
273
|
Validator.validateEnvFilesExist(newPaths);
|
|
294
274
|
this._envPaths = newPaths;
|
|
295
275
|
this.refreshCache();
|
|
@@ -319,30 +299,44 @@ var EnvapterBase = class _EnvapterBase {
|
|
|
319
299
|
void this.config;
|
|
320
300
|
}
|
|
321
301
|
static resolveKeyInput(keyInput) {
|
|
322
|
-
const keys = Array.isArray(keyInput) ? keyInput : [
|
|
302
|
+
const keys = Array.isArray(keyInput) ? keyInput : [
|
|
303
|
+
keyInput
|
|
304
|
+
];
|
|
323
305
|
const normalizedKeys = keys;
|
|
324
306
|
if (normalizedKeys.length === 0) {
|
|
325
|
-
throw new EnvaptError(
|
|
307
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "At least one environment key must be provided.");
|
|
326
308
|
}
|
|
327
309
|
if (normalizedKeys.some((k) => typeof k !== "string")) {
|
|
328
|
-
throw new EnvaptError(
|
|
310
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "Environment keys must be strings.");
|
|
329
311
|
}
|
|
330
312
|
if (normalizedKeys.some((k) => k.trim() === "")) {
|
|
331
|
-
throw new EnvaptError(
|
|
313
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "Environment keys cannot be empty strings.");
|
|
332
314
|
}
|
|
333
315
|
for (const candidate of normalizedKeys) {
|
|
334
316
|
const value = this.config.get(candidate);
|
|
335
317
|
if (value !== void 0) {
|
|
336
|
-
return {
|
|
318
|
+
return {
|
|
319
|
+
key: candidate,
|
|
320
|
+
value
|
|
321
|
+
};
|
|
337
322
|
}
|
|
338
323
|
}
|
|
339
|
-
return {
|
|
324
|
+
return {
|
|
325
|
+
key: normalizedKeys[0],
|
|
326
|
+
value: void 0
|
|
327
|
+
};
|
|
340
328
|
}
|
|
341
329
|
static get config() {
|
|
342
330
|
if (EnvaptCache.size === 0) {
|
|
343
|
-
const isolatedEnv = {
|
|
331
|
+
const isolatedEnv = {
|
|
332
|
+
...process__default.default.env
|
|
333
|
+
};
|
|
344
334
|
try {
|
|
345
|
-
dotenv.config({
|
|
335
|
+
dotenv.config({
|
|
336
|
+
path: this._envPaths,
|
|
337
|
+
processEnv: isolatedEnv,
|
|
338
|
+
...this._userDefinedDotenvConfig
|
|
339
|
+
});
|
|
346
340
|
} catch {
|
|
347
341
|
}
|
|
348
342
|
for (const [key, value] of Object.entries(isolatedEnv)) EnvaptCache.set(key, value);
|
|
@@ -371,8 +365,18 @@ var BuiltInConverters = class _BuiltInConverters {
|
|
|
371
365
|
}
|
|
372
366
|
static boolean(raw, fallback) {
|
|
373
367
|
const lower = raw.toLowerCase().trim();
|
|
374
|
-
const truthyValues = [
|
|
375
|
-
|
|
368
|
+
const truthyValues = [
|
|
369
|
+
"1",
|
|
370
|
+
"yes",
|
|
371
|
+
"true",
|
|
372
|
+
"on"
|
|
373
|
+
];
|
|
374
|
+
const falsyValues = [
|
|
375
|
+
"0",
|
|
376
|
+
"no",
|
|
377
|
+
"false",
|
|
378
|
+
"off"
|
|
379
|
+
];
|
|
376
380
|
if (truthyValues.includes(lower)) return true;
|
|
377
381
|
if (falsyValues.includes(lower)) return false;
|
|
378
382
|
return fallback;
|
|
@@ -496,13 +500,14 @@ var BuiltInConverters = class _BuiltInConverters {
|
|
|
496
500
|
|
|
497
501
|
// src/Parser.ts
|
|
498
502
|
var Parser = class {
|
|
499
|
-
constructor(envService) {
|
|
500
|
-
this.envService = envService;
|
|
501
|
-
}
|
|
502
503
|
static {
|
|
503
504
|
__name(this, "Parser");
|
|
504
505
|
}
|
|
506
|
+
envService;
|
|
505
507
|
TEMPLATE_REGEX = /\${\w*}/g;
|
|
508
|
+
constructor(envService) {
|
|
509
|
+
this.envService = envService;
|
|
510
|
+
}
|
|
506
511
|
/**
|
|
507
512
|
* Resolve template variables in a string while handling circular references and missing variables
|
|
508
513
|
* @internal
|
|
@@ -549,7 +554,7 @@ var Parser = class {
|
|
|
549
554
|
if (primitiveConstructor === Boolean) return "boolean";
|
|
550
555
|
if (primitiveConstructor === BigInt) return "bigint";
|
|
551
556
|
if (primitiveConstructor === Symbol) return "symbol";
|
|
552
|
-
throw new EnvaptError(
|
|
557
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Unknown primitive constructor`);
|
|
553
558
|
}
|
|
554
559
|
processBuiltInConverter(key, fallback, resolvedConverter, hasFallback, wasOriginallyConstructor) {
|
|
555
560
|
Validator.builtInConverter(resolvedConverter);
|
|
@@ -569,10 +574,7 @@ var Parser = class {
|
|
|
569
574
|
processArrayConverter(key, fallback, resolvedConverter, hasFallback) {
|
|
570
575
|
Validator.arrayConverter(resolvedConverter);
|
|
571
576
|
if (hasFallback && fallback !== void 0 && !Array.isArray(fallback)) {
|
|
572
|
-
throw new EnvaptError(
|
|
573
|
-
101 /* InvalidFallback */,
|
|
574
|
-
`ArrayConverter requires that the fallback be an array, got ${typeof fallback}`
|
|
575
|
-
);
|
|
577
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, `ArrayConverter requires that the fallback be an array, got ${typeof fallback}`);
|
|
576
578
|
}
|
|
577
579
|
if (hasFallback && Array.isArray(fallback)) {
|
|
578
580
|
Validator.validateArrayFallbackElementTypes(fallback);
|
|
@@ -603,12 +605,12 @@ var Parser = class {
|
|
|
603
605
|
};
|
|
604
606
|
|
|
605
607
|
// src/core/EnvironmentMethods.ts
|
|
606
|
-
var Environment = /* @__PURE__ */ ((Environment2)
|
|
608
|
+
var Environment = /* @__PURE__ */ (function(Environment2) {
|
|
607
609
|
Environment2[Environment2["Development"] = 0] = "Development";
|
|
608
610
|
Environment2[Environment2["Staging"] = 1] = "Staging";
|
|
609
611
|
Environment2[Environment2["Production"] = 2] = "Production";
|
|
610
612
|
return Environment2;
|
|
611
|
-
})(
|
|
613
|
+
})({});
|
|
612
614
|
var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
|
|
613
615
|
static {
|
|
614
616
|
__name(this, "EnvironmentMethods");
|
|
@@ -617,7 +619,7 @@ var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
|
|
|
617
619
|
static determineEnvironment(env) {
|
|
618
620
|
const environment = env ?? this.getRawValue("ENVIRONMENT", this.getRawValue("ENV", this.getRawValue("NODE_ENV", "development")));
|
|
619
621
|
if (typeof environment === "string") {
|
|
620
|
-
this._environment = environment.toLowerCase() === "production" ? 2
|
|
622
|
+
this._environment = environment.toLowerCase() === "production" ? 2 : environment === "staging" ? 1 : 0;
|
|
621
623
|
} else {
|
|
622
624
|
this._environment = environment;
|
|
623
625
|
}
|
|
@@ -656,37 +658,37 @@ var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
|
|
|
656
658
|
* Check if the current environment is production
|
|
657
659
|
*/
|
|
658
660
|
static get isProduction() {
|
|
659
|
-
return this.environment === 2
|
|
661
|
+
return this.environment === 2;
|
|
660
662
|
}
|
|
661
663
|
/**
|
|
662
664
|
* @see {@link EnvironmentMethods.isProduction}
|
|
663
665
|
*/
|
|
664
666
|
get isProduction() {
|
|
665
|
-
return _EnvironmentMethods.environment === 2
|
|
667
|
+
return _EnvironmentMethods.environment === 2;
|
|
666
668
|
}
|
|
667
669
|
/**
|
|
668
670
|
* Check if the current environment is staging
|
|
669
671
|
*/
|
|
670
672
|
static get isStaging() {
|
|
671
|
-
return this.environment === 1
|
|
673
|
+
return this.environment === 1;
|
|
672
674
|
}
|
|
673
675
|
/**
|
|
674
676
|
* @see {@link EnvironmentMethods.isStaging}
|
|
675
677
|
*/
|
|
676
678
|
get isStaging() {
|
|
677
|
-
return _EnvironmentMethods.environment === 1
|
|
679
|
+
return _EnvironmentMethods.environment === 1;
|
|
678
680
|
}
|
|
679
681
|
/**
|
|
680
682
|
* Check if the current environment is development
|
|
681
683
|
*/
|
|
682
684
|
static get isDevelopment() {
|
|
683
|
-
return this.environment === 0
|
|
685
|
+
return this.environment === 0;
|
|
684
686
|
}
|
|
685
687
|
/**
|
|
686
688
|
* @see {@link EnvironmentMethods.isDevelopment}
|
|
687
689
|
*/
|
|
688
690
|
get isDevelopment() {
|
|
689
|
-
return _EnvironmentMethods.environment === 0
|
|
691
|
+
return _EnvironmentMethods.environment === 0;
|
|
690
692
|
}
|
|
691
693
|
static refreshCache() {
|
|
692
694
|
super.refreshCache();
|
|
@@ -706,13 +708,10 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
706
708
|
if (!rawVal) return def;
|
|
707
709
|
const parsed = this.parser.resolveTemplate(resolvedKey, String(rawVal));
|
|
708
710
|
let result;
|
|
709
|
-
if (type === 1
|
|
710
|
-
else if (type === 2
|
|
711
|
-
|
|
712
|
-
else if (type ===
|
|
713
|
-
result = BuiltInConverters.bigint(parsed, def);
|
|
714
|
-
else if (type === 4 /* Symbol */)
|
|
715
|
-
result = BuiltInConverters.symbol(parsed, def);
|
|
711
|
+
if (type === 1) result = BuiltInConverters.number(parsed, def);
|
|
712
|
+
else if (type === 2) result = BuiltInConverters.boolean(parsed, def);
|
|
713
|
+
else if (type === 3) result = BuiltInConverters.bigint(parsed, def);
|
|
714
|
+
else if (type === 4) result = BuiltInConverters.symbol(parsed, def);
|
|
716
715
|
else result = BuiltInConverters.string(parsed, def);
|
|
717
716
|
return result;
|
|
718
717
|
}
|
|
@@ -722,10 +721,10 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
722
721
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
723
722
|
*/
|
|
724
723
|
static get(key, def) {
|
|
725
|
-
return this._get(key, 0
|
|
724
|
+
return this._get(key, 0, def);
|
|
726
725
|
}
|
|
727
726
|
get(key, def) {
|
|
728
|
-
return _PrimitiveMethods._get(key, 0
|
|
727
|
+
return _PrimitiveMethods._get(key, 0, def);
|
|
729
728
|
}
|
|
730
729
|
/**
|
|
731
730
|
* Get a number environment variable with optional fallback.
|
|
@@ -733,13 +732,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
733
732
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
734
733
|
*/
|
|
735
734
|
static getNumber(key, def) {
|
|
736
|
-
return this._get(key, 1
|
|
735
|
+
return this._get(key, 1, def);
|
|
737
736
|
}
|
|
738
737
|
/**
|
|
739
738
|
* @see {@link PrimitiveMethods.getNumber}
|
|
740
739
|
*/
|
|
741
740
|
getNumber(key, def) {
|
|
742
|
-
return _PrimitiveMethods._get(key, 1
|
|
741
|
+
return _PrimitiveMethods._get(key, 1, def);
|
|
743
742
|
}
|
|
744
743
|
/**
|
|
745
744
|
* Get a boolean environment variable with optional fallback.
|
|
@@ -747,13 +746,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
747
746
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
748
747
|
*/
|
|
749
748
|
static getBoolean(key, def) {
|
|
750
|
-
return this._get(key, 2
|
|
749
|
+
return this._get(key, 2, def);
|
|
751
750
|
}
|
|
752
751
|
/**
|
|
753
752
|
* @see {@link PrimitiveMethods.getBoolean}
|
|
754
753
|
*/
|
|
755
754
|
getBoolean(key, def) {
|
|
756
|
-
return _PrimitiveMethods._get(key, 2
|
|
755
|
+
return _PrimitiveMethods._get(key, 2, def);
|
|
757
756
|
}
|
|
758
757
|
/**
|
|
759
758
|
* Get a bigint environment variable with optional fallback.
|
|
@@ -761,13 +760,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
761
760
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
762
761
|
*/
|
|
763
762
|
static getBigInt(key, def) {
|
|
764
|
-
return this._get(key, 3
|
|
763
|
+
return this._get(key, 3, def);
|
|
765
764
|
}
|
|
766
765
|
/**
|
|
767
766
|
* @see {@link PrimitiveMethods.getBigInt}
|
|
768
767
|
*/
|
|
769
768
|
getBigInt(key, def) {
|
|
770
|
-
return _PrimitiveMethods._get(key, 3
|
|
769
|
+
return _PrimitiveMethods._get(key, 3, def);
|
|
771
770
|
}
|
|
772
771
|
/**
|
|
773
772
|
* Get a symbol environment variable with optional fallback.
|
|
@@ -775,13 +774,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
775
774
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
776
775
|
*/
|
|
777
776
|
static getSymbol(key, def) {
|
|
778
|
-
return this._get(key, 4
|
|
777
|
+
return this._get(key, 4, def);
|
|
779
778
|
}
|
|
780
779
|
/**
|
|
781
780
|
* @see {@link PrimitiveMethods.getSymbol}
|
|
782
781
|
*/
|
|
783
782
|
getSymbol(key, def) {
|
|
784
|
-
return _PrimitiveMethods._get(key, 4
|
|
783
|
+
return _PrimitiveMethods._get(key, 4, def);
|
|
785
784
|
}
|
|
786
785
|
};
|
|
787
786
|
|
|
@@ -808,12 +807,7 @@ var AdvancedMethods = class _AdvancedMethods extends PrimitiveMethods {
|
|
|
808
807
|
const { key: resolvedKey, value } = this.resolveKeyInput(key);
|
|
809
808
|
if (!value) return fallback;
|
|
810
809
|
const hasFallback = fallback !== void 0;
|
|
811
|
-
const result = this.parser.convertValue(
|
|
812
|
-
resolvedKey,
|
|
813
|
-
fallback,
|
|
814
|
-
converter,
|
|
815
|
-
hasFallback
|
|
816
|
-
);
|
|
810
|
+
const result = this.parser.convertValue(resolvedKey, fallback, converter, hasFallback);
|
|
817
811
|
return result;
|
|
818
812
|
}
|
|
819
813
|
/**
|
|
@@ -900,7 +894,7 @@ function Envapt(key, fallbackOrOptions, converter) {
|
|
|
900
894
|
__name(Envapt, "Envapt");
|
|
901
895
|
|
|
902
896
|
// src/Converters.ts
|
|
903
|
-
var Converters = /* @__PURE__ */ ((Converters2)
|
|
897
|
+
var Converters = /* @__PURE__ */ (function(Converters2) {
|
|
904
898
|
Converters2["String"] = "string";
|
|
905
899
|
Converters2["Number"] = "number";
|
|
906
900
|
Converters2["Boolean"] = "boolean";
|
|
@@ -915,7 +909,7 @@ var Converters = /* @__PURE__ */ ((Converters2) => {
|
|
|
915
909
|
Converters2["Date"] = "date";
|
|
916
910
|
Converters2["Time"] = "time";
|
|
917
911
|
return Converters2;
|
|
918
|
-
})(
|
|
912
|
+
})({});
|
|
919
913
|
/* v8 ignore next -- @preserve */
|
|
920
914
|
|
|
921
915
|
exports.Converters = Converters;
|