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
66export let _cur = 0
77export let _last = true
88
9- /** @type {*[]} */
10- let items
9+ let items = []
1110let isArray = false
1211let brackets = [' ' , ' ' ]
1312let collapsed = false
@@ -21,16 +20,27 @@ function getType(i) {
2120 return typeof i
2221}
2322
23+ /**
24+ * @param {*} i
25+ * @returns {string}
26+ */
27+ function stringify (i ) {
28+ return JSON .stringify (i)
29+ }
30+
2431/**
2532 * @param {*} i
2633 * @returns {string}
2734 */
2835function 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+ }
3444}
3545
3646function clicked () {
@@ -79,7 +89,7 @@ $: collapsed = depth < _cur
7989 {#each items as i , idx }
8090 <li >
8191 {#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 >
8393 {/if }
8494 {#if getType (json [i ]) === ' object' }
8595 <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