is-typeof
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published


Is-TypeOf
API Stability TypeScript Styled with prettier Build status Test Coverage NPM Version Downloads Browser Bundle Size

Lightweight library for better type checking in JavaScript.

Installation

npm install is-typeof

Examples

import * as check from "is-typeof";
 
// String
check.isString("hello"); // true
check.isString(1); // false
 
// Number
check.isNumber(1); // true
check.isNumber("hello"); // false
 
// Boolean
check.isBoolean(true); // true
check.isBoolean(1); // false
 
// Date
check.isDate(new Date); // true
check.isDate(1); // false
 
// RegExp
check.isRegExp(/a/g); // true
check.isRegExp(1); // false
 
// Error
check.isError(new TypeError("Bad!")); // true
check.isError(1); // false
 
// Function
check.isFunction(function () {}); // true
check.isFunction(1); // false
 
// Arguments
(function () {
    check.isArguments(arguments); // true
    check.isArguments([]); // false
}());
 
// Object
check.isObject({}); // true
check.isObject([]); // false
 
// Array
check.isArray([]); // true
check.isArray({}); // false
 
// Stream
check.isStream(fs.createReadStream(...)); // true
check.isStream({}); // false
 
// Buffer
check.isBuffer(new Buffer("")); // true
check.isBuffer(""); // false
 
// Empty
check.isEmpty([]); // true
check.isEmpty([1]); // false

Contributions

  • Use npm test to run tests.

Please feel free to create a PR!

Package Sidebar

Install

npm i is-typeof

Weekly Downloads

697

Version

2.0.2

License

MIT

Last publish

Collaborators

  • dylanpiercey