jistype
Version:
yet another istype detect library using `Object.prototype.toStirng` to get type.
66 lines (46 loc) • 1.56 kB
text/coffeescript
getType = (obj) ->
Object::toString.call(obj)
util = class module.exports
'[object String]' is getType(obj)
'[object Array]' is getType(obj)
'[object RegExp]' is getType(obj)
!isNaN(obj) and '[object Number]' is getType(obj)
'[object Object]' is getType(obj)
'[object Function]' is getType(obj)
'[object Boolean]' is getType(obj)
'[object Undefined]' is getType(obj)
'[object Null]' is getType(obj)
'[object Date]' is getType(obj)
'[object global]' is getType(obj)
obj instanceof Error and '[object Error]' is getType(obj)
Buffer.isBuffer(obj)
util.isNull(obj) or util.isUndefined(obj)
isNaN(obj)
util.isNull(obj) or
util.isBoolean(obj) or
util.isNumber(obj) or
util.isString(obj) or
util.isUndefined(obj)
obj and util.isFunction(obj.next) and util.isFunction(obj.throw)
obj and obj.constructor and 'GeneratorFunction' is obj.constructor.name
obj and util.isFunction(obj.then)