@thi.ng/text-format
Version:
Customizable color text formatting with presets for ANSI & HTML
60 lines • 2.14 kB
TypeScript
import { type FormatPresets, type StringFormat } from "./api.js";
/**
* HOF format function. Returns a single-arg function which wraps a given value
* into a fully prefixed & suffixed format string using given
* {@link StringFormat} impl.
*
* @example
* ```ts tangle:../export/def-format.ts
* import { defFormat, FMT_ANSI16, FG_RED } from "@thi.ng/text-format";
*
* const red = defFormat(FMT_ANSI16, FG_RED);
*
* console.log(red("hello"));
* // hello (shown in red in ANSI-supporting terminals)
*
* console.log(escape(red("hello")));
* // "%1B%5B31mhello%1B%5B0m"
* ```
*
* @param fmt -
* @param code -
*/
export declare const defFormat: (fmt: StringFormat, code: number) => (x: any) => string;
/**
* Takes a {@link StringFormat} impl supporting preset format ID constants (e.g.
* {@link FG_GREEN}) and returns an object of formatting functions for each
* `FG_XXX` preset ID.
*
* @remarks
* The underlying {@link StringFormat} can be obtained from the result object
* via `.format`.
*
* @param fmt -
*/
export declare const defFormatPresets: (format: StringFormat) => FormatPresets;
/**
* Returns string representation of a single line/row (of a potentially larger
* buffer/canvas), using the given string formatter. Use {@link formatNone} to
* create a plain string representation, ignoring any character format data.
*
* @param format -
* @param data -
* @param width - line length (default length of data)
* @param offset - read offset in data buffer
*/
export declare const format: (format: StringFormat, data: Uint32Array, width?: number, offset?: number) => string;
/**
* Returns plain string representation of a single line/row (of a potentially
* larger buffer/canvas), ignoring any formatting data (i.e. upper 16 bits of
* each character).
*
* @remarks
* Also see {@link format} for actually applying a {@link StringFormat}.
*
* @param data -
* @param width - line length (default length of data)
* @param offset - read offset in data buffer
*/
export declare const formatNone: (data: Uint32Array, width?: number, offset?: number) => string;
//# sourceMappingURL=format.d.ts.map