type-dragoon
v1.0.5
Published
Type enforcer for JavaScript in Node.js
Downloads
3
Maintainers
Readme
type-dragoon
Type enforcer for JavaScript in Node.js
Installation
npm i type-dragoon
Importing
const t = require('type-dragoon');
Usage
General
const name = 'Lelouch';
const age = 18;
const alive = false;
t({string: name}, {number: age}, {boolean: alive});
// continues if correct types, else throws an error
Multiple types
t({'number|string': 18});
Custom errors
t({boolean: 'not a boolean', TypeError: 'My generic error'});
// throws 'TypeError: My generic error'
Callback on error
t({object: undefined, onWrongType: () => {
console.log('My nice callback');
}});
Data types
- undefined
- null
- object
- array
- boolean
- function
- number
- bigint
- string
- symbol
Error types (mdn)
- EvalError
- RangeError
- ReferenceError
- SyntaxError
- TypeError
- URIError