moko
Version:
Generator based models
36 lines (29 loc) • 737 B
JavaScript
/**
* https://github.com/component/type
*
* TODO: un-bundle, once we have a way to use component and node together
*/
/**
* 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;
};