1 var toString = Object.prototype.toString;
4 * Get the native `typeof` a value.
7 * @return {*} Native javascript type
10 module.exports = function kindOf(val) {
11 var type = typeof val;
14 if (type === 'undefined') {
20 if (val === true || val === false || val instanceof Boolean) {
23 if (type === 'string' || val instanceof String) {
26 if (type === 'number' || val instanceof Number) {
31 if (type === 'function' || val instanceof Function) {
32 if (typeof val.constructor.name !== 'undefined' && val.constructor.name.slice(0, 9) === 'Generator') {
33 return 'generatorfunction';
39 if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) {
43 // check for instances of RegExp and Date before calling `toString`
44 if (val instanceof RegExp) {
47 if (val instanceof Date) {
52 type = toString.call(val);
54 if (type === '[object RegExp]') {
57 if (type === '[object Date]') {
60 if (type === '[object Arguments]') {
63 if (type === '[object Error]') {
66 if (type === '[object Promise]') {
75 // es6: Map, WeakMap, Set, WeakSet
76 if (type === '[object Set]') {
79 if (type === '[object WeakSet]') {
82 if (type === '[object Map]') {
85 if (type === '[object WeakMap]') {
88 if (type === '[object Symbol]') {
92 if (type === '[object Map Iterator]') {
95 if (type === '[object Set Iterator]') {
98 if (type === '[object String Iterator]') {
99 return 'stringiterator';
101 if (type === '[object Array Iterator]') {
102 return 'arrayiterator';
106 if (type === '[object Int8Array]') {
109 if (type === '[object Uint8Array]') {
112 if (type === '[object Uint8ClampedArray]') {
113 return 'uint8clampedarray';
115 if (type === '[object Int16Array]') {
118 if (type === '[object Uint16Array]') {
119 return 'uint16array';
121 if (type === '[object Int32Array]') {
124 if (type === '[object Uint32Array]') {
125 return 'uint32array';
127 if (type === '[object Float32Array]') {
128 return 'float32array';
130 if (type === '[object Float64Array]') {
131 return 'float64array';
134 // must be a plain object
139 * If you need to support Safari 5-7 (8-10 yr-old browser),
140 * take a look at https://github.com/feross/is-buffer
143 function isBuffer(val) {
144 return val.constructor
145 && typeof val.constructor.isBuffer === 'function'
146 && val.constructor.isBuffer(val);