2.0.2 • Published 7 years ago

is-typeof v2.0.2

Weekly downloads
108
License
MIT
Repository
github
Last release
7 years ago

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!