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

Function serializeProperty

lib/stringify.js:61–102  ·  view source on GitHub ↗
(key, holder)

Source from the content-addressed store, hash-verified

59 return serializeProperty('', {'': value})
60
61 function serializeProperty (key, holder) {
62 let value = holder[key]
63 if (value != null) {
64 if (typeof value.toJSON5 === 'function') {
65 value = value.toJSON5(key)
66 } else if (typeof value.toJSON === 'function') {
67 value = value.toJSON(key)
68 }
69 }
70
71 if (replacerFunc) {
72 value = replacerFunc.call(holder, key, value)
73 }
74
75 if (value instanceof Number) {
76 value = Number(value)
77 } else if (value instanceof String) {
78 value = String(value)
79 } else if (value instanceof Boolean) {
80 value = value.valueOf()
81 }
82
83 switch (value) {
84 case null: return 'null'
85 case true: return 'true'
86 case false: return 'false'
87 }
88
89 if (typeof value === 'string') {
90 return quoteString(value, false)
91 }
92
93 if (typeof value === 'number') {
94 return String(value)
95 }
96
97 if (typeof value === 'object') {
98 return Array.isArray(value) ? serializeArray(value) : serializeObject(value)
99 }
100
101 return undefined
102 }
103
104 function quoteString (value) {
105 const quotes = {

Callers 3

stringify.jsFile · 0.85
serializeObjectFunction · 0.85
serializeArrayFunction · 0.85

Calls 3

quoteStringFunction · 0.85
serializeArrayFunction · 0.85
serializeObjectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…