Skip to content

Commit dbce51e

Browse files
committed
Add functions to objType utility
1 parent 070df3f commit dbce51e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/utils.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Determine the type of a variable/object.
22
export const objType = function(obj) {
3-
if (typeof obj === 'undefined') return 'undefined';
4-
else if (typeof obj === 'string' || obj instanceof String) return 'string';
5-
else if (typeof obj === 'number' || obj instanceof Number) return 'number';
6-
else if (!!obj && obj.constructor === Array) return 'array';
7-
else if (obj && obj.nodeType === 1) return 'element';
8-
else if (typeof obj === 'object') return 'object';
9-
else return 'unknown';
3+
var type = typeof obj;
4+
if (type === 'undefined') return 'undefined';
5+
else if (type === 'string' || obj instanceof String) return 'string';
6+
else if (type === 'number' || obj instanceof Number) return 'number';
7+
else if (type === 'function' || obj instanceof Function) return 'function';
8+
else if (!!obj && obj.constructor === Array) return 'array';
9+
else if (obj && obj.nodeType === 1) return 'element';
10+
else if (type === 'object') return 'object';
11+
else return 'unknown';
1012
};
1113

1214
// Create an HTML element with optional className, innerHTML, and style.

0 commit comments

Comments
 (0)