( object: unknown, maxDepth = 10, maxWidth = 10, )
| 92 | ); |
| 93 | |
| 94 | export const stringify = ( |
| 95 | object: unknown, |
| 96 | maxDepth = 10, |
| 97 | maxWidth = 10, |
| 98 | ): string => { |
| 99 | const MAX_LENGTH = 10_000; |
| 100 | let result; |
| 101 | |
| 102 | try { |
| 103 | result = prettyFormat(object, { |
| 104 | maxDepth, |
| 105 | maxWidth, |
| 106 | min: true, |
| 107 | plugins: PLUGINS, |
| 108 | }); |
| 109 | } catch { |
| 110 | result = prettyFormat(object, { |
| 111 | callToJSON: false, |
| 112 | maxDepth, |
| 113 | maxWidth, |
| 114 | min: true, |
| 115 | plugins: PLUGINS, |
| 116 | }); |
| 117 | } |
| 118 | |
| 119 | if (result.length >= MAX_LENGTH && maxDepth > 1) { |
| 120 | return stringify(object, Math.floor(maxDepth / 2), maxWidth); |
| 121 | } else if (result.length >= MAX_LENGTH && maxWidth > 1) { |
| 122 | return stringify(object, maxDepth, Math.floor(maxWidth / 2)); |
| 123 | } else { |
| 124 | return result; |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | export const highlightTrailingWhitespace = (text: string): string => |
| 129 | text.replaceAll(/\s+$/gm, chalk.inverse('$&')); |
no outgoing calls