UNPKG

type-component

Version:

Cross-browser type assertions (less broken typeof)

31 lines (24 loc) 615 B
/** * toString ref. */ var toString = Object.prototype.toString; /** * Return the type of `val`. * * @param {Mixed} val * @return {String} * @api public */ module.exports = function(val){ switch (toString.call(val)) { case '[object Function]': return 'function'; case '[object Date]': return 'date'; case '[object RegExp]': return 'regexp'; case '[object Arguments]': return 'arguments'; case '[object Array]': return 'array'; } if (val === null) return 'null'; if (val === undefined) return 'undefined'; if (val === Object(val)) return 'object'; return typeof val; };