1.1.0 • Published 2 years ago

@valu/env v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

@valu/env

Tiny helper for managing enviroment variables type safely.

Install

npm install @valu/env

Usage

import { TypedEnv } from "@valu/env";

type AllowedKeys = "FOO" | "BAR";

const env = new TypedEnv<AllowedKeys>(process.env);

Reading

// Get value in FOO env. Throws if FOO is not defined. The return type is always
// `string`.
const value = env.get("FOO");

// Type error
const value = env.get("WAT");

// Second argument can be used for default values to avoid throwing.
const value = env.get("FOO", "default");

// Use null as the default the get return value of `string | null` without
// throwing
const value = env.get("FOO", null);

Mutation

// Set env var
env.set("FOO", "value");

// Delete env var
env.delete("FOO");
1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago