-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype.js
More file actions
35 lines (29 loc) · 772 Bytes
/
type.js
File metadata and controls
35 lines (29 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// https://github.com/component/type
/**
* toString ref.
*/
let toString = Object.prototype.toString
/**
* Return the type of `val`.
*
* @param {Mixed} val
* @return {String}
* @api public
*/
export default function (val) {
switch (toString.call(val)) {
case '[object Date]': return 'date'
case '[object RegExp]': return 'regexp'
case '[object Arguments]': return 'arguments'
case '[object Array]': return 'array'
case '[object Error]': return 'error'
}
if (val === null) { return 'null' }
if (val === undefined) { return 'undefined' }
if (val !== val) { return 'nan' }
if (val && val.nodeType === 1) { return 'element' }
val = val.valueOf
? val.valueOf()
: Object.prototype.valueOf.apply(val)
return typeof val
}