@cto.af/string-width - v4.0.2
    Preparing search index...

    Class StringWidth

    Compute the widths of strings in display terminal "cells" of horizontal space. Intuitionally, a plain ASCII character takes up one cell. Certain grapheme clusters may take up -1 (e.g. backspace), 0 (e.g. escape sequences), 1, or 2 (e.g. emoji) cells.

    ANSI escape sequences are stripped by default. This can be disabled by setting the includeANSI option. Escape sequences that are paired with a start sequence and a stop sequence will be processed much more gracefully than individual sequences (e.g. cursor movements) or overlapping pairs.

    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get isCJK(): boolean

      Is the context for ambiguous East Asian Width code points CJK?

      Returns boolean

    • get locale(): string

      Resolved locale for grapheme segmentation.

      Returns string

    Methods

    • Break a string into multiple parts, such that each part has maximum cell length of width, unless a particular grapheme cluster is longer than width. Therefore, width should probably be 4 or higher to get the expected results.

      Parameters

      • str: string

        String to segment

      • width: number

        Maximum number of display cells for chunks

      Returns WidthBreak[]

    • Yield each segment of the input string as a separate substring.

      Parameters

      • str: string

      Returns Generator<string, undefined, undefined>

    • How many display cells does the given string take up? Accounts for EastAsianWidth, Emoji, combining characters, regional indicators (flags), backspaces

      Parameters

      • str: string

        String to count

      Returns number