-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsee.js
More file actions
70 lines (66 loc) · 2.2 KB
/
see.js
File metadata and controls
70 lines (66 loc) · 2.2 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
58
59
60
61
62
63
64
65
66
67
68
export function see(a) {
var stack = [];
var ret = [];
function print_rec(a) {
var n, i, keys, key, type, s;
type = typeof(a);
if (type === "object") {
if (a === null) {
ret.push(a);
} else if (stack.indexOf(a) >= 0) {
ret.push("[circular]");
} else {
stack.push(a);
let tab = [...Array(stack.length).keys()].map(() => " ").join("");
if (Array.isArray(a)) {
n = a.length;
ret.push("[");
for(i = 0; i < n; i++) {
if (i !== 0)
ret.push(",");
ret.push("\n", tab);
if (i in a) {
print_rec(a[i]);
} else {
ret.push("<empty>");
}
if (i > 20) {
ret.push("...");
break;
}
}
ret.push(" ]");
} else if (Object.__getClass(a) === "RegExp") {
ret.push(a.toString());
} else {
keys = Object.keys(a);
n = keys.length;
ret.push("{");
for(i = 0; i < n; i++) {
if (i !== 0)
ret.push(",");
ret.push("\n", tab);
key = keys[i];
ret.push(key, ": ");
print_rec(a[key]);
}
ret.push(" }");
}
stack.pop(a);
}
} else if (type === "string") {
s = a.__quote();
if (s.length > 79)
s = s.substring(0, 75) + "...\"";
ret.push(s);
} else if (type === "symbol") {
ret.push(String(a));
} else if (type === "function") {
ret.push("function " + a.name + "()");
} else {
ret.push(a);
}
}
print_rec(a)
return ret.join("");
}