1 | var toString = Object.prototype.toString;
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function kindOf(val) {
|
11 | if (val === undefined) {
|
12 | return 'undefined';
|
13 | }
|
14 | if (val === null) {
|
15 | return 'null';
|
16 | }
|
17 | if (typeof val !== 'object') {
|
18 | return typeof val;
|
19 | }
|
20 |
|
21 | if (Array.isArray(val)) {
|
22 | return 'array';
|
23 | }
|
24 |
|
25 | var type = toString.call(val);
|
26 |
|
27 | if (val instanceof RegExp || type === '[object RegExp]') {
|
28 | return 'regexp';
|
29 | }
|
30 | if (val instanceof Date || type === '[object Date]') {
|
31 | return 'date';
|
32 | }
|
33 | if (type === '[object Function]') {
|
34 | return 'function';
|
35 | }
|
36 |
|
37 | return type.slice(8, -1).toLowerCase();
|
38 | };
|