UNPKG

@visulima/string

Version:

Functions for manipulating strings.

59 lines (58 loc) 1.79 kB
/** * Enum representing different wrapping strategies for text */ declare const WrapMode: { /** * Breaks words at character boundaries to fit the width */ readonly BREAK_AT_CHARACTERS: "BREAK_AT_CHARACTERS"; /** * Breaks lines at word boundaries. If a word is longer than the width, it will be broken. */ readonly BREAK_WORDS: "BREAK_WORDS"; /** * Preserves word boundaries, words are kept intact even if they exceed width */ readonly PRESERVE_WORDS: "PRESERVE_WORDS"; /** * Enforces strict adherence to the width limit by breaking at exact width */ readonly STRICT_WIDTH: "STRICT_WIDTH"; }; /** * Word wrap options interface with detailed documentation */ interface WordWrapOptions { /** * Whether to remove zero-width characters from the string. * @default true */ removeZeroWidthCharacters?: boolean; /** * Whether to trim whitespace from wrapped lines. * @default true */ trim?: boolean; /** * Maximum width of each line in visible characters. * @default 80 */ width?: number; /** * Controls how text wrapping is handled at width boundaries. * - PRESERVE_WORDS: Words are kept intact even if they exceed width (default) * - BREAK_AT_CHARACTERS: Words are broken at character boundaries to fit width * - STRICT_WIDTH: Forces breaking exactly at width limit, always * - BREAK_WORDS: Breaks at word boundaries, but breaks words if they are too long * @default WrapMode.PRESERVE_WORDS */ wrapMode?: keyof typeof WrapMode; } /** * Wraps text using multiple wrapping strategies. * @param string The string to wrap * @param options Wrapping options * @returns The wrapped string */ declare const wordWrap: (string: string, options?: WordWrapOptions) => string; export { WordWrapOptions, WrapMode, wordWrap };