(input: unknown[], delimiter?: string)
| 67 | * @returns Joined values |
| 68 | */ |
| 69 | export function safeJoin(input: unknown[], delimiter?: string): string { |
| 70 | if (!Array.isArray(input)) { |
| 71 | return ''; |
| 72 | } |
| 73 | |
| 74 | const output = []; |
| 75 | // eslint-disable-next-line typescript/prefer-for-of |
| 76 | for (let i = 0; i < input.length; i++) { |
| 77 | const value = input[i]; |
| 78 | if (isPrimitive(value)) { |
| 79 | output.push(String(value)); |
| 80 | } else if (value instanceof Error) { |
| 81 | // While stringifyValue does not special-case errors, because we later handle them specifically based on the [object XXX] fallback, |
| 82 | // in this method we want to render them more nicely |
| 83 | output.push(value.message ? `${value.name}: ${value.message}` : value.name); |
| 84 | } else { |
| 85 | output.push(stringifyValue(undefined, value)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return output.join(delimiter); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Checks if the given value matches a regex or string |
no test coverage detected