-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject-value.vue
113 lines (111 loc) · 2.61 KB
/
object-value.vue
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<template>
<span
:class="['object-value', calcObject.class]"
:title="type === 'string' ? calcObject.noQouteText : calcObject.text"
>{{ calcObject.text
}}<template v-if="type === 'function'"
><span class="object-value-function-prefix">ƒ </span
><span class="object-value-function-name"
>{{ object.name }}()</span
></template
></span
>
</template>
<script>
export default {
name: 'object-value',
props: ['object'],
computed: {
type() {
return typeof this.object
},
calcObject() {
const o = this.object
switch (typeof o) {
case 'bigint':
return {
class: 'object-value-number',
text: `${o}n`,
}
case 'number':
return {
class: 'object-value-number',
text: `${o}`,
}
case 'string':
return {
class: 'object-value-string',
text: `"${o}"`,
noQouteText: `${o}`,
}
case 'boolean':
return {
class: 'object-value-boolean',
text: `${o}`,
}
case 'undefined':
return {
class: 'object-value-undefined',
text: 'undefined',
}
case 'object':
if (o === null) {
return {
class: 'object-value-null',
text: 'null',
}
}
if (o instanceof Date) {
return {
class: '',
text: o.toString(),
}
}
if (o instanceof RegExp) {
return {
class: 'object-value-regexp',
text: o.toString(),
}
}
if (Array.isArray(o)) {
return {
class: '',
text: `Array(${o.length})`,
}
}
if (!o.constructor) {
return {
class: '',
text: 'Object',
}
}
if (
typeof o.constructor.isBuffer === 'function' &&
o.constructor.isBuffer(o)
) {
return {
class: '',
text: `Buffer[${o.constructor.name}]`,
}
}
return {
class: '',
text: o.constructor.name,
}
case 'function':
return {
class: '',
text: '',
}
case 'symbol':
return {
class: 'object-value-symbol',
text: o.toString(),
}
}
},
},
methods: {},
}
</script>
<style lang="less"></style>