v-type
v0.1.0
Published
Validation type of value is assignable
Downloads
2
Maintainers
Readme
v-type
Validation type of value is assignable.
Install
$ npm install --save v-type
Usage
const vType = require('v-type');
vType('△', String);
//=> true
vType(['△'], String);
//=> TypeError: Type `Array` is not assignable to type `String`
API
vType(input, TypeName, [message])
Returns throw TypeError
if input
is not assignable to type TypeName
.
input
Required: true
Type: any
TypeName
Required: true
Type: constructor<Function>
The constructor function - Function
, Object
, Array
, Map
, etc...
message
Type: string
Set the default message.
Example:
function foo(bar) {
vType(bar, Object, 'Expected `bar` to be of type `Object`');
console.log(bar.x);
}
foo({x: 'yo'});
//=> 'yo'
foo('1');
//=> 'TypeError: Expected `bar` to be of type `Object`'
License
MIT © Guntur Poetra