(input: unknown)
| 151 | * @since 4.0.0 |
| 152 | */ |
| 153 | export const toJson = (input: unknown): unknown => { |
| 154 | try { |
| 155 | input = redact(input) |
| 156 | if ( |
| 157 | Predicate.hasProperty(input, "toJSON") && |
| 158 | Predicate.isFunction(input["toJSON"]) && |
| 159 | input["toJSON"].length === 0 |
| 160 | ) { |
| 161 | return input.toJSON() |
| 162 | } else if (Array.isArray(input)) { |
| 163 | return input.map(toJson) |
| 164 | } |
| 165 | return input |
| 166 | } catch { |
| 167 | return "[toJSON threw]" |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Converts an unknown value to a string for diagnostics. |
no test coverage detected