( value: unknown, indent: number, currentIndent: string, opts: SerializationOptions, seen: unknown[] )
| 108 | : "an object" |
| 109 | |
| 110 | const stringifyUnquoted = ( |
| 111 | value: unknown, |
| 112 | indent: number, |
| 113 | currentIndent: string, |
| 114 | opts: SerializationOptions, |
| 115 | seen: unknown[] |
| 116 | ): string => { |
| 117 | if (typeof value === "function") return printableOpts.onFunction(value) |
| 118 | if (typeof value === "symbol") return printableOpts.onSymbol(value) |
| 119 | if (typeof value !== "object" || value === null) |
| 120 | return serializePrimitive(value as never) |
| 121 | if (seen.includes(value)) |
| 122 | return (opts.onCycle ?? printableOpts.onCycle)(value) |
| 123 | |
| 124 | const nextIndent = currentIndent + " ".repeat(indent) |
| 125 | const nextSeen = [...seen, value] |
| 126 | |
| 127 | if (isArray(value)) { |
| 128 | if (value.length === 0) return "[]" |
| 129 | const items = value |
| 130 | .map(item => stringifyUnquoted(item, indent, nextIndent, opts, nextSeen)) |
| 131 | .join(indent ? ",\n" + nextIndent : ", ") |
| 132 | return indent ? `[\n${nextIndent}${items}\n${currentIndent}]` : `[${items}]` |
| 133 | } |
| 134 | |
| 135 | const ctorName = constructorNameOf(value, opts) ?? "Object" |
| 136 | |
| 137 | if (ctorName === "Object") { |
| 138 | const keyValues = ownEntriesOf(value, opts).map(([key, val]) => { |
| 139 | const stringifiedKey = |
| 140 | typeof key === "symbol" ? printableOpts.onSymbol(key) |
| 141 | : isDotAccessible(key) ? key |
| 142 | : JSON.stringify(key) |
| 143 | const stringifiedValue = stringifyUnquoted( |
| 144 | val, |
| 145 | indent, |
| 146 | nextIndent, |
| 147 | opts, |
| 148 | nextSeen |
| 149 | ) |
| 150 | return `${nextIndent}${stringifiedKey}: ${stringifiedValue}` |
| 151 | }) |
| 152 | |
| 153 | if (keyValues.length === 0) return "{}" |
| 154 | |
| 155 | return indent ? |
| 156 | `{\n${keyValues.join(",\n")}\n${currentIndent}}` |
| 157 | : `{${keyValues.join(", ")}}` |
| 158 | } |
| 159 | |
| 160 | if (isDate(value)) return describeCollapsibleDate(value) |
| 161 | |
| 162 | return expressionOf(value) ?? ctorName |
| 163 | } |
| 164 | |
| 165 | export const printSymbol = (symbol: symbol): string => |
| 166 | `Symbol(${baseNameOfSymbol(symbol)})` |
no test coverage detected