(text: string, maxBytes: number)
| 128 | } |
| 129 | |
| 130 | function clipBytes(text: string, maxBytes: number): string { |
| 131 | if (Buffer.byteLength(text, 'utf-8') <= maxBytes) return text; |
| 132 | // Binary-search the longest prefix that fits. |
| 133 | let lo = 0; |
| 134 | let hi = text.length; |
| 135 | while (lo < hi) { |
| 136 | const mid = (lo + hi + 1) >> 1; |
| 137 | if ( |
| 138 | Buffer.byteLength(text.slice(0, mid), 'utf-8') <= |
| 139 | maxBytes - Buffer.byteLength(TRUNCATED_TAIL, 'utf-8') |
| 140 | ) { |
| 141 | lo = mid; |
| 142 | } else { |
| 143 | hi = mid - 1; |
| 144 | } |
| 145 | } |
| 146 | return text.slice(0, lo) + TRUNCATED_TAIL; |
| 147 | } |
| 148 | |
| 149 | function clipStack(stack: string): string { |
| 150 | if (Buffer.byteLength(stack, 'utf-8') <= STACK_MAX_BYTES) return stack; |
no outgoing calls
no test coverage detected