c-c-config

Tagged configuration

npm install c-c-config
2 downloads in the last month

c-c-config is a library to parse tagged configuration.

As an example, take the following JSON config which describes different database servers to use for different application environments:

{
    "development": {
        "database": "localhost"
    },
    "production": {
        "database": "power-hungry-server"
    }
}

You'd use this with c-c-config as follows:

var ccconfig = require("c-c-config");

// c-c-config does not concern itself with I/O.
var raw = JSON.parse(/* … */);

var cfg = ccconfig("development", raw);
// do something with cfg.database

However, multiple tags (and thus levels of configuration) are possible:

ccconfig("worker development", {
    "worker development": {
        "bindPort": 91234
    },
    "worker": {
        "bindPort": 1234
    },
    "development": {
        "database": "localhost"
    }
});

The most specific rule will prevail, so bindPort will be set to 91234. Objects are merged, so the resulting object will also contain the database property. (In fact, c-c-config does deep merging of object structures.)

npm loves you