Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iguntur/v-type
:umbrella: Validation type of value is assignable.
https://github.com/iguntur/v-type
Last synced: about 11 hours ago
JSON representation
:umbrella: Validation type of value is assignable.
- Host: GitHub
- URL: https://github.com/iguntur/v-type
- Owner: iguntur
- License: mit
- Created: 2017-05-03T01:58:12.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-05-03T10:22:00.000Z (over 7 years ago)
- Last Synced: 2024-04-23T21:31:09.386Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# v-type [![Build Status](https://travis-ci.org/iguntur/v-type.svg?branch=master)](https://travis-ci.org/iguntur/v-type)
> Validation type of value is assignable.
## Install
```
$ npm install --save v-type
```## Usage
```js
const vType = require('v-type');vType('△', String);
//=> truevType(['△'], 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`The constructor function - __`Function`__, __`Object`__, __`Array`__, __`Map`__, etc...
#### message
Type: `string`
Set the default message.
__Example:__
```js
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](http://iguntur.starmediateknik.com)