@knpwrs/envariant
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

envariant

This is a small snippet that I found myself writing for multiple projects in the form of an npm module. envariant is essentially a way to guarantee that an environment variable contains a truthy string at runtime. If the environment variable is not defined, envariant will throw. This is useful for type narrowing your environment variables that you expect to be defined.

Usage

import env from '@knpwrs/envariant';

const DB_URI = env('DB_URI');
// DB_URI is guaranteed to be defined at this point, as long as there is a `DB_URI` environment variable defined.
// If there isn't a `DB_URI` variable defined then `env` will throw and this script will crash.

// There is an optional second parameter that lets you supply an object to read variables from; for
// instance, the `env` parameter in Cloudflare workers:
const ENDPOINT = env('ENDPOINT', env);

Installation

npm install @knpwrs/envariant

License

Unlicensed

Package Sidebar

Install

npm i @knpwrs/envariant

Weekly Downloads

4

Version

1.1.1

License

Unlicense

Unpacked Size

6.01 kB

Total Files

9

Last publish

Collaborators

  • knpwrs