MCPcopy Index your code
hub / github.com/json5/json5 / serializeObject

Function serializeObject

lib/stringify.js:164–206  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

162 }
163
164 function serializeObject (value) {
165 if (stack.indexOf(value) >= 0) {
166 throw TypeError('Converting circular structure to JSON5')
167 }
168
169 stack.push(value)
170
171 let stepback = indent
172 indent = indent + gap
173
174 let keys = propertyList || Object.keys(value)
175 let partial = []
176 for (const key of keys) {
177 const propertyString = serializeProperty(key, value)
178 if (propertyString !== undefined) {
179 let member = serializeKey(key) + ':'
180 if (gap !== '') {
181 member += ' '
182 }
183 member += propertyString
184 partial.push(member)
185 }
186 }
187
188 let final
189 if (partial.length === 0) {
190 final = '{}'
191 } else {
192 let properties
193 if (gap === '') {
194 properties = partial.join(',')
195 final = '{' + properties + '}'
196 } else {
197 let separator = ',\n' + indent
198 properties = partial.join(separator)
199 final = '{\n' + indent + properties + ',\n' + stepback + '}'
200 }
201 }
202
203 stack.pop()
204 indent = stepback
205 return final
206 }
207
208 function serializeKey (key) {
209 if (key.length === 0) {

Callers 1

serializePropertyFunction · 0.85

Calls 2

serializePropertyFunction · 0.85
serializeKeyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…