wtf
Tiny JS type-checking library.
Install
node.js
npm install wtf-is
var wtf = ;
browser
git clone
this repo, or download wtf.js or wtf.min.js
Include the script as an AMD module, or directly in a script tag.
;
Using the script tag creates a global variable wtf
Usage
wtf.is(<thing>)
Basic type-checking: wtf; // 'string'wtf; // 'float'wtf; // 'array'wtf; // 'function'wtf; // 'infinite'wtf; // 'NaN'wtf; // 'integer'
wtf.is()
distinguishes integers from floats.
Before you send me nasty emails, I know JavaScript only has one Number type. This is done simply because it is potentially useful to know when a number is an integer or not, especially when...
wtf(<thing>).switch({types})
Handling input: // assume someThing expects a percentage alpha value// but you want users to be able to provide 0-255 as well { ;}
You can also simply use number:
if you want to match both integers and floats.
{ ;}
Use the internals:
cross-platform versions of the checks built-in to modern browsers
wtf; // truewtf; // falsewtf; // truewtf; // false