0.1.18 • Published 1 year ago
castenv v0.1.18
castenv
Overview
Environment variables like MAX_THREADS=5 , ENABLE_DEBUG=false are usually imported into process.env as strings.
This leads to subtle bugs when treating them like booleans or numbers e.g. if (process.env['ENABLE_DEBUG'])...
because "false" equals true in JS
castenv uses JSON.parse() to convert env variables into native types. castenv.cast() will modify process.env,
and castenv.env() will leave process.env unmodified.
Getting Started
Install it via npm:
npm install castenvInclude in your project:
// cast process.env in place
require("castenv").cast()
// alternatively, don't modify process.env
var env = require("castenv").env()Example Casting
process.env["TEST_NUMBER_VALUE"] = "5"
console.log(typeof process.env["TEST_NUMBER_VALUE"])
// "string"
require("castenv").cast()
console.log(typeof process.env["TEST_NUMBER_VALUE"])
// numberPitfalls
- hex & octal values like
0x123and0123will return as strings--JSON doesn't support those literals
License
MIT
0.1.18
1 year ago
0.1.17
2 years ago
0.1.16
3 years ago
0.1.15
4 years ago
0.1.13
5 years ago
0.1.14
5 years ago
0.0.1
5 years ago
0.1.12
5 years ago
0.1.11
6 years ago
0.1.10
7 years ago
0.1.9
7 years ago
0.1.8
8 years ago
0.1.7
8 years ago
0.1.6
8 years ago
0.1.5
8 years ago
0.1.4
8 years ago
0.1.3
8 years ago
0.1.2
8 years ago
0.1.1
8 years ago
0.1.0
8 years ago