UNPKG

2.18 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.testOnly = exports.customCleanEnv = exports.cleanEnv = void 0;
4var core_1 = require("./core");
5var middleware_1 = require("./middleware");
6/**
7 * Returns a sanitized, immutable environment object. _Only_ the env vars
8 * specified in the `validators` parameter will be accessible on the returned
9 * object.
10 * @param environment An object containing your env vars (eg. process.env).
11 * @param specs An object that specifies the format of required vars.
12 * @param options An object that specifies options for cleanEnv.
13 */
14function cleanEnv(environment, specs, options) {
15 if (options === void 0) { options = {}; }
16 var cleaned = (0, core_1.getSanitizedEnv)(environment, specs, options);
17 return Object.freeze((0, middleware_1.applyDefaultMiddleware)(cleaned, environment));
18}
19exports.cleanEnv = cleanEnv;
20/**
21 * Returns a sanitized, immutable environment object, and passes it through a custom
22 * applyMiddleware function before being frozen. Most users won't need the flexibility of custom
23 * middleware; prefer cleanEnv() unless you're sure you need it
24 *
25 * @param environment An object containing your env vars (eg. process.env).
26 * @param specs An object that specifies the format of required vars.
27 * @param applyMiddleware A function that applies transformations to the cleaned env object
28 * @param options An object that specifies options for cleanEnv.
29 */
30function customCleanEnv(environment, specs, applyMiddleware, options) {
31 if (options === void 0) { options = {}; }
32 var cleaned = (0, core_1.getSanitizedEnv)(environment, specs, options);
33 return Object.freeze(applyMiddleware(cleaned, environment));
34}
35exports.customCleanEnv = customCleanEnv;
36/**
37 * Utility function for providing default values only when NODE_ENV=test
38 *
39 * For more context, see https://github.com/af/envalid/issues/32
40 */
41var testOnly = function (defaultValueForTests) {
42 return process.env.NODE_ENV === 'test' ? defaultValueForTests : core_1.testOnlySymbol; // T is not strictly correct, but prevents type errors during usage
43};
44exports.testOnly = testOnly;
45//# sourceMappingURL=envalid.js.map
\No newline at end of file