summaryrefslogtreecommitdiff
path: root/u/process/env.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-06-29 17:31:30 -0700
committerElizabeth Hunt <me@liz.coffee>2025-06-29 17:31:30 -0700
commit58be1809c46cbe517a18d86d0af52179dcc5cbf6 (patch)
tree9ccc678b3fd48c1a52fe501600dd2c2051740a55 /u/process/env.ts
parentd4791f3d357634daf506fb8f91cc5332a794c421 (diff)
downloadci-58be1809c46cbe517a18d86d0af52179dcc5cbf6.tar.gz
ci-58be1809c46cbe517a18d86d0af52179dcc5cbf6.zip
Move to nodejs and also lots of significant refactoring that should've been broken up but idgaf
Diffstat (limited to 'u/process/env.ts')
-rw-r--r--u/process/env.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/u/process/env.ts b/u/process/env.ts
index 1e4fd32..9a55488 100644
--- a/u/process/env.ts
+++ b/u/process/env.ts
@@ -1,10 +1,11 @@
-import { Either, type IEither } from '@emprespresso/pengueno';
+import { IOptional, Either, Optional, type IEither } from '@emprespresso/pengueno';
-export const getRequiredEnv = <V extends string>(name: V): IEither<Error, V> =>
- Either.fromFailable<Error, V | undefined>(() => process.env[name] as V | undefined) // could throw when no permission.
- .flatMap(
- (v) => (v && Either.right(v)) || Either.left(new Error(`environment variable "${name}" is required D:`)),
- );
+export const getEnv = <V extends string>(name: string): IOptional<V> => Optional.from(<V>process.env[name]);
+
+export const getRequiredEnv = <V extends string>(name: string): IEither<Error, V> =>
+ Either.fromFailable(() => getEnv<V>(name).get()).mapLeft(
+ () => new Error(`environment variable "${name}" is required D:`),
+ );
type ObjectFromList<T extends ReadonlyArray<string>, V = string> = {
[K in T extends ReadonlyArray<infer U> ? U : never]: V;