Truncate text in the middle, preserving start and end. Useful for file paths: /home/user/.../config.json
The text to truncate
Maximum width in terminal cells
Truncated text with ellipsis in middle, or original if it fits
truncateMiddle("/home/user/documents/project/src/index.ts", 25)// "/home/user/…/src/index.ts" Copy
truncateMiddle("/home/user/documents/project/src/index.ts", 25)// "/home/user/…/src/index.ts"
Truncate text in the middle, preserving start and end. Useful for file paths: /home/user/.../config.json