1.1.1 • Published 1 year ago

@knpwrs/envariant v1.1.1

Weekly downloads
-
License
Unlicense
Repository
github
Last release
1 year ago

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

1.1.1

1 year ago

1.1.0

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago