UNPKG

is-typeof

Version:
74 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var toString = Object.prototype.toString; var typeClass = { arguments: "Arguments", array: "Array", boolean: "Boolean", date: "Date", error: "Error", function: "Function", number: "Number", object: "Object", regexp: "RegExp", string: "String" }; /** Test if a value is a string. */ exports.isString = isType("String"); /** Test if a value is a number. */ exports.isNumber = isType("Number"); /** Test if a value is a boolean. */ exports.isBoolean = isType("Boolean"); /** Test if a value is a date. */ exports.isDate = isType("Date"); /** Test if a value is a regex. */ exports.isRegExp = isType("RegExp"); /** Test if a value is an error. */ exports.isError = isType("Error"); /** Test if a value is a function. */ exports.isFunction = isType("Function"); /** Test if a value is an arguments object. */ exports.isArguments = isType("Arguments"); /** Test if a value is a plain object. */ exports.isObject = isType("Object"); /** Test if a value is an array. */ exports.isArray = isType("Array"); /** Test if a value is a stream. */ function isStream(val) { return val != null && typeof val.pipe === "function"; } exports.isStream = isStream; /** Test if a value is a buffer. */ function isBuffer(val) { return (val != null && val.constructor != null && typeof val.constructor.isBuffer === "function"); } exports.isBuffer = isBuffer; /** Test if a value is empty. */ function isEmpty(val) { // tslint:disable-next-line for (var key in val) { return false; } return true; } exports.isEmpty = isEmpty; /** * Creates a type checker function based on the given type. * @internal */ function isType(name) { var type = name.toLowerCase(); return function (val) { var typeOf = typeof val; switch (typeOf) { case "object": case "function": return toString.call(val) === "[object " + typeClass[type] + "]"; default: return typeOf === type; } }; } //# sourceMappingURL=index.js.map