forked from angus-c/just
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (28 loc) · 710 Bytes
/
Copy pathindex.js
File metadata and controls
31 lines (28 loc) · 710 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
module.exports = typeOf;
/*
typeOf({}); // 'object'
typeOf([]); // 'array'
typeOf(function() {}); // 'function'
typeOf(async function() {}); // 'function'
typeOf(/a/); // 'regexp'
typeOf(new Date()); // 'date'
typeOf(null); // 'null'
typeOf(undefined); // 'undefined'
typeOf('a'); // 'string'
typeOf(1); // 'number'
typeOf(true); // 'boolean'
*/
function typeOf(obj) {
if (obj === null) {
return 'null';
}
if (obj !== Object(obj)) {
return typeof obj;
}
var result = {}.toString
.call(obj)
.slice(8, -1)
.toLowerCase();
// strip function adornments (e.g. "sAsyncFunction")
return result.toLowerCase().indexOf('function') > -1 ? 'function' : result;
}