Skip to main content
Module

x/indent_and_wrap/mod.ts>indentAndWrap

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
function indentAndWrap
import { indentAndWrap } from "https://deno.land/x/indent_and_wrap@v0.0.16/mod.ts";

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).

Parameters

text: string
optional
options: IndentAndWrapOptions
optional
knownCommonIndent: string