assert-types.js
A small JavaScript library for arguments assertion. Browser and Node.JS compatible.
What's the mission
The main mission is to provide simple and slick API for checking arguments and throwing exceptions. Let's get rid of explicit complex conditions.
Dependencies
- Underscore.js
7.5 Kb unminified with comments, 3.6 Kb minified
How to install
NPM
npm install assert-types
Development and contributing
Install dependencies
npm install && bower install
Build Project
npm run build
Run Tests
npm run test
How to use
Loading library
If you're running in Node.js, you can require
assertTypes.js like so:
var assertTypes = ;
It also supports Require.js:
require; ;
Also assertTypes.js could be included with an HTML <script>
tag and assertTypes
variable will be visible globally.
Assertions
// Numbers assertTypes;assertTypes;assertTypes;assertTypes;assertTypes;assertTypes;assertTypes;assertTypes; // Equals assertTypes; // Boolean assertTypes;assertTypes;assertTypes; // String assertTypes;assertTypes; // Other assertTypesobjectvalue;assertTypes;assertTypes;assertTypes;assertTypes; assertTypes;assertTypes;
In case if assertion is failed, assertTypes will throw Error.
Conditions
Also the library has possibility to define conditions. Let's take a look here:
// These could be translated as: if value is defined then it should be a numberassertTypes; // Other examplesassertTypesobjectvalue assertTypesconditionIfDefined; // You can define your own conditionsassertTypes; // Condition could be a functionassertTypes;
The assertion will be performed if condition is true;