node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



How often you need to cope with situations like this?

function init(config) {
    myOption || (myOption = parseInt(config.myOption, 10));
TypeError: Cannot read property 'myOption' of null
// NO MORE !!!

Wouldn't it be easier to keep all your configuration schemas in one place and delegate all the validation hassle to external library (like cruks-lib-config)?

var expectedConfiguration = expect.schema({
    "myOption": expect.integer().default(10)
function init(config) {
    config = expectedConfiguration.assert(config);
    config.myOption; // 10! Much better!

Configuration processor asserts that any input matches your expected parameters and makes validating complicated objects much easier. It also provides some basic assertion tools and verbose debug messages.

Focus on clear, readable messages and ability to track exact failing element makes cruks-lib-config really special.


Testing array keys

Every array item needs to be integer.

expect.array.every(expect.integer()).assert([1, "2", 3]);


AssertionFailureError: expected integer but "1" got (string)"2"
// "1" is the name of affected array key

Testing unexpected input against predefined schema

expect = require("cruks-lib-config").expect;
expectedConfiguration = exepct.schema({
    "a": expect.number(),
    "b": expect.string(),
    "c": expect.schema({
        "d": expect.schema({
            "e": expect.boolean()
    "f": expect.array()
    "a": 5,
    "b": "some-string",
    "c": {
        "d": {
            "e": "not-a-boolean"
    "f": []


AssertionFailureError: expected boolean but "c.d.e" got (string)"not-a-boolean"


For more information please refer to project's wiki.

Build Status Code Climate Dependency Status