UNPKG

@je-es/format

Version:

A function to format text with ANSI styles, padding, and borders

96 lines (88 loc) 3.05 kB
import { t_style } from '@je-es/ansi'; export { t_style } from '@je-es/ansi'; /** * @name format.d.ts * @description Definitions for the `format` module */ type t_padding = { top?: number; bottom?: number; left?: number; right?: number; }; type t_prefix = { value: string; style: t_style; }; type t_border = { width?: number; color?: string; }; type formatOptions = { ansi?: t_style; padding?: t_padding; border?: t_border; prefix?: t_prefix; suffix?: t_prefix; width?: number; align?: 'left' | 'center' | 'right'; }; type borderDimensions = { topBeg: string; topEnd: string; botBeg: string; botEnd: string; char: string; side: string; }; type t_pattern = [ { value?: string; gvalue?: string; options: formatOptions; }[] ]; /** * @name format.ts * @description This module provides functions to format text with ANSI styles, padding, and borders. */ /** * Applies styles, padding, and borders to a given string. * * @param {string} input - The string to apply styles to. * @param {types.formatOptions} options - The formatting options. * @param {types.t_style} options.ansi - The ANSI styles to apply. * @param {types.t_prefix} options.prefix - The prefix options. * @param {types.t_prefix} options.suffix - The suffix options. * @param {number} options.width - The width of the formatted string. * @param {'left'|'center'|'right'} options.align - The alignment of the formatted string. * @param {types.t_padding} options.padding - The padding options. * @param {types.t_border} options.border - The border options. * @return {string} The formatted string. */ declare const style: (input: string, options?: formatOptions) => string; /** * @name tools.ts * @description More tools ! */ /** * Applies styles to a given message based on a pattern and optional values. * * @param {any} msg - The message to apply styles to. * @param {types.t_pattern} pattern - The pattern to apply styles from. * @param {object} [values] - Optional values to use for dynamic styles. * @return {string} The formatted message with applied styles. */ declare const apply: (msg: any, pattern: t_pattern, values?: {}) => string; /** * Combines multiple messages with patterns and optional values into a single string. * * @param {Array<{ msg?: any, pattern?: any, values?: any }>} opt - An array of objects containing the message, pattern, and optional values. * @return {string} - The combined string with applied styles. */ declare const combine: (opt: { msg?: any; pattern?: any; values?: any; }[]) => string; export { apply, type borderDimensions, combine, type formatOptions, style, type t_border, type t_padding, type t_pattern, type t_prefix };