really-bad-configs
v1.0.0
Published
A package to handle configuration variables the worst way ever.
Downloads
2
Readme
Really Bad Configs
A module to turn configuration storage into living hell.
Usage
npm i really-bad-configs
Create a directory to hold your configuration's key-value pairs. Remember, each file holds a key-value pair, so that the name of the file will be the key and the contents will be the value.
Once you have that directory, pass it through the load
function:
const { load } = require('really-bad-configs');
// or: const loadConfig = require('really-bad-configs').load;
// or simply: const rbc = require('really-bad-configs');
const config = load({ location: 'path/to/the/config/dir' });
console.log(config);
API
load ({ location })
Loads a configuration. Expects an object with a location
property that specifies the directory that contains the key-value pairs. It returns an object.
const config = load({ location: '.config' });
lookup (location, key)
Looks up a value based on config location and key. Returns the contents of the file if it exists. Otherwise, it returns undefined.
const databaseUser = lookup('.config', 'DATABASE_USER');
createKey (location, key, value)
Creates a key-value pair in the specified location (if it doesn't already exist). It returns true
if it succeded, false
if the location doesn't exist or the value is an object, throws for any other issue.
createKey('.config', 'DATABASE_USER', 'testuser');
createMultiple (location, configObject)
Creates a key-value pair for an entire config object. Useful for converting your old, lame, JSON-based configs into RBCs. It returns true if it has succeded, throws if something bad happened. It uses the createKey
method.
createMultiple('.config', {
DATABASE_HOST: 'localhost',
DATABASE_USER: 'testuser'
});
Disclaimer
This project is a joke. Please don't use it in your production apps... or not even in your development apps.
License
MIT.