summaryrefslogtreecommitdiff
path: root/u/process/env.ts
diff options
context:
space:
mode:
Diffstat (limited to 'u/process/env.ts')
-rw-r--r--u/process/env.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/u/process/env.ts b/u/process/env.ts
index 26e1158..65f4e63 100644
--- a/u/process/env.ts
+++ b/u/process/env.ts
@@ -10,3 +10,18 @@ export const getRequiredEnv = (name: string): IEither<Error, string> =>
new Error(`environment variable "${name}" is required D:`),
)
);
+
+export const getRequiredEnvVars = (vars: Array<string>) =>
+ vars
+ .map((envVar) =>
+ [envVar, getRequiredEnv(envVar)] as [string, IEither<Error, string>]
+ )
+ .reduce((acc, x: [string, IEither<Error, string>]) => {
+ const [envVar, eitherVal] = x;
+ return acc.flatMap((args) => {
+ return eitherVal.mapRight((envValue) => ({
+ ...args,
+ [envVar]: envValue,
+ }));
+ });
+ }, Either.right<Error, Record<string, string>>({}));