centerTruncate.ts 545 B

12345678910111213141516
  1. import {formatVersion} from 'sentry/utils/formatters';
  2. export const ELLIPSIS = '\u2026';
  3. export function centerTruncate(value: string, maxLength: number = 20) {
  4. const divider = Math.floor(maxLength / 2);
  5. if (value?.length > maxLength) {
  6. return `${value.slice(0, divider)}${ELLIPSIS}${value.slice(value.length - divider)}`;
  7. }
  8. return value;
  9. }
  10. export function formatVersionAndCenterTruncate(value: string, maxLength?: number) {
  11. const formattedVersion = formatVersion(value);
  12. return centerTruncate(formattedVersion, maxLength);
  13. }