Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Use chai to validate your method's parameters
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);
}
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;
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...
Type:
Boolean
Default:true
This option is only available for node and requires improveMessages
to be true
.
chaiParam.config.showCaller = true;
Type:
Boolean
Default:false
Disables message coloring. Boring, but useful for tests.
FAQs
Adds useful methods for using chai to validate function parameters
The npm package chai-param receives a total of 219 weekly downloads. As such, chai-param popularity was classified as not popular.
We found that chai-param demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.