Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "string/truncate-middle/docs/types/index.d"

Index

Functions

Functions

Export assignment truncateMiddle

  • truncateMiddle(str: string, len: number, seq?: undefined | string): string
  • Truncates a string in the middle to a specified length.

    Parameters

    • str: string

      input string

    • len: number

      output string length (including sequence)

    • Optional seq: undefined | string

      custom replacement sequence (default: ...)

    Returns string

    truncated string

    Example

    var str = 'beep boop';
    var out = truncateMiddle( str, 5 );
    // returns 'b...p'

    Example

    var str = 'beep boop';
    var out = truncateMiddle( str, 5, '>>>' );
    // returns 'b>>>p'

    Example

    var str = 'beep boop';
    var out = truncateMiddle( str, 10 );
    // returns 'beep boop'

    Example

    var str = 'beep boop';
    var out = truncateMiddle( str, 0 );
    // returns ''

    Example

    var str = 'beep boop';
    var out = truncateMiddle( str, 2 );
    // returns '..'

    Example

    var str = '🐺 Wolf Brothers 🐺';
    var out = truncateMiddle( str, 7 );
    // returns '🐺 ... 🐺'