UNPKG

@placeholdersoft/typed-env

Version:

typed-env can help us better handle environment variables

47 lines (46 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.anyEnv = exports.typedEnv = exports.injectGlobalEnv = void 0; const env_box_1 = require("./env-box"); let __GLOBAL_ENV__ = {}; try { /** * default env source is process.env, if you want to use other env source, you can use injectGlobalEnv */ __GLOBAL_ENV__ = process.env; // eslint-disable-next-line no-empty } catch (e) { } /** * Set the global environment for the current process. * * @param env The environment to set. * @example injectGlobalEnv(process.env) | injectGlobalEnv({"app_version": "0.0.1"}) * */ const injectGlobalEnv = (env) => { __GLOBAL_ENV__ = env; }; exports.injectGlobalEnv = injectGlobalEnv; /** * * @param key env key * @returns EnvBox * * @description support evn-name type check, default env source is process.env, if you want to use other env source, you can use injectGlobalEnv * */ function typedEnv(key) { return env_box_1.EnvBox.of(key, __GLOBAL_ENV__); } exports.typedEnv = typedEnv; /** * @param key env key * @returns EnvBox * * @description can be any env-name, default env source is process.env, if you want to use other env source, you can use injectGlobalEnv */ function anyEnv(key) { return env_box_1.EnvBox.of(key, __GLOBAL_ENV__); } exports.anyEnv = anyEnv;