linegauge
API reference

linegauge

Every export of linegauge, with its signature and doc comment: lineCount, measure, width, width, strip, widest and 3 more, plus 4 types.

linegauge — how much of a terminal line a string occupies, and how to fold it.

import width from 'linegauge';
import { lineCount, measure, width, … } from 'linegauge';

Functions

default

The default export, declared as width.

How many terminal columns input occupies once its escape sequences are removed — string-width 9's answer, under its option names and defaults (WidthOptions). Non-strings measure 0.

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

Returns number

lineCount

Lines a string occupies in a terminal columns wide, each measured by width. 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.

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 — string-width 9's answer, under its option names and defaults (WidthOptions). Non-strings measure 0.

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

Returns number

Re-exported

Documented on the page of the entry point that declares them.

ExportKindDocumented in
slicefunctionlinegauge/slice
stripfunctionlinegauge/strip
truncatefunctionlinegauge/truncate
widestfunctionlinegauge/widest
wrapfunctionlinegauge/wrap
Optionsinterfacelinegauge/v8
TruncateOptionsinterfacelinegauge/truncate
WidthOptionsinterfacelinegauge/v8
WrapOptionsinterfacelinegauge/wrap

On this page