Skip to content

iguntur/v-type

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

☔ Validation type of value is assignable.

Resources

License

Stars

Watchers

Forks

Packages

No packages published