env-sanitize 🧹
Sanitization and verification of environment variables with typescript support.
Installation
npm
npm install env-sanitize
yarn
yarn add env-sanitize
Example
;// or const env = require('env-sanitize'); // If not exists, throw.const env_region = ; // use default if not exists.const env_server_url = ; // get MAX_CONNECTIONS env, and transform it to int.// throw if its not a number or not exists.const env_max_connections = ; // get PORT env, and transform it to number in port range.// throw if its out of the range.// return default if not exists.const env_port = ; // We can chain the Sanitizers.const env_key = ;
Sanitizers
- required
- with default
- asInt
- asFloat
- greater
- greaterOrEqual
- less
- lessOrEqual
- asBoolean
- asEnum
- asRegex
- asPort
- asJson
- asJsonArray
- asLowerCase
- asUpperCase
- assert
- transform
required
const env_required = ;
with default
const env_key = ;
asInt
const env_key = ;
asFloat
const env_key = ;
greater
const env_float_key = ;const env_int_key = ;
greaterOrEqual
const env_float_key = ;const env_int_key = ;
less
const env_float_key = ;const env_int_key = ;
lessOrEqual
const env_float_key = ;const env_int_key = ;
asBoolean
const env_key = ;
asEnum
const env_key = ;
asRegex
const env_key = ;
asPort
const env_key = ;
asJson
const env_key = ;
asJsonArray
const env_key = ;
asLowerCase
const env_key = ;
asUpperCase
const env_key = ;
assert
const env_key = ;
transform
const env_key = ;