(value, max)
| 363 | } |
| 364 | |
| 365 | function truncateMiddle(value, max) { |
| 366 | const str = String(value); |
| 367 | |
| 368 | if (!Number.isFinite(max) || max <= 0) return ""; |
| 369 | if (str.length <= max) return str; |
| 370 | if (max <= 3) return str.slice(0, max); |
| 371 | |
| 372 | const available = max - 1; |
| 373 | const left = Math.ceil(available / 2); |
| 374 | const right = Math.floor(available / 2); |
| 375 | |
| 376 | return `${str.slice(0, left)}…${str.slice(-right)}`; |
| 377 | } |
| 378 | |
| 379 | function padRight(value, width) { |
| 380 | return String(value).padEnd(width, " "); |
no test coverage detected