mwg API
    Preparing search index...

    Function ellipsize

    • text cut to fit maxWidth, ending in ellipsis, as measured by measure (the width of a string in whatever font the caller draws it with). A text that already fits comes back unchanged.

      Parameters

      • text: string
      • maxWidth: number
      • measure: (text: string) => number
      • ellipsis: string = '…'

      Returns string

      import { ellipsize } from '@datamoc/mwg/two-d/ui';

      const width = (text: string) => text.length * 10;
      console.log(ellipsize('3. Le Fleuve profond (verrouillé)', 150, width)); // 3. Le Fleuve…