@bemoje/assert-type
Perform easy type-checks with a simple type assertion.
Version
Travis CI
Dependencies
Stats
Donate
Installation
npm install @bemoje/assert-typenpm install --save @bemoje/assert-typenpm install --save-dev @bemoje/assert-type
Usage
/** * @param * @param * @param * @param */ { // quite extensive, but now very simple type-checks. // other code return 'Types are checked and OK'} const STRING = 'a'const NUMBER = 1const ARRAY = // NOTE: 'undefined' always passes type check //=> 'Types are checked and OK' //=> 'Types are checked and OK' //=> 'Types are checked and OK' //=> throws TypeError('Expected String, got Array') //=> throws TypeError('Expected Number, got Array') //=> throws TypeError('Expected Null, got Array') //=> throws TypeError('Expected String, Number, got Array')
Tests
Uses Jest to test module functionality. Run tests to get coverage details.
npm run test
API
assertType
Perform easy type-checks with a simple type assertion.
Parameters
-
constructors
(function | null | Array<(function | null)>) The expected type's constructor(s). Also accepted as a "constructor" is the null value. -
value
any The value to evaluate
Returns
void