dotenv-safe
dotenv-safe copied to clipboard
Add `optionalValues` and `requiredValues` options
Closes #41, resolves #45
First, thank you for this lib, I use it on almost every projects of mine! 😊
This PR adds the options optionalValues and requiredValues. I thought it would be better to not allow allowEmptyValues to be a Set just like in #41, and make it new separate options.
How it works
- Uses
Setas mentioned in #41 optionalValues: Values inoptionalValueswill not be required anymoreallowEmptyValues: true+requiredValues: All values are optional except ones inrequiredValues
Errors
allowEmptyValues: true+optionalValues: Error, useless as all values are already optionalallowEmptyValues: false+requiredValues: Error, everything is already requiredoptionalValuesorrequiredValuesare notSet: Error, must beSet
How to use
// Any value can be empty except `THIS_ENV_IS_REQUIRED_ANYWAY` and `THIS_ONE_TOO`
require('dotenv-safe').config({
allowEmptyValues: true,
requiredValues: new Set(['THIS_ENV_IS_REQUIRED_ANYWAY', 'THIS_ONE_TOO']),
example: './.my-env-example-filename'
});
// Every values are required except `THIS_ENV_IS_OPTIONAL` and `THIS_ONE_TOO`
require('dotenv-safe').config({
optionalValues: new Set(['THIS_ENV_IS_OPTIONAL', 'THIS_ONE_TOO']),
example: './.my-env-example-filename'
});
Let me know what you think of it 😄