Function truncate

Truncates the provided string to fit in the max character length if it truncates it will add the ending to the start or end of the string

  • Parameters

    • str: string

      String to be truncated

    • maxLength: number

      Max length of the string

    • param2: Partial<Options> = ...

    Returns string

    const str = truncate('Hello World!', 5, { ending: '...' });

    console.log(str); // 'hello...'
    const str = truncate('Hello World!', 6, { ending: '...', reverse: true });

    console.log(str); // '...World!'