type-checker
A simple, comprehensive and lightweight type-checking library for JavaScript.
Most type-checking libraries are compatible with 10 or 20 types. This library offers 50+, but the minified library is still just 3KB in size.
It's easy to check for anything from a Number, String or Array to a Promise, WeakMap or Generator – and much more!
Install
Using npm:
npm i type-checker
Using yarn:
yarn add type-checker
Import
const { isAsyncFunction, isFunction, isPromise } = require('type-checker');
Documentation
To view our docs, click here.
Quick Example 1
const { isAsyncFunction, isFunction } = require('type-checker');
function run(fn) {
if (isFunction(fn) || isAsyncFunction(fn)) {
fn();
} else {
return new TypeError('run expects a function or an async function.');
}
}