all files / src/ type.js

85.71% Statements 12/14
75% Branches 6/8
100% Functions 1/1
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15       82×   74× 74×    
const types = 'Boolean Number String Function Array Date RegExp Object Error'.split(' ')
const class2type = {}
 
for (let i = 0; i < types.length; i++) {
  class2type['[object ' + types[i] + ']'] = types[i].toLowerCase()
}
 
export default function type (obj) {
  if (obj === null) {
    return obj + ''
  }
  return typeof obj === 'object' || typeof obj === 'function'
    ? class2type[Object.prototype.toString.call(obj)] || 'object' : typeof obj
}