-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlogTern.js
More file actions
57 lines (52 loc) · 1.73 KB
/
logTern.js
File metadata and controls
57 lines (52 loc) · 1.73 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
let vUndefined;
const vNull = null;
const vString = "some text";
const vNumber = 10;
const vBoolean = false;
const vSymbol = Symbol('foo');
const vBigInt = BigInt(9007199254740991);
const vObjectObj = {property: "Value"}
const vArrayObject = [1, 2.1, "string"]
function functionObject(params) {}
async function functionAsync(params) {}
class ClassObj {}
const LOG = (VAR) => {
const LOG = console.log;
// 1. check if the variable is a primitive type and not an object ?
( typeof VAR==="string"||typeof VAR==="number"||typeof VAR==="boolean"||typeof VAR==="symbol"||typeof VAR==="bigint"
&& typeof VAR !=="object" && VAR !==null && VAR !==undefined
) ?
LOG("\n PRIMITIVE: ", typeof VAR, "\n Value: ",VAR)
:
// 2. ELSE, Check what kind of object it is
// A. check if variable is an array ?
( Array.isArray(VAR) ) ?
// if it is an array, log it with table
LOG(`type: Array Object,
data:
`)& console.table(VAR)
:
// B. check if variable is object object and the state of the object
(VAR !==null && typeof VAR === "object") ?
LOG(`type: ${VAR}
frozen: ${Object.isFrozen(VAR)}
sealed: ${Object.isSealed(VAR)}
data:
${JSON.stringify(VAR)}
`)
:
// C. check if variable is function
(typeof VAR === "function") ?
LOG(`type: ${VAR},
frozen: ${Object.isFrozen(VAR)},
sealed: ${Object.isSealed(VAR)}
`)
:
// D. Null BUG Check
// due to the typeof null bug we, we check the value instead of using the operator
(VAR===null) ?
LOG("\n must be null: ", "'",typeof VAR,"'")
:
// E. Log as undefined
LOG("\n must be undefined... \n");
}