1
1
<script >
2
- import JsonView from ' $lib'
2
+ import { JsonView } from ' $lib'
3
3
4
4
/* eslint-disable */
5
- const test1 = [
5
+ const fixture = [
6
6
{
7
+ desc: ' Test basic' ,
7
8
_id: ' 60702426463e99454c8b9ce4' ,
8
9
index: 0 ,
9
10
guid: ' c47f144e-9390-4e96-8b9f-7f3d0fb4250a' ,
@@ -30,154 +31,41 @@ const test1 = [
30
31
{ id: 2 , name: ' Mcclure Tate' , address: null }
31
32
],
32
33
greeting: ' Hello, Hampton Hardin! You have 2 unread messages.' ,
33
- favoriteFruit: ' banana' ,
34
- contacts: [],
35
- report: {},
36
- email2: null ,
37
- email3: ' ' ,
38
- email4: undefined
34
+ favoriteFruit: ' banana'
39
35
},
40
36
{
41
- _id: ' 60702426f2aec6774924fd63' ,
42
- index: 1 ,
43
- guid: ' 027c7f09-4161-47b2-91c5-01f675094e40' ,
44
- isActive: true ,
45
- balance: ' $2,875.12' ,
46
- picture: ' http://placehold.it/32x32' ,
47
- age: 28 ,
48
- eyeColor: ' brown' ,
49
- name: ' Atkinson Giles' ,
50
- gender: ' male' ,
51
- company: ' BESTO' ,
52
-
53
- phone: ' +1 (986) 474-3672' ,
54
- address: ' 906 Classon Avenue, Riverton, Guam, 4080' ,
55
- about:
56
- ' Consectetur esse et exercitation irure qui adipisicing magna laboris cupidatat incididunt fugiat est. Occaecat irure magna do non cillum magna veniam occaecat. Ullamco officia irure id voluptate consequat amet aliquip in eiusmod deserunt aliquip exercitation culpa excepteur. Enim occaecat consectetur ex non ipsum fugiat amet et proident esse. Commodo cillum ad eiusmod enim sunt sint officia commodo et laborum.\r\n ' ,
57
- registered: ' 2019-05-23T01:23:32 -08:00' ,
58
- latitude: - 37.633187 ,
59
- longitude: - 126.992778 ,
60
- tags: [' esse' , ' nostrud' , ' et' , ' ex' , ' deserunt' , ' veniam' , ' veniam' ],
61
- friends: [
62
- { id: 0 , name: ' Millicent Mcconnell' },
63
- { id: 1 , name: ' Jeanne Wise' },
64
- { id: 2 , name: ' Nichols Roberts' }
65
- ],
66
- greeting: ' Hello, Atkinson Giles! You have 1 unread messages.' ,
67
- favoriteFruit: ' apple'
68
- },
69
- {
70
- _id: ' 607024260a4713fae5019419' ,
71
- index: 2 ,
72
- guid: ' b32f9f9b-0def-46a1-a286-a8196ec4638c' ,
73
- isActive: false ,
74
- balance: ' $3,489.63' ,
75
- picture: ' http://placehold.it/32x32' ,
76
- age: 36 ,
77
- eyeColor: ' blue' ,
78
- name: ' Desiree William' ,
79
- gender: ' female' ,
80
- company: ' LYRICHORD' ,
81
-
82
- phone: ' +1 (975) 485-3348' ,
83
- address: ' 993 Thatford Avenue, Wells, Missouri, 2351' ,
84
- about:
85
- ' Eu nostrud sunt occaecat adipisicing consectetur ipsum aute non voluptate pariatur aliquip excepteur. Minim ea aliqua do dolore tempor aliquip irure. Amet amet quis incididunt irure aute. Lorem amet reprehenderit adipisicing do laborum incididunt labore incididunt laboris velit consequat ut aute. Ea exercitation ut non dolore culpa dolore officia et elit do. Ullamco deserunt cillum aliqua tempor ipsum officia. Lorem cupidatat cillum velit est minim aliquip qui ipsum.\r\n ' ,
86
- registered: ' 2015-08-04T04:33:40 -08:00' ,
87
- latitude: - 15.687988 ,
88
- longitude: - 144.842709 ,
89
- tags: [' do' , ' laborum' , ' fugiat' , ' qui' , ' duis' , ' eu' , ' eiusmod' ],
90
- friends: [
91
- { id: 0 , name: ' Baxter Fulton' },
92
- { id: 1 , name: ' Buckley Dean' },
93
- { id: 2 , name: ' Carmen Fitzpatrick' }
94
- ],
95
- greeting: ' Hello, Desiree William! You have 8 unread messages.' ,
96
- favoriteFruit: ' apple'
37
+ desc: ' Test nested' ,
38
+ nest0: {
39
+ nest1: {
40
+ nest2: {
41
+ nest3: {
42
+ nest4: {
43
+ nest5: {
44
+ nest6: {
45
+ nest7: {
46
+ foo: ' bar'
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ },
55
+ arr: [[[[[[[' baz' ]]]]]]]
97
56
},
98
57
{
99
- _id: ' 60702426dce125ecccee577f' ,
100
- index: 3 ,
101
- guid: ' 0e1d5f0d-84cd-49fe-9b69-1540ab57d509' ,
102
- isActive: true ,
103
- balance: ' $3,254.06' ,
104
- picture: ' http://placehold.it/32x32' ,
105
- age: 20 ,
106
- eyeColor: ' blue' ,
107
- name: ' John Aguirre' ,
108
- gender: ' female' ,
109
- company: ' GINK' ,
110
-
111
- phone: ' +1 (828) 407-2949' ,
112
- address: ' 958 Caton Avenue, Waterford, Puerto Rico, 6386' ,
113
- about:
114
- ' Consequat labore minim excepteur ullamco ex consequat. Occaecat dolore magna enim eiusmod qui dolore sint qui officia. Laborum consectetur fugiat officia et sit incididunt veniam dolor culpa. Sunt anim non id sit ut ipsum laborum est sint commodo nulla incididunt incididunt. Adipisicing eiusmod voluptate deserunt minim esse reprehenderit. Irure elit culpa quis non fugiat aute proident dolore elit consectetur nostrud eu consequat nisi. Ex adipisicing in nisi proident officia.\r\n ' ,
115
- registered: ' 2014-09-06T10:10:11 -08:00' ,
116
- latitude: 41.628236 ,
117
- longitude: 161.223523 ,
118
- tags: [' laboris' , ' exercitation' , ' eiusmod' , ' quis' , ' ad' , ' amet' , ' adipisicing' ],
119
- friends: [
120
- { id: 0 , name: ' Madden Ballard' },
121
- { id: 1 , name: ' Ferguson Gibbs' },
122
- { id: 2 , name: ' Allyson Pickett' }
123
- ],
124
- greeting: ' Hello, John Aguirre! You have 7 unread messages.' ,
125
- favoriteFruit: ' apple'
126
- },
127
- {
128
- _id: ' 6070242649fb4bc3dfca54c2' ,
129
- index: 4 ,
130
- guid: ' 0f4b2fef-f38f-4c93-925c-01f4d015a04a' ,
131
- isActive: false ,
132
- balance: ' $2,684.08' ,
133
- picture: ' http://placehold.it/32x32' ,
134
- age: 25 ,
135
- eyeColor: ' brown' ,
136
- name: ' Clark Rollins' ,
137
- gender: ' male' ,
138
- company: ' KIDGREASE' ,
139
-
140
- phone: ' +1 (945) 464-2097' ,
141
- address: ' 515 Hancock Street, Columbus, Florida, 6747' ,
142
- about:
143
- ' Lorem nostrud quis amet qui. Nisi cupidatat ullamco cillum enim culpa labore fugiat ea laboris in ipsum. Proident enim dolore duis ut deserunt eiusmod consectetur minim ipsum aliquip est commodo.\r\n ' ,
144
- registered: ' 2017-09-05T12:57:25 -08:00' ,
145
- latitude: - 4.239975 ,
146
- longitude: 179.856364 ,
147
- tags: [' mollit' , ' fugiat' , ' dolor' , ' occaecat' , ' dolor' , ' aliquip' , ' ullamco' ],
148
- friends: [
149
- { id: 0 , name: ' Humphrey Simmons' },
150
- { id: 1 , name: ' Lela Berg' },
151
- { id: 2 , name: ' Branch Holder' }
152
- ],
153
- greeting: ' Hello, Clark Rollins! You have 3 unread messages.' ,
154
- favoriteFruit: ' apple'
58
+ desc: ' Test special types' ,
59
+ fn : function () {},
60
+ sym: Symbol (' bar' ),
61
+ null: null ,
62
+ undefined : undefined ,
63
+ empty_string: ' ' ,
64
+ empty_obj: {},
65
+ empty_arr: []
155
66
}
156
67
]
157
- const test2 = {
158
- random: 85 ,
159
- ' random float' : 75.744 ,
160
- bool: true ,
161
- date: ' 1996-12-26' ,
162
- regEx: ' helloooooooooooooooo to you' ,
163
- enum: ' generator' ,
164
- firstname: ' Evaleen' ,
165
- lastname: ' Dorothy' ,
166
- city: ' Labasa' ,
167
- country: ' Virgin Islands, U.S.' ,
168
- countryCode: ' TL' ,
169
- ' email uses current data' : ' [email protected] ' ,
170
- ' email from expression' : ' [email protected] ' ,
171
- array: [' Glynnis' , ' Antonietta' , ' Penelopa' , ' Briney' , ' Viki' ],
172
- ' array of objects' : [
173
- { index: 0 , ' index start at 5' : 5 },
174
- { index: 1 , ' index start at 5' : 6 },
175
- { index: 2 , ' index start at 5' : 7 }
176
- ],
177
- Bobbi: { age: 31 }
178
- }
179
- const test3 = ' test invalid json'
180
- const test4 = { desc: ' Test special types' , foo : function () {}, bar: Symbol (' bar' ), null: null }
68
+ const fixture2 = ' test invalid object'
181
69
/* eslint-enable */
182
70
183
71
let depth = 0
@@ -187,37 +75,47 @@ let depth = 0
187
75
<title >svelte-json-view</title >
188
76
</svelte:head >
189
77
190
- <button
191
- on:click ={() => {
192
- depth = Infinity
193
- }}>EXPAND ALL</button
194
- >
195
- <button
196
- on:click ={() => {
197
- depth = 0
198
- }}>COLLAPSE ALL</button
199
- >
200
- <br /><br />
201
- <div class =" wrap" >
202
- <JsonView json ={test1 } {depth } />
203
- </div >
204
- <hr />
205
- <div class =" wrap" >
206
- <JsonView json ={test2 } depth =" 0" />
207
- </div >
208
- <hr />
209
- <div class =" wrap" >
210
- <JsonView json ={test3 } />
211
- </div >
212
- <hr />
213
- <div class =" wrap" >
214
- <JsonView json ={test4 } />
215
- </div >
78
+ <section >
79
+ <h1 >Basic</h1 >
80
+ <button on:click ={() => (depth = 0 )} id =" btn_0" >DEPTH 0</button >
81
+ <button on:click ={() => (depth = 1 )} id =" btn_1" >DEPTH 1</button >
82
+ <button on:click ={() => (depth = Infinity )} id =" btn_i" >DEPTH INFINITY</button >
83
+ <br /><br />
84
+ <div class =" wrap" id =" basic" >
85
+ <JsonView json ={fixture } {depth } />
86
+ </div >
87
+ </section >
88
+
89
+ <section >
90
+ <h1 >Test default depth=1</h1 >
91
+ <div class =" wrap" id =" depth_1" >
92
+ <JsonView json ={fixture [0 ]} depth ={1 } />
93
+ </div >
94
+ </section >
95
+
96
+ <section >
97
+ <h1 >Test special types</h1 >
98
+ <div class =" wrap" id =" special_types" >
99
+ <JsonView json ={fixture [2 ]} />
100
+ </div >
101
+ </section >
102
+
103
+ <section >
104
+ <h1 >Test invalid object</h1 >
105
+ <div class =" wrap" id =" invalid_obj" >
106
+ <JsonView json ={fixture2 } />
107
+ </div >
108
+ </section >
216
109
217
110
<style >
111
+ section {
112
+ margin : 0 0 4rem 0 ;
113
+ border-bottom : 1px solid black ;
114
+ }
218
115
.wrap {
219
116
font-family : ui-monospace , SFMono-Regular, Menlo, Monaco, Consolas, ' Liberation Mono' ,
220
117
' Courier New' , monospace ;
221
118
font-size : 0.875rem ;
119
+ color : #374151 ;
222
120
}
223
121
</style >
0 commit comments