| .gitignore | ||
| index.js | ||
| package-lock.json | ||
| package.json | ||
| readme.md | ||
confer
confer is a configuration helper. it wraps the dotenv library. application config is defined in a .env file, or in the shell environment. confer is used to filter, validate, transform, and display the configuration values.
usage
put your configuration in a .env file in the root of your project.
SERVICE=https/example.org/foo
USERNAME=bob
PASSWORD=supersecret
DATA=/tmp
ALLOW_LIST=sally, marge
DEBUG=true
call init_config() at the beginning of program execution. the parameter passed to init_config() contains rules for processing app configuration.
import { init_config, print_config } from "confer";
const config = init_config({
required_keys: ["SERVICE", "USERNAME", "PASSWORD", "DATA"],
optional_keys: ["ALLOW_LIST", "DEBUG"],
hidden_keys: ["PASSWORD"],
validate: (config) => {
config.is_writable("DATA");
},
transform: (config) => {
config.to_array("ALLOW_LIST");
config.to_boolean("DEBUG");
},
});
print_config(config);
print_config() will display the processed config values. keys in the hidden_keys array will be obfuscated. the validate and transform functions are passed the config object which can be manipulated directly, or validated and transformed with the attached helpers. is_readable(), is_writable(), to_array() and to_boolean().
SERVICE https/example.org/foo
USERNAME bob
PASSWORD ***********
DATA /tmp
ALLOW_LIST [ 'sally', 'marge' ]
DEBUG true