(value: unknown)
| 1 | export function stringifyUnknown(value: unknown): string { |
| 2 | if (value === null || value === undefined) { |
| 3 | return ""; |
| 4 | } |
| 5 | |
| 6 | if (typeof value === "string") { |
| 7 | return value; |
| 8 | } |
| 9 | |
| 10 | if (typeof value === "number") { |
| 11 | return Number.prototype.toString.call(value); |
| 12 | } |
| 13 | |
| 14 | if (typeof value === "bigint") { |
| 15 | return BigInt.prototype.toString.call(value); |
| 16 | } |
| 17 | |
| 18 | if (typeof value === "boolean") { |
| 19 | return value ? "true" : "false"; |
| 20 | } |
| 21 | |
| 22 | if (typeof value === "symbol") { |
| 23 | return value.description ?? ""; |
| 24 | } |
| 25 | |
| 26 | if (value instanceof Date) { |
| 27 | return value.toISOString(); |
| 28 | } |
| 29 | |
| 30 | if (Array.isArray(value)) { |
| 31 | return value |
| 32 | .map((item) => stringifyUnknown(item)) |
| 33 | .filter((item) => item.length > 0) |
| 34 | .join(", "); |
| 35 | } |
| 36 | |
| 37 | try { |
| 38 | const json = JSON.stringify(value); |
| 39 | return typeof json === "string" ? json : ""; |
| 40 | } catch { |
| 41 | return ""; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | export function stringifyUnknownArray(value: unknown): string[] { |
| 46 | if (Array.isArray(value)) { |
no outgoing calls
no test coverage detected