1 | var toString = Object.prototype.toString;
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function kindOf(val) {
|
11 |
|
12 | if (typeof val === 'undefined') {
|
13 | return 'undefined';
|
14 | }
|
15 | if (val === null) {
|
16 | return 'null';
|
17 | }
|
18 | if (val === true || val === false || val instanceof Boolean) {
|
19 | return 'boolean';
|
20 | }
|
21 | if (typeof val === 'string' || val instanceof String) {
|
22 | return 'string'
|
23 | }
|
24 | if (typeof val === 'number' || val instanceof Number) {
|
25 | return 'number'
|
26 | }
|
27 |
|
28 |
|
29 | if (typeof val === 'function' || val instanceof Function) {
|
30 | return 'function'
|
31 | }
|
32 |
|
33 |
|
34 | if (typeof Array.isArray !== 'undefined' && Array.isArray(val)) {
|
35 | return 'array';
|
36 | }
|
37 |
|
38 |
|
39 | if (val instanceof RegExp) {
|
40 | return 'regexp';
|
41 | }
|
42 | if (val instanceof Date) {
|
43 | return 'date';
|
44 | }
|
45 |
|
46 |
|
47 | var type = toString.call(val);
|
48 |
|
49 | if (type === '[object RegExp]') {
|
50 | return 'regexp';
|
51 | }
|
52 | if (type === '[object Date]') {
|
53 | return 'date';
|
54 | }
|
55 | if (type === '[object Arguments]') {
|
56 | return 'arguments';
|
57 | }
|
58 |
|
59 |
|
60 | if (typeof Buffer !== 'undefined' && Buffer.isBuffer(val)) {
|
61 | return 'buffer';
|
62 | }
|
63 |
|
64 |
|
65 | if (type === '[object Set]') {
|
66 | return 'set';
|
67 | }
|
68 | if (type === '[object WeakSet]') {
|
69 | return 'weakset';
|
70 | }
|
71 | if (type === '[object Map]') {
|
72 | return 'map';
|
73 | }
|
74 | if (type === '[object WeakMap]') {
|
75 | return 'weakmap';
|
76 | }
|
77 | if (type === '[object Symbol]') {
|
78 | return 'symbol';
|
79 | }
|
80 |
|
81 |
|
82 | return 'object';
|
83 | };
|