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

0.1.3 • Public • Published

Env validation library

This started as a shameless ripoff of env-var, then took its own way.

This library exploits the moveax validation library to validate environment variables.

Installation

yarn add @moveaxlab/env-validation

Usage

Values can be retrieved from the environment specifying the type and, optionally, some rules, according to chainside validation library.

import { envValidation } from '@moveax/env-validation';

const my_var = envValidation.get('VARIABLE_NAME').asString();

const my_var_with_default = envValidation.get('VARIABLE_NAME', 'DEFAULT_VALUE').asString();

All variables are required by default. If you want to make a variable optional, add the nullable rule.

const my_var_possibly_null = envValidation.get('VARIABLE_NAME').asString('nullable');

If no value is given, no default value is specified, and the nullable rule is present, the value returned will be undefined. String types, if given the nullable rule, will return an empty string ('') if no value is given for the variable.

Rules can be passed as an array of string or as a | (pipe) separated string of rules.

The library throws an error in your face if the environment variable does not match the type.

Readme

Keywords

none

Package Sidebar

Install

npm i @moveaxlab/env-validation

Weekly Downloads

110

Version

0.1.3

License

MIT

Unpacked Size

105 kB

Total Files

164

Last publish

Collaborators

  • gdecicco
  • psenderos
  • lorenzogiustozzi
  • asmeikal
  • simone.bronzini