centerTruncate.ts 258 B

1234567
  1. export function centerTruncate(value: string, maxLength: number = 20) {
  2. const divider = Math.floor(maxLength / 2);
  3. if (value.length > maxLength) {
  4. return `${value.slice(0, divider)}\u2026${value.slice(value.length - divider)}`;
  5. }
  6. return value;
  7. }