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.mjs
CHANGED
|
@@ -6,7 +6,7 @@ var __defProp = Object.defineProperty;
|
|
|
6
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
7
|
|
|
8
8
|
// src/Error.ts
|
|
9
|
-
var EnvaptErrorCodes = /* @__PURE__ */ ((EnvaptErrorCodes2)
|
|
9
|
+
var EnvaptErrorCodes = /* @__PURE__ */ (function(EnvaptErrorCodes2) {
|
|
10
10
|
EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidFallback"] = 101] = "InvalidFallback";
|
|
11
11
|
EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidFallbackType"] = 102] = "InvalidFallbackType";
|
|
12
12
|
EnvaptErrorCodes2[EnvaptErrorCodes2["ArrayFallbackElementTypeMismatch"] = 103] = "ArrayFallbackElementTypeMismatch";
|
|
@@ -21,7 +21,7 @@ var EnvaptErrorCodes = /* @__PURE__ */ ((EnvaptErrorCodes2) => {
|
|
|
21
21
|
EnvaptErrorCodes2[EnvaptErrorCodes2["EnvFilesNotFound"] = 303] = "EnvFilesNotFound";
|
|
22
22
|
EnvaptErrorCodes2[EnvaptErrorCodes2["InvalidKeyInput"] = 304] = "InvalidKeyInput";
|
|
23
23
|
return EnvaptErrorCodes2;
|
|
24
|
-
})(
|
|
24
|
+
})({});
|
|
25
25
|
var EnvaptError = class extends Error {
|
|
26
26
|
static {
|
|
27
27
|
__name(this, "EnvaptError");
|
|
@@ -96,19 +96,18 @@ var Validator = class {
|
|
|
96
96
|
*/
|
|
97
97
|
static isValidArrayConverterType(value) {
|
|
98
98
|
if (typeof value !== "string") return false;
|
|
99
|
-
const invalidTypes = [
|
|
99
|
+
const invalidTypes = [
|
|
100
|
+
"array",
|
|
101
|
+
"json",
|
|
102
|
+
"regexp"
|
|
103
|
+
];
|
|
100
104
|
if (invalidTypes.includes(value)) return false;
|
|
101
|
-
const validTypes = ListOfBuiltInConverters.filter(
|
|
102
|
-
(type) => !invalidTypes.includes(type)
|
|
103
|
-
);
|
|
105
|
+
const validTypes = ListOfBuiltInConverters.filter((type) => !invalidTypes.includes(type));
|
|
104
106
|
return validTypes.includes(value);
|
|
105
107
|
}
|
|
106
108
|
static customConvertor(converter) {
|
|
107
109
|
if (typeof converter !== "function") {
|
|
108
|
-
throw new EnvaptError(
|
|
109
|
-
203 /* InvalidCustomConverter */,
|
|
110
|
-
`Custom converter must be a function, got ${typeof converter}.`
|
|
111
|
-
);
|
|
110
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidCustomConverter, `Custom converter must be a function, got ${typeof converter}.`);
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
@@ -116,13 +115,10 @@ var Validator = class {
|
|
|
116
115
|
*/
|
|
117
116
|
static arrayConverter(value) {
|
|
118
117
|
if (!this.isArrayConverter(value)) {
|
|
119
|
-
throw new EnvaptError(
|
|
118
|
+
throw new EnvaptError(EnvaptErrorCodes.MissingDelimiter, "Must have delimiter property");
|
|
120
119
|
}
|
|
121
120
|
if (value.type !== void 0 && !this.isValidArrayConverterType(value.type)) {
|
|
122
|
-
throw new EnvaptError(
|
|
123
|
-
201 /* InvalidArrayConverterType */,
|
|
124
|
-
`"${value.type}" is not a valid converter type`
|
|
125
|
-
);
|
|
121
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidArrayConverterType, `"${value.type}" is not a valid converter type`);
|
|
126
122
|
}
|
|
127
123
|
}
|
|
128
124
|
/**
|
|
@@ -130,13 +126,10 @@ var Validator = class {
|
|
|
130
126
|
*/
|
|
131
127
|
static builtInConverter(value) {
|
|
132
128
|
if (typeof value !== "string") {
|
|
133
|
-
throw new EnvaptError(
|
|
129
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Expected string, got ${typeof value}`);
|
|
134
130
|
}
|
|
135
131
|
if (!ListOfBuiltInConverters.includes(value)) {
|
|
136
|
-
throw new EnvaptError(
|
|
137
|
-
202 /* InvalidBuiltInConverter */,
|
|
138
|
-
`"${value}" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(",")}`
|
|
139
|
-
);
|
|
132
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidBuiltInConverter, `"${value}" is not a valid converter type. Valid types are: ${ListOfBuiltInConverters.join(",")}`);
|
|
140
133
|
}
|
|
141
134
|
}
|
|
142
135
|
/**
|
|
@@ -145,10 +138,7 @@ var Validator = class {
|
|
|
145
138
|
static validateBuiltInConverterFallback(converter, fallback) {
|
|
146
139
|
const typeChecker = BuiltInConverterTypeCheckers[converter];
|
|
147
140
|
if (!typeChecker(fallback)) {
|
|
148
|
-
throw new EnvaptError(
|
|
149
|
-
104 /* FallbackConverterTypeMismatch */,
|
|
150
|
-
`Fallback type does not match converter "${converter}". Expected ${converter} compatible type.`
|
|
151
|
-
);
|
|
141
|
+
throw new EnvaptError(EnvaptErrorCodes.FallbackConverterTypeMismatch, `Fallback type does not match converter "${converter}". Expected ${converter} compatible type.`);
|
|
152
142
|
}
|
|
153
143
|
}
|
|
154
144
|
/**
|
|
@@ -162,10 +152,7 @@ var Validator = class {
|
|
|
162
152
|
return typeof element !== firstElementType;
|
|
163
153
|
});
|
|
164
154
|
if (hasInconsistentTypes) {
|
|
165
|
-
throw new EnvaptError(
|
|
166
|
-
103 /* ArrayFallbackElementTypeMismatch */,
|
|
167
|
-
`All elements in array fallback must have the same type. Found mixed types.`
|
|
168
|
-
);
|
|
155
|
+
throw new EnvaptError(EnvaptErrorCodes.ArrayFallbackElementTypeMismatch, `All elements in array fallback must have the same type. Found mixed types.`);
|
|
169
156
|
}
|
|
170
157
|
}
|
|
171
158
|
/**
|
|
@@ -176,10 +163,7 @@ var Validator = class {
|
|
|
176
163
|
const firstElement = fallback[0];
|
|
177
164
|
const typeChecker = BuiltInConverterTypeCheckers[converterType];
|
|
178
165
|
if (!typeChecker(firstElement)) {
|
|
179
|
-
throw new EnvaptError(
|
|
180
|
-
103 /* ArrayFallbackElementTypeMismatch */,
|
|
181
|
-
`Array converter type "${converterType}" does not match fallback element type. Expected ${converterType} compatible elements.`
|
|
182
|
-
);
|
|
166
|
+
throw new EnvaptError(EnvaptErrorCodes.ArrayFallbackElementTypeMismatch, `Array converter type "${converterType}" does not match fallback element type. Expected ${converterType} compatible elements.`);
|
|
183
167
|
}
|
|
184
168
|
}
|
|
185
169
|
/**
|
|
@@ -217,33 +201,27 @@ var Validator = class {
|
|
|
217
201
|
if (converter === BigInt) return BigInt(fallback);
|
|
218
202
|
if (converter === Symbol) return Symbol.for(String(fallback));
|
|
219
203
|
} catch (error) {
|
|
220
|
-
throw new EnvaptError(
|
|
221
|
-
205 /* PrimitiveCoercionFailed */,
|
|
222
|
-
`Failed to coerce fallback value using ${converter.name}: ${error.message}`
|
|
223
|
-
);
|
|
204
|
+
throw new EnvaptError(EnvaptErrorCodes.PrimitiveCoercionFailed, `Failed to coerce fallback value using ${converter.name}: ${error.message}`);
|
|
224
205
|
}
|
|
225
|
-
throw new EnvaptError(
|
|
226
|
-
205 /* PrimitiveCoercionFailed */,
|
|
227
|
-
`Unknown primitive converter: ${converter.name}`
|
|
228
|
-
);
|
|
206
|
+
throw new EnvaptError(EnvaptErrorCodes.PrimitiveCoercionFailed, `Unknown primitive converter: ${converter.name}`);
|
|
229
207
|
}
|
|
230
208
|
/**
|
|
231
209
|
* Make sure the user hasn't provided prohibited options in their dotenv config
|
|
232
210
|
*/
|
|
233
211
|
static validateDotenvConfig(config2) {
|
|
234
212
|
if ("path" in config2 || "processEnv" in config2) {
|
|
235
|
-
throw new EnvaptError(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
213
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidUserDefinedConfig, 'Custom dotenvConfig should not include "path" or "processEnv" options. Those are managed by Envapter.');
|
|
214
|
+
}
|
|
215
|
+
const validKeys = /* @__PURE__ */ new Set([
|
|
216
|
+
"encoding",
|
|
217
|
+
"quiet",
|
|
218
|
+
"debug",
|
|
219
|
+
"override",
|
|
220
|
+
"DOTENV_KEY"
|
|
221
|
+
]);
|
|
241
222
|
const invalidKeys = Object.keys(config2).filter((key) => !validKeys.has(key));
|
|
242
223
|
if (invalidKeys.length > 0) {
|
|
243
|
-
throw new EnvaptError(
|
|
244
|
-
302 /* InvalidUserDefinedConfig */,
|
|
245
|
-
`Invalid dotenvConfig options: ${invalidKeys.join(", ")}. Allowed options: ${Array.from(validKeys).join(", ")}`
|
|
246
|
-
);
|
|
224
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidUserDefinedConfig, `Invalid dotenvConfig options: ${invalidKeys.join(", ")}. Allowed options: ${Array.from(validKeys).join(", ")}`);
|
|
247
225
|
}
|
|
248
226
|
return true;
|
|
249
227
|
}
|
|
@@ -260,10 +238,7 @@ var Validator = class {
|
|
|
260
238
|
}
|
|
261
239
|
});
|
|
262
240
|
if (missing.length > 0) {
|
|
263
|
-
throw new EnvaptError(
|
|
264
|
-
303 /* EnvFilesNotFound */,
|
|
265
|
-
`Environment file not found at path: ${missing.join(", ")}`
|
|
266
|
-
);
|
|
241
|
+
throw new EnvaptError(EnvaptErrorCodes.EnvFilesNotFound, `Environment file not found at path: ${missing.join(", ")}`);
|
|
267
242
|
}
|
|
268
243
|
}
|
|
269
244
|
};
|
|
@@ -274,15 +249,20 @@ var EnvapterBase = class _EnvapterBase {
|
|
|
274
249
|
static {
|
|
275
250
|
__name(this, "EnvapterBase");
|
|
276
251
|
}
|
|
277
|
-
static _envPaths = [
|
|
278
|
-
|
|
279
|
-
|
|
252
|
+
static _envPaths = [
|
|
253
|
+
".env"
|
|
254
|
+
];
|
|
255
|
+
static _userDefinedDotenvConfig = {
|
|
256
|
+
quiet: true
|
|
257
|
+
};
|
|
280
258
|
/**
|
|
281
259
|
* Set custom .env file paths. Accepts either a single path or array of paths.
|
|
282
260
|
* Setting new paths clears the cache and reloads environment variables.
|
|
283
261
|
*/
|
|
284
262
|
static set envPaths(paths) {
|
|
285
|
-
const newPaths = Array.isArray(paths) ? paths : [
|
|
263
|
+
const newPaths = Array.isArray(paths) ? paths : [
|
|
264
|
+
paths
|
|
265
|
+
];
|
|
286
266
|
Validator.validateEnvFilesExist(newPaths);
|
|
287
267
|
this._envPaths = newPaths;
|
|
288
268
|
this.refreshCache();
|
|
@@ -312,30 +292,44 @@ var EnvapterBase = class _EnvapterBase {
|
|
|
312
292
|
void this.config;
|
|
313
293
|
}
|
|
314
294
|
static resolveKeyInput(keyInput) {
|
|
315
|
-
const keys = Array.isArray(keyInput) ? keyInput : [
|
|
295
|
+
const keys = Array.isArray(keyInput) ? keyInput : [
|
|
296
|
+
keyInput
|
|
297
|
+
];
|
|
316
298
|
const normalizedKeys = keys;
|
|
317
299
|
if (normalizedKeys.length === 0) {
|
|
318
|
-
throw new EnvaptError(
|
|
300
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "At least one environment key must be provided.");
|
|
319
301
|
}
|
|
320
302
|
if (normalizedKeys.some((k) => typeof k !== "string")) {
|
|
321
|
-
throw new EnvaptError(
|
|
303
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "Environment keys must be strings.");
|
|
322
304
|
}
|
|
323
305
|
if (normalizedKeys.some((k) => k.trim() === "")) {
|
|
324
|
-
throw new EnvaptError(
|
|
306
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidKeyInput, "Environment keys cannot be empty strings.");
|
|
325
307
|
}
|
|
326
308
|
for (const candidate of normalizedKeys) {
|
|
327
309
|
const value = this.config.get(candidate);
|
|
328
310
|
if (value !== void 0) {
|
|
329
|
-
return {
|
|
311
|
+
return {
|
|
312
|
+
key: candidate,
|
|
313
|
+
value
|
|
314
|
+
};
|
|
330
315
|
}
|
|
331
316
|
}
|
|
332
|
-
return {
|
|
317
|
+
return {
|
|
318
|
+
key: normalizedKeys[0],
|
|
319
|
+
value: void 0
|
|
320
|
+
};
|
|
333
321
|
}
|
|
334
322
|
static get config() {
|
|
335
323
|
if (EnvaptCache.size === 0) {
|
|
336
|
-
const isolatedEnv = {
|
|
324
|
+
const isolatedEnv = {
|
|
325
|
+
...process.env
|
|
326
|
+
};
|
|
337
327
|
try {
|
|
338
|
-
config({
|
|
328
|
+
config({
|
|
329
|
+
path: this._envPaths,
|
|
330
|
+
processEnv: isolatedEnv,
|
|
331
|
+
...this._userDefinedDotenvConfig
|
|
332
|
+
});
|
|
339
333
|
} catch {
|
|
340
334
|
}
|
|
341
335
|
for (const [key, value] of Object.entries(isolatedEnv)) EnvaptCache.set(key, value);
|
|
@@ -364,8 +358,18 @@ var BuiltInConverters = class _BuiltInConverters {
|
|
|
364
358
|
}
|
|
365
359
|
static boolean(raw, fallback) {
|
|
366
360
|
const lower = raw.toLowerCase().trim();
|
|
367
|
-
const truthyValues = [
|
|
368
|
-
|
|
361
|
+
const truthyValues = [
|
|
362
|
+
"1",
|
|
363
|
+
"yes",
|
|
364
|
+
"true",
|
|
365
|
+
"on"
|
|
366
|
+
];
|
|
367
|
+
const falsyValues = [
|
|
368
|
+
"0",
|
|
369
|
+
"no",
|
|
370
|
+
"false",
|
|
371
|
+
"off"
|
|
372
|
+
];
|
|
369
373
|
if (truthyValues.includes(lower)) return true;
|
|
370
374
|
if (falsyValues.includes(lower)) return false;
|
|
371
375
|
return fallback;
|
|
@@ -489,13 +493,14 @@ var BuiltInConverters = class _BuiltInConverters {
|
|
|
489
493
|
|
|
490
494
|
// src/Parser.ts
|
|
491
495
|
var Parser = class {
|
|
492
|
-
constructor(envService) {
|
|
493
|
-
this.envService = envService;
|
|
494
|
-
}
|
|
495
496
|
static {
|
|
496
497
|
__name(this, "Parser");
|
|
497
498
|
}
|
|
499
|
+
envService;
|
|
498
500
|
TEMPLATE_REGEX = /\${\w*}/g;
|
|
501
|
+
constructor(envService) {
|
|
502
|
+
this.envService = envService;
|
|
503
|
+
}
|
|
499
504
|
/**
|
|
500
505
|
* Resolve template variables in a string while handling circular references and missing variables
|
|
501
506
|
* @internal
|
|
@@ -542,7 +547,7 @@ var Parser = class {
|
|
|
542
547
|
if (primitiveConstructor === Boolean) return "boolean";
|
|
543
548
|
if (primitiveConstructor === BigInt) return "bigint";
|
|
544
549
|
if (primitiveConstructor === Symbol) return "symbol";
|
|
545
|
-
throw new EnvaptError(
|
|
550
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidConverterType, `Unknown primitive constructor`);
|
|
546
551
|
}
|
|
547
552
|
processBuiltInConverter(key, fallback, resolvedConverter, hasFallback, wasOriginallyConstructor) {
|
|
548
553
|
Validator.builtInConverter(resolvedConverter);
|
|
@@ -562,10 +567,7 @@ var Parser = class {
|
|
|
562
567
|
processArrayConverter(key, fallback, resolvedConverter, hasFallback) {
|
|
563
568
|
Validator.arrayConverter(resolvedConverter);
|
|
564
569
|
if (hasFallback && fallback !== void 0 && !Array.isArray(fallback)) {
|
|
565
|
-
throw new EnvaptError(
|
|
566
|
-
101 /* InvalidFallback */,
|
|
567
|
-
`ArrayConverter requires that the fallback be an array, got ${typeof fallback}`
|
|
568
|
-
);
|
|
570
|
+
throw new EnvaptError(EnvaptErrorCodes.InvalidFallback, `ArrayConverter requires that the fallback be an array, got ${typeof fallback}`);
|
|
569
571
|
}
|
|
570
572
|
if (hasFallback && Array.isArray(fallback)) {
|
|
571
573
|
Validator.validateArrayFallbackElementTypes(fallback);
|
|
@@ -596,12 +598,12 @@ var Parser = class {
|
|
|
596
598
|
};
|
|
597
599
|
|
|
598
600
|
// src/core/EnvironmentMethods.ts
|
|
599
|
-
var Environment = /* @__PURE__ */ ((Environment2)
|
|
601
|
+
var Environment = /* @__PURE__ */ (function(Environment2) {
|
|
600
602
|
Environment2[Environment2["Development"] = 0] = "Development";
|
|
601
603
|
Environment2[Environment2["Staging"] = 1] = "Staging";
|
|
602
604
|
Environment2[Environment2["Production"] = 2] = "Production";
|
|
603
605
|
return Environment2;
|
|
604
|
-
})(
|
|
606
|
+
})({});
|
|
605
607
|
var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
|
|
606
608
|
static {
|
|
607
609
|
__name(this, "EnvironmentMethods");
|
|
@@ -610,7 +612,7 @@ var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
|
|
|
610
612
|
static determineEnvironment(env) {
|
|
611
613
|
const environment = env ?? this.getRawValue("ENVIRONMENT", this.getRawValue("ENV", this.getRawValue("NODE_ENV", "development")));
|
|
612
614
|
if (typeof environment === "string") {
|
|
613
|
-
this._environment = environment.toLowerCase() === "production" ? 2
|
|
615
|
+
this._environment = environment.toLowerCase() === "production" ? 2 : environment === "staging" ? 1 : 0;
|
|
614
616
|
} else {
|
|
615
617
|
this._environment = environment;
|
|
616
618
|
}
|
|
@@ -649,37 +651,37 @@ var EnvironmentMethods = class _EnvironmentMethods extends EnvapterBase {
|
|
|
649
651
|
* Check if the current environment is production
|
|
650
652
|
*/
|
|
651
653
|
static get isProduction() {
|
|
652
|
-
return this.environment === 2
|
|
654
|
+
return this.environment === 2;
|
|
653
655
|
}
|
|
654
656
|
/**
|
|
655
657
|
* @see {@link EnvironmentMethods.isProduction}
|
|
656
658
|
*/
|
|
657
659
|
get isProduction() {
|
|
658
|
-
return _EnvironmentMethods.environment === 2
|
|
660
|
+
return _EnvironmentMethods.environment === 2;
|
|
659
661
|
}
|
|
660
662
|
/**
|
|
661
663
|
* Check if the current environment is staging
|
|
662
664
|
*/
|
|
663
665
|
static get isStaging() {
|
|
664
|
-
return this.environment === 1
|
|
666
|
+
return this.environment === 1;
|
|
665
667
|
}
|
|
666
668
|
/**
|
|
667
669
|
* @see {@link EnvironmentMethods.isStaging}
|
|
668
670
|
*/
|
|
669
671
|
get isStaging() {
|
|
670
|
-
return _EnvironmentMethods.environment === 1
|
|
672
|
+
return _EnvironmentMethods.environment === 1;
|
|
671
673
|
}
|
|
672
674
|
/**
|
|
673
675
|
* Check if the current environment is development
|
|
674
676
|
*/
|
|
675
677
|
static get isDevelopment() {
|
|
676
|
-
return this.environment === 0
|
|
678
|
+
return this.environment === 0;
|
|
677
679
|
}
|
|
678
680
|
/**
|
|
679
681
|
* @see {@link EnvironmentMethods.isDevelopment}
|
|
680
682
|
*/
|
|
681
683
|
get isDevelopment() {
|
|
682
|
-
return _EnvironmentMethods.environment === 0
|
|
684
|
+
return _EnvironmentMethods.environment === 0;
|
|
683
685
|
}
|
|
684
686
|
static refreshCache() {
|
|
685
687
|
super.refreshCache();
|
|
@@ -699,13 +701,10 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
699
701
|
if (!rawVal) return def;
|
|
700
702
|
const parsed = this.parser.resolveTemplate(resolvedKey, String(rawVal));
|
|
701
703
|
let result;
|
|
702
|
-
if (type === 1
|
|
703
|
-
else if (type === 2
|
|
704
|
-
|
|
705
|
-
else if (type ===
|
|
706
|
-
result = BuiltInConverters.bigint(parsed, def);
|
|
707
|
-
else if (type === 4 /* Symbol */)
|
|
708
|
-
result = BuiltInConverters.symbol(parsed, def);
|
|
704
|
+
if (type === 1) result = BuiltInConverters.number(parsed, def);
|
|
705
|
+
else if (type === 2) result = BuiltInConverters.boolean(parsed, def);
|
|
706
|
+
else if (type === 3) result = BuiltInConverters.bigint(parsed, def);
|
|
707
|
+
else if (type === 4) result = BuiltInConverters.symbol(parsed, def);
|
|
709
708
|
else result = BuiltInConverters.string(parsed, def);
|
|
710
709
|
return result;
|
|
711
710
|
}
|
|
@@ -715,10 +714,10 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
715
714
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
716
715
|
*/
|
|
717
716
|
static get(key, def) {
|
|
718
|
-
return this._get(key, 0
|
|
717
|
+
return this._get(key, 0, def);
|
|
719
718
|
}
|
|
720
719
|
get(key, def) {
|
|
721
|
-
return _PrimitiveMethods._get(key, 0
|
|
720
|
+
return _PrimitiveMethods._get(key, 0, def);
|
|
722
721
|
}
|
|
723
722
|
/**
|
|
724
723
|
* Get a number environment variable with optional fallback.
|
|
@@ -726,13 +725,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
726
725
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
727
726
|
*/
|
|
728
727
|
static getNumber(key, def) {
|
|
729
|
-
return this._get(key, 1
|
|
728
|
+
return this._get(key, 1, def);
|
|
730
729
|
}
|
|
731
730
|
/**
|
|
732
731
|
* @see {@link PrimitiveMethods.getNumber}
|
|
733
732
|
*/
|
|
734
733
|
getNumber(key, def) {
|
|
735
|
-
return _PrimitiveMethods._get(key, 1
|
|
734
|
+
return _PrimitiveMethods._get(key, 1, def);
|
|
736
735
|
}
|
|
737
736
|
/**
|
|
738
737
|
* Get a boolean environment variable with optional fallback.
|
|
@@ -740,13 +739,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
740
739
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
741
740
|
*/
|
|
742
741
|
static getBoolean(key, def) {
|
|
743
|
-
return this._get(key, 2
|
|
742
|
+
return this._get(key, 2, def);
|
|
744
743
|
}
|
|
745
744
|
/**
|
|
746
745
|
* @see {@link PrimitiveMethods.getBoolean}
|
|
747
746
|
*/
|
|
748
747
|
getBoolean(key, def) {
|
|
749
|
-
return _PrimitiveMethods._get(key, 2
|
|
748
|
+
return _PrimitiveMethods._get(key, 2, def);
|
|
750
749
|
}
|
|
751
750
|
/**
|
|
752
751
|
* Get a bigint environment variable with optional fallback.
|
|
@@ -754,13 +753,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
754
753
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
755
754
|
*/
|
|
756
755
|
static getBigInt(key, def) {
|
|
757
|
-
return this._get(key, 3
|
|
756
|
+
return this._get(key, 3, def);
|
|
758
757
|
}
|
|
759
758
|
/**
|
|
760
759
|
* @see {@link PrimitiveMethods.getBigInt}
|
|
761
760
|
*/
|
|
762
761
|
getBigInt(key, def) {
|
|
763
|
-
return _PrimitiveMethods._get(key, 3
|
|
762
|
+
return _PrimitiveMethods._get(key, 3, def);
|
|
764
763
|
}
|
|
765
764
|
/**
|
|
766
765
|
* Get a symbol environment variable with optional fallback.
|
|
@@ -768,13 +767,13 @@ var PrimitiveMethods = class _PrimitiveMethods extends EnvironmentMethods {
|
|
|
768
767
|
* Accepts a single key or an ordered array of keys (first match wins).
|
|
769
768
|
*/
|
|
770
769
|
static getSymbol(key, def) {
|
|
771
|
-
return this._get(key, 4
|
|
770
|
+
return this._get(key, 4, def);
|
|
772
771
|
}
|
|
773
772
|
/**
|
|
774
773
|
* @see {@link PrimitiveMethods.getSymbol}
|
|
775
774
|
*/
|
|
776
775
|
getSymbol(key, def) {
|
|
777
|
-
return _PrimitiveMethods._get(key, 4
|
|
776
|
+
return _PrimitiveMethods._get(key, 4, def);
|
|
778
777
|
}
|
|
779
778
|
};
|
|
780
779
|
|
|
@@ -801,12 +800,7 @@ var AdvancedMethods = class _AdvancedMethods extends PrimitiveMethods {
|
|
|
801
800
|
const { key: resolvedKey, value } = this.resolveKeyInput(key);
|
|
802
801
|
if (!value) return fallback;
|
|
803
802
|
const hasFallback = fallback !== void 0;
|
|
804
|
-
const result = this.parser.convertValue(
|
|
805
|
-
resolvedKey,
|
|
806
|
-
fallback,
|
|
807
|
-
converter,
|
|
808
|
-
hasFallback
|
|
809
|
-
);
|
|
803
|
+
const result = this.parser.convertValue(resolvedKey, fallback, converter, hasFallback);
|
|
810
804
|
return result;
|
|
811
805
|
}
|
|
812
806
|
/**
|
|
@@ -893,7 +887,7 @@ function Envapt(key, fallbackOrOptions, converter) {
|
|
|
893
887
|
__name(Envapt, "Envapt");
|
|
894
888
|
|
|
895
889
|
// src/Converters.ts
|
|
896
|
-
var Converters = /* @__PURE__ */ ((Converters2)
|
|
890
|
+
var Converters = /* @__PURE__ */ (function(Converters2) {
|
|
897
891
|
Converters2["String"] = "string";
|
|
898
892
|
Converters2["Number"] = "number";
|
|
899
893
|
Converters2["Boolean"] = "boolean";
|
|
@@ -908,7 +902,7 @@ var Converters = /* @__PURE__ */ ((Converters2) => {
|
|
|
908
902
|
Converters2["Date"] = "date";
|
|
909
903
|
Converters2["Time"] = "time";
|
|
910
904
|
return Converters2;
|
|
911
|
-
})(
|
|
905
|
+
})({});
|
|
912
906
|
/* v8 ignore next -- @preserve */
|
|
913
907
|
|
|
914
908
|
export { Converters, Envapt, EnvaptError, EnvaptErrorCodes, Envapter, Environment };
|