diff options
Diffstat (limited to 'u/process/env.ts')
-rw-r--r-- | u/process/env.ts | 25 |
1 files changed, 0 insertions, 25 deletions
diff --git a/u/process/env.ts b/u/process/env.ts deleted file mode 100644 index f59fadf..0000000 --- a/u/process/env.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { IOptional, Either, Optional, type IEither, type ObjectFromList } from '@emprespresso/pengueno'; - -// type safe environment variables - -export const getEnv = (name: string): IOptional<string> => Optional.from(process.env[name]); - -export const getRequiredEnv = <V extends string>(name: V): IEither<Error, string> => - Either.fromFailable(() => getEnv(name).get()).mapLeft( - () => new Error(`environment variable "${name}" is required D:`), - ); - -export const getRequiredEnvVars = <V extends string>(vars: Array<V>): IEither<Error, ObjectFromList<typeof vars>> => { - type Environment = ObjectFromList<typeof vars>; - const emptyEnvironment = Either.right<Error, Environment>(<Environment>{}); - const addTo = (env: Environment, key: V, val: string) => - <Environment>{ - ...env, - [key]: val, - }; - return vars.reduce( - (environment, key) => - environment.joinRight(getRequiredEnv(key), (value, environment) => addTo(environment, key, value)), - emptyEnvironment, - ); -}; |