(data: unknown, opts?: PrintableOptions)
| 74 | console.log(printable(data, opts)) |
| 75 | |
| 76 | export const printable = (data: unknown, opts?: PrintableOptions): string => { |
| 77 | switch (domainOf(data)) { |
| 78 | case "object": |
| 79 | const o = data as dict |
| 80 | const serializationOpts = |
| 81 | opts?.ownDataOnly ? ownDataPrintableOpts : printableOpts |
| 82 | const ctorName = constructorNameOf(o, serializationOpts) ?? "Object" |
| 83 | return ( |
| 84 | ctorName === "Object" || ctorName === "Array" ? |
| 85 | opts?.quoteKeys === false ? |
| 86 | stringifyUnquoted(o, opts?.indent ?? 0, "", serializationOpts, []) |
| 87 | : JSON.stringify( |
| 88 | _serialize(o, serializationOpts, []), |
| 89 | null, |
| 90 | opts?.indent |
| 91 | ).replace(quotedMarkedValue, "$1") |
| 92 | : stringifyUnquoted(o, opts?.indent ?? 0, "", serializationOpts, []) |
| 93 | ) |
| 94 | case "symbol": |
| 95 | return printableOpts.onSymbol(data as symbol) |
| 96 | default: |
| 97 | return serializePrimitive(data as SerializablePrimitive) |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // errors print an object by its kind, so its contents never reach a message |
| 102 | export const printKind = (data: unknown): string => |
no test coverage detected