Add default to getEnvVar and better typing

This commit is contained in:
mifi committed 2023-05-30 20:21:30 -04:00
1 parent 9e72e98232
commit 19b3de3905
2 files changed
+4 -3

No files matched your search

+1 -1
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": {
+3 -2
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);
};