Skip to main content
Module

x/indent_and_wrap/mod.ts

Finds and replaces common indent, hard-wraps text, generates text tables and table-based complex text layouts. Can work on text that contains terminal escape sequences.
Go to Latest
import * as indentAndWrap from "https://deno.land/x/indent_and_wrap@v0.0.16/mod.ts";

Functions

Count number of lines in text string, and determine column number after the last character. This function only considers text substring from from to to. Lines and columns counter starts from provided values: nLine and nColumn. If options.mode is term, skips terminal escape sequences (like VT100 color codes).

Scan text string, and find leading space characters, that are common across all lines. If ignoreFirstIndent is set, then the leading space on the first line is not counted, so the provided text string can be trimmed. If options.mode is term, then terminal escape sequences (like VT100 color codes) can be part of indent. This function uses fast algorithm that avoids splitting text to lines array.

This function works the same as indentAndWrap(), but it doesn't return resulting text, but it returns number of lines and columns the result occupies. It only counts columns on non-blank lines.

This function does: - Replaces new line characters (\n, \r\n or \r) to options.endl, or if it's not set to \n. - If options.indent is set, it determines common indent characters across all lines, and replaces them with options.indent string. This can lead to indent increase or decrease. If options.ignoreFirstIndent is set, will look for common indent starting at second line, so the text can be trimmed. If you already know the common indent (e.g. you called findCommonIndent()), you can provide it as knownCommonIndent to save some calculation time. If knownCommonIndent doesn't match the result of findCommonIndent(), the behavior is undefined. - If options.wrapWidth is set, it inserts options.endl, so there're no lines longer than options.wrapWidth columns. Columns are calculated with respect to options.tabWidth (default 8).