Add default to getEnvVar and better typing

This commit is contained in:
2023-05-30 20:21:30 -04:00
parent 9e72e98232
commit 19b3de3905
2 changed files with 4 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@mifi/services-common",
"version": "1.0.9",
"version": "1.0.11",
"author": "mifi (Mike Fitzpatrick)",
"license": "MIT",
"scripts": {

View File

@@ -1,5 +1,6 @@
export const getEnvVar = (key: string) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const getEnvVar = <T = any>(key: string, defaultValue: T): T => {
const val = process.env[key];
if (!val) return undefined;
if (!val) return defaultValue as T;
else return JSON.parse(val);
};