@halospv3/hce.shared-config
Version:
Automate commit message quality, changelogs, and CI/CD releases. Its `main` entry point is a Semantic Release config. Functions and classes are exposed for customization. An ESLint config, a Commitlint config, and addl. resources for .NET projects are als
1 lines • 2.88 kB
Source Map (JSON)
{"version":3,"file":"env.mjs","names":[],"sources":["../../src/utils/env.ts"],"sourcesContent":["/* eslint-disable unicorn/name-replacements */\nimport dotenvx, {\n type DotenvConfigOptions,\n type GetOptions,\n} from '@dotenvx/dotenvx';\nimport { env } from 'node:process';\n\n// I hate importing CommonJS modules with their broken default exports\nconst {\n get,\n config: loadDotenv,\n} = dotenvx;\n\n/** `get` can return `undefined`. It can also return a `Record`, but that's internal. */\ntype Get = (key: string, options?: GetOptions) => string | undefined;\n\n/**\n * A thin wrapper for {@link loadDotenv}. Loads a .env file from {@link process.cwd()} with the given options (or defaults), returns the new value of {@link process.env} with optional overrides.\n * @param [dotenvOptions] An optional {@link DotenvConfigOptions} object to pass to {@link loadDotenv}.\n * @param [overrides] If provided, this {@link NodeJS.ProcessEnv} object is merged into the return value, overriding existing properties where overlap occurs.\n * @returns A {@link NodeJS.ProcessEnv} object whose properties are variables loaded from the\n * process environment, the nearest .env file, and {@link overrides} (if provided). Where\n * overlap occurs, the later source takes priority.\n */\nexport function getEnv(dotenvOptions?: DotenvConfigOptions, overrides?: NodeJS.ProcessEnv): NodeJS.ProcessEnv {\n loadDotenv(dotenvOptions);\n\n if (overrides)\n Object.assign(env, overrides);\n\n return env;\n}\n\n/**\n * Get the value from the given env var in the current process or nearby .env file.\n * If found in process environment, its value is returned.\n * Else, try to get it from the nearest .env file.\n * If NOT found, return `undefined`\n * @param envVar The environment variable to lookup.\n * @param [options] Options to pass to {@link get}\n * @returns The string value of the environment variable or `undefined`.\n * `undefined` may be returned when the variable is undefined or its string is\n * empty, whitespace, or appears to have been converted from `null` or\n * `undefined`.\n */\nexport function getEnvVarValue(envVar: string, options?: GetOptions): string | undefined {\n options ??= { ignore: ['MISSING_KEY', 'MISSING_ENV_FILE'] };\n let value = env[envVar];\n const x = (get as Get)(envVar, options);\n if (typeof x === 'string')\n value = x;\n // I hate this. Why is undefined converted to a string?\n return value === '' || value === 'undefined'\n ? undefined\n : value;\n}\n"],"mappings":";;;AAQA,MAAM,EACJ,KACA,QAAQ,eACN;;;;;;;;;AAaJ,SAAgB,OAAO,eAAqC,WAAkD;CAC5G,WAAW,aAAa;CAExB,IAAI,WACF,OAAO,OAAO,KAAK,SAAS;CAE9B,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,eAAe,QAAgB,SAA0C;CACvF,YAAY,EAAE,QAAQ,CAAC,eAAe,kBAAkB,EAAE;CAC1D,IAAI,QAAQ,IAAI;CAChB,MAAM,IAAK,IAAY,QAAQ,OAAO;CACtC,IAAI,OAAO,MAAM,UACf,QAAQ;CAEV,OAAO,UAAU,MAAM,UAAU,cAC7B,KAAA,IACA;AACN"}