wardon v0.0.0
wardon
wardon provides you with a suite of reusable guards that you can use to check the parameters to your functions, methods or constructor functions.
wardon is very simple for you to extend so you can implement your own guards.
Releases
See the changelog for more information.
Limitations
Or, as one of my tutors once put it 'Messen kommt von Mist', so be sure what you compare what with.
wardon.prototype
When using node's util.inherits
, be aware that the prototype chain is not
established the way it should be. See issue #4179 for more information.
With the new ES2015 features, you will not have to use util.inherits()
. And if you need to establish the prototype
chain yourself, make sure that you follow the rules, see for example OOPinJS2.
In addition, most native node classes such as fs.WriteStream
do not have Object
as part of their
prototype chain, again a shortcoming of the node API, so you will not be able to test their prototype
chain against Object
.
The same holds true for coffee-script, which also fails to establish a proper prototype chain.
In order to overcome that situation, you may want to have a look at the vibejs-subclassof project and include that with your custom test code. Due to its complexity and because of the fact that it supports legacy code, its functionality will not be included with this project.
Motivation
For my own projects I find that I repeat the same code and error messages over and over again when implementing guards for parameters passed to functions. Having looked at the available options over at npmjs.org I did find not a single package that would meet my requirements.
Project Site
The project site, see (2) under resources below, provides more insight into the project, including test coverage reports and API documentation.
Contributing
You are very welcome to propose changes and report bugs, or even provide pull requests on github.
See the contributing guidelines for more information.
Contributors
- Carsten Klein Maintainer
Building
See build process and the available build targets for more information on how to build this.
See also development dependencies and on how to deal with them.
Installation
npm --save wardon
Runtime Dependencies
The dependencies denoted in italics must be provided by the using project.
Usage
import * as wardon from 'wardon';
export function do_something(param1, param2)
{
// mandatory number parameter
wardon.isNumber('param1', param1).min(1).max(10).check();
// optional parameter
wardon.instanceOf('param2', param2, SomeClass).optional().check();
}
For more information, see the API docs available on the project site (2).
Similar Projects
- argtype - decorator style function argument validation
Resources
- (1) Github Site
- (2) Project Site
8 years ago