0.1.1 • Published 9 years ago
configurationjs v0.1.1
configurationjs
Configuration manager for your node apps
var Configuration = require("configurationjs")
, config;
config = new Configuration();
Creating a new configuration that absorbs multiple objects by passing them has argument of the constructor
var Configuration = require("configurationjs")
, config;
config = new Configuration( { "hostname": 127.0.0.1, "port": 80 }, { "databaseLogin": "something" } );
Load configurations from the filesystem. By default it searches for package.json, config.json and config.js
var Configuration = require("configurationjs")
, config;
config = new Configuration();
config.load( Configuration.fromFiles( __dirname ) );
You may load other files and even with different extentions by adding the filename and respective parser to the Configuration's acceptedFiles property.
var Configuration = require("configurationjs")
, config;
config = new Configuration();
/* Parser function should respect such arguments, the file's content is accessible by the data variable,
the parsed content should be passed to the callback( err, object ) function.
**/
Configuration.acceptedFiles = {
"config.xml": function ( data, callback ) {
/* some parsing madness… */
if (err) {
callback(err);
} else {
callback( void 0, object );
}
}
}
config.load( Configuration.fromFiles( __dirname ) );
Instead of using the usual dot notation (which is still possible to be used) we access values by their namespace like root::config::key.
Use the set property function to set the value on the specified object.
var Configuration = require("configurationjs")
config;
config = new Configuration( settings );
value = config.set( "books::helloworld", "Hello world" );
Use the get property function to access the value on specified path.
var Configuration = require("configurationjs")
, settings = {
"root": {
"config": {
"key": "nugget";
}
}
}
, config, value, itsTrue;
config = new Configuration( settings );
value = config.get("root::config::key");
itsTrue = ( value === config.root.config.key );