linegauge
API reference

linegauge/v8

Every export of linegauge/v8, with its signature and doc comment: lineCount, measure, width, width, plus 2 types.

linegauge/v8 — string-width 8.3.0's drop-in, for a project pinned to string-width@8.

import width from 'linegauge/v8';
import { lineCount, measure, width } from 'linegauge/v8';

Functions

default

The default export, declared as width.

How many terminal columns input occupies once its escape sequences are removed.

function width(input: string, options?: WidthOptions): number;
ParameterType
inputstring
options (optional)WidthOptions

Returns number

lineCount

Lines a string occupies in a terminal columns wide — the measurement the frame loop actually asks for. An empty line still occupies one.

function lineCount(text: string, columns: number): number;
ParameterType
textstring
columnsnumber

Returns number

measure

Columns a string of plain text occupies — no escape scan. The wrapper below has already split its input into text runs and complete sequences, so rescanning would only give a malformed sequence a second chance to be mistaken for one.

function measure(text: string, ambiguousIsWide?: boolean): number;
ParameterType
textstring
ambiguousIsWide (optional)boolean

Returns number

width

How many terminal columns input occupies once its escape sequences are removed.

function width(input: string, options?: WidthOptions): number;
ParameterType
inputstring
options (optional)WidthOptions

Returns number

Interfaces

Options

What width accepts beyond the string. Graded against string-width's own suite, so the names and the defaults are its names and its defaults, not ours.

interface WidthOptions {
    /**
     * Treat East Asian Ambiguous characters as one column. **Default `true`** — the incumbent's
     * default, and right for a Latin terminal: `±`, `×`, `÷`, the box-drawing set, Greek and
     * Cyrillic all occupy one column there.
     */
    ambiguousIsNarrow?: boolean;
    /**
     * Count escape sequences as the characters they are made of instead of removing them.
     */
    countAnsiEscapeCodes?: boolean;
}

WidthOptions

What width accepts beyond the string. Graded against string-width's own suite, so the names and the defaults are its names and its defaults, not ours.

interface WidthOptions {
    /**
     * Treat East Asian Ambiguous characters as one column. **Default `true`** — the incumbent's
     * default, and right for a Latin terminal: `±`, `×`, `÷`, the box-drawing set, Greek and
     * Cyrillic all occupy one column there.
     */
    ambiguousIsNarrow?: boolean;
    /**
     * Count escape sequences as the characters they are made of instead of removing them.
     */
    countAnsiEscapeCodes?: boolean;
}

On this page