New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cruks-lib-config

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cruks-lib-config

If you want to maintain and validate configuration objects with ease, then you are looking for cruks-lib-config!

  • 3.1.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
37
increased by164.29%
Maintainers
1
Weekly downloads
 
Created
Source

cruks-lib-config

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.

Examples

Testing array keys

Every array item needs to be integer.

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

Result:

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()
});

expectedConfiguration.assert({
    "a": 5,
    "b": "some-string",
    "c": {
        "d": {
            "e": "not-a-boolean"
        }
    },
    "f": []
});

Result:

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

More

For more information please refer to project's wiki.


Build Status Code Climate Dependency Status

Keywords

FAQs

Package last updated on 20 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc