Parse dotenv files for
Numbervariable types, built for CrocodileJS.
Imagine you have a configuration file at
.env with the following:
FOO=barBAZ=2BEEP=falseBOOP=some,thing,that,goes,wow# note how we use an asterisk here to turn off the parsing for this variableBLEEP=false*# note how we use an asterisk in the array to turn off parsing for an array key valuePING=ping,true*,2,100# note a string between bacticks won't be parsedPONG=`some,thing,that,goes,wow`
After using this plugin, the environment variables are parsed to their proper types.
To test it out, simply log the returned object in your console:
And you'll see that it outputs the properly parsed variable types:
// StringFOO: 'bar'// NumberBAZ: 2// BooleanBEEP: false// ArrayBOOP: 'some' 'thing' 'that' 'goes' 'wow'// NOTE: this was not parsed due to the * asterisk override aboveBLEEP: 'false'// NOTE: only the `true*` above was opted out through the use of an asteriskPING: 'ping' 'true' 2 100// NOTE: this was not parsed because the string was between bacticksPONG: 'some,thing,that,goes,wow'
If your configuration line ends in
* it will not be parsed by this package, which allows you to keep values as the
String variable type if needed. Also when you encapsulate a value between bacticks e.g. `value`, the value won't be parsed and it will return as a
String variable. This can be used in situations where you for example have a ',' inside your string and it should not be parsed as an array.
npm install --save dotenv-parse-variables
const dotenv = ;const dotenvParseVariables = ;let env = dotenvif enverror throw enverror;env = ;console;
dotenv-extended(which supports a well-defined
dotenv-expand(which supports variable interpolation):
const dotenvExtended = ;const dotenvMustache = ;const dotenvParseVariables = ;let env = dotenvExtended;env = ;env = ;console;
If you don't want to use this package to parse variable types, you could also use getenv (but it requires more work).