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

    checkpublic

    node-check

    Configuration checker.

    Build Status

    Install

    npm install check
    

    (Or clone the repo.)

    Usage

    var check = require('check');
    
    var config = {
        database: {hostname: 'example.com', debug: false},
    	someOtherSetting: 'bar'
    };
    
    check(config)
    	.has('database.hostname') // Implicitly checks 'database'
    	.hasBoolean('database.debug')
    	.has('missingSetting')   // Missing key - this will make check fail.
    	.assert();               // Assert if anything isn't as required.
    

    Will produce an error not entirely unlike this:

    AssertionError: Incorrect configuration:
        Missing key 'missingSetting'.
    at functionA (/your/source/code/a.js:line:col)
    at functionB (/your/source/code/b.js:line:col)
    ...
    at EventEmitter._tickCallback (node.js:190:38)
    

    API

    Initialization

    check(object-literal)
    

    Returns an chainable object whereon the following functions can be used.

    .has(key)

    Tests if the given key is present. This also works with dot-notation, so has('foo.bar') will check if foo exists and then if foo has a bar-thing stuck on.

    .hasArguments(key)

    .hasArray(key)

    .hasBoolean(key)

    .hasDate(key)

    .hasFunction(key)

    .hasNumber(key)

    .hasObject(key)

    .hasRegExp(key)

    .hasString(key)

    First checks if the key is present (as if running .has(key)), and if the given key is the right type.

    .optionalArguments(key)

    .optionalArray(key)

    .optionalBoolean(key)

    .optionalDate(key)

    .optionalFunction(key)

    .optionalNumber(key)

    .optionalObject(key)

    .optionalRegExp(key)

    .optionalString(key)

    If the key is present, it checks if it is of the indicated type.

    Finalizers

    .assert()

    Stops the chaining and assert() if any keys were missing.

    .ok()

    Stops the chaining and returns if any errors were found.

    .errors()

    Stops the chaining and returns a list of errors (if any).

    Bugs

    Plenty! Report them! And add ideas for great features.

    See Also

    License

    ISC; see LICENSE.

    Keywords

    none

    install

    npm i check

    Downloadsweekly downloads

    257

    version

    1.0.0

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar