WarnTypes
Great type checkers out there just return something_
_but I just want a simple type checker which warns.
This is just a simple wrapper of check-types for my need.
Installation
$ npm install --save warn-types
Import
Node app:
var typeWarner = require('warn-types')
React app:
import typeWarner from 'warn-types'
Usage
The typeWarner
is an object which hold single field testResult
and the methods below.
The testResult
by default hold the value null
.
Any of the methods will return a new instance of typeWarner
.
The testResult
of new instance will be true
or false
.
typeWarner.number(thing)
typeWarner.string(thing)
typeWarner.bool(thing)
typeWarner.func(thing)
typeWarner.array(thing)
typeWarner.implement(thing, class)
If the thing
is the expected type, the testResult
will be true
;
Else the testResult
will be false
.
There are also methods with optional
prefix.
They work the same as the above. The difference is...
If the thing
is null
or undefined
, the testResult
will be true
typeWarner.optionalNumber(thing)
typeWarner.optionalString(thing)
typeWarner.optionalBool(thing)
typeWarner.optionalFunc(thing)
typeWarner.optionalArray(thing)
typeWarner.optionalImplement(thing, class)
Extra
All the methods support an extra argument which is optional error message.
For example:
WarnType.number(thing, 'some words go here')