v-type

0.1.0 • Public • Published

v-type Build Status

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

Dependencies (0)

    Dev Dependencies (2)

    Package Sidebar

    Install

    npm i v-type

    Weekly Downloads

    1

    Version

    0.1.0

    License

    MIT

    Last publish

    Collaborators

    • guntur