You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

chai-param

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-param

Adds useful methods for using chai to validate function parameters


Version published
Weekly downloads
90
decreased by-32.84%
Maintainers
2
Install size
41.4 kB
Created
Weekly downloads
 

Readme

Source

chai-param

Use chai to validate your method's parameters

Quick start

Install it on your project

npm install chai-param

Require and load it

var chai = require('chai'),
    chaiParam = require('chai-param'),
    expect = chai.expect,
    should = chai.should(),
    param = chaiParam.param;

chai.use(chaiParam);

Happy method guarding :)

function register(user, pass) {
	// using should
	param(user, 'user', 'UsersCtl.register').should.not.be.empty;
	
	// or using expect
	expect(user).param('user', 'UsersCtl.register')
		.to.have.length.above(5)
		.and.below(16);
}

Config

Chai-param can be configured by setting the values in chaiParam.config object properties. E.g:

var chaiParam = require('chai-param');

chaiParam.config.improveMessages = true;

improveMessages

Type: Boolean Default: true

Controls whether or not chai-param should replace chai's messages by more descriptive ones. So, for example, instead of getting

UserCtl.register: expected 'asdf' to have a length above 5 but got 4

You'll get...

Improved error message

showCaller on error messages

Type: Boolean Default: true

This option is only available for node and requires improveMessages to be true.

chaiParam.config.showCaller = true;

disableColors

Type: Boolean Default: false

Disables message coloring. Boring, but useful for tests.

Keywords

FAQs

Package last updated on 27 Jan 2016

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc