@valu/env
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@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");

Readme

Keywords

none

Package Sidebar

Install

npm i @valu/env

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

9.71 kB

Total Files

12

Last publish

Collaborators

  • saulirajala
  • valudigital
  • esamatti
  • joonasvaris