File tree Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Expand file tree Collapse file tree 1 file changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,7 @@ export let depth = Infinity
6
6
export let _cur = 0
7
7
export let _last = true
8
8
9
- /** @type {*[]} */
10
- let items
9
+ let items = []
11
10
let isArray = false
12
11
let brackets = [' ' , ' ' ]
13
12
let collapsed = false
@@ -21,16 +20,27 @@ function getType(i) {
21
20
return typeof i
22
21
}
23
22
23
+ /**
24
+ * @param {*} i
25
+ * @returns {string}
26
+ */
27
+ function stringify (i ) {
28
+ return JSON .stringify (i)
29
+ }
30
+
24
31
/**
25
32
* @param {*} i
26
33
* @returns {string}
27
34
*/
28
35
function format (i ) {
29
- const t = getType (i)
30
- if (t === ' string' ) return ` ${ JSON .stringify (i)} `
31
- if (t === ' function' ) return ' f () {...}'
32
- if (t === ' symbol' ) return i .toString ()
33
- return i
36
+ switch (getType (i)) {
37
+ case ' function' :
38
+ return ' f () {...}'
39
+ case ' symbol' :
40
+ return i .toString ()
41
+ default :
42
+ return stringify (i)
43
+ }
34
44
}
35
45
36
46
function clicked () {
@@ -79,7 +89,7 @@ $: collapsed = depth < _cur
79
89
{#each items as i , idx }
80
90
<li >
81
91
{#if ! isArray }
82
- <span class ="_jsonKey" >{JSON . stringify (i )}</span ><span class =" _jsonSep" >:</span >
92
+ <span class ="_jsonKey" >{stringify (i )}</span ><span class =" _jsonSep" >:</span >
83
93
{/if }
84
94
{#if getType (json [i ]) === ' object' }
85
95
<svelte:self json ={json [i ]} {depth } _cur={_cur + 1} _last={idx === items .length - 1} />
You can’t perform that action at this time.
0 commit comments