All files / static / util / typeof_detail.js

100.00% Branches 4/4
100.00% Lines 28/28
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
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x13
x61
x61
x62
x62
x1
x108
x108
x61
x103
x103
x1
x66
x66
x61

























/**
 * @file Improved typeof - get type name or object name
 *
 * @author aKuad
 */

/**
 * Improved typeof - get type name or object name
 *
 * @param {*} obj Object to check type or object name
 * @returns Type or object name
 */
export function typeof_detail(obj) {
  // null is special case
  if(obj === null) {
    return "null";
  }

  // primitive type
  const obj_typeof = typeof obj;
  if(obj_typeof !== "object") {
    return obj_typeof;
  }

  // constructor name
  return obj.constructor.name;
}