types-env

1.0.1 • Public • Published

types-env

Gives a simple type validation for your environment variables. Zero dependency.

How to use

// CommonJS modules
const env = require('types-env');
// ES6 modules
import env from 'types-env';
const baseUrl = env('REACT_APP_BASE_URL', 'string', 'http://default-base-url.com');
const widthLimit = env('REACT_APP_WIDTH_LIMIT', 'number', 1000);
const isActivated = env('REACT_APP_ACTIVATED', 'boolean', false);

Three types are supported: 'string', 'number' and 'boolean'. Default value can be provided as a third argument. Throws an error in case of type mismatch.

Boolean variables

For boolean variables the values

1, true, yes, y, ok, on

are considered as true. Values

0, false, no, n, nok, off

are considered as false. Any other value will produce an error.

Package Sidebar

Install

npm i types-env

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

6.48 kB

Total Files

7

Last publish

Collaborators

  • matadorvirtuoz