linegauge
API reference

linegauge/wrap

Every export of linegauge/wrap, with its signature and doc comment: visibleWidth, wrap, wrap, plus 2 types.

import wrap from 'linegauge/wrap';
import { visibleWidth, wrap } from 'linegauge/wrap';

Functions

default

The default export, declared as wrap.

Wrap string to columns, keeping its ANSI intact and each row self-contained.

function wrap(string: string, columns: number, options?: WrapOptions): string;
ParameterType
stringstring
columnsnumber
options (optional)WrapOptions

Returns string

visibleWidth

The visible width of a string, escape sequences ignored.

function visibleWidth(string: string): number;
ParameterType
stringstring

Returns number

wrap

Wrap string to columns, keeping its ANSI intact and each row self-contained.

function wrap(string: string, columns: number, options?: WrapOptions): string;
ParameterType
stringstring
columnsnumber
options (optional)WrapOptions

Returns string

Interfaces

Options

interface WrapOptions {
    /** Trim leading and trailing whitespace from each row. Default true. */
    trim?: boolean;
    /** Break a word longer than `columns` rather than let it overflow. Default false. */
    hard?: boolean;
    /** Break on any character rather than at word boundaries. Default true. */
    wordWrap?: boolean;
}

WrapOptions

interface WrapOptions {
    /** Trim leading and trailing whitespace from each row. Default true. */
    trim?: boolean;
    /** Break a word longer than `columns` rather than let it overflow. Default false. */
    hard?: boolean;
    /** Break on any character rather than at word boundaries. Default true. */
    wordWrap?: boolean;
}

On this page