(input: unknown)
| 1 | export const stringFromUnknown = (input: unknown): string => { |
| 2 | if (typeof input === 'string') { |
| 3 | return input |
| 4 | } |
| 5 | if (input == undefined) { |
| 6 | return '' |
| 7 | } |
| 8 | if (typeof input === 'function') { |
| 9 | return '<Function>' |
| 10 | } |
| 11 | if (typeof input === 'number' || typeof input == 'boolean' || typeof input === 'bigint' || |
| 12 | typeof input === 'symbol') { |
| 13 | return input.toString() |
| 14 | } |
| 15 | if (typeof input === 'object') { |
| 16 | // For object, only use the toString if it's not the default from `Object`. |
| 17 | if (input.toString !== Object.prototype.toString) { |
| 18 | return input.toString() |
| 19 | } |
| 20 | } |
| 21 | return JSON.stringify(input) |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Clip the input string to the maximum length, using ellipses if it is too long. |
no outgoing calls
no test coverage detected