UNPKG

@visulima/string

Version:

Functions for manipulating strings.

41 lines (40 loc) 1.98 kB
import { L as LocaleOptions, i as SplitByCase } from "../packem_shared/types.d-fhe030jX.js"; import "../packem_shared/types.d-CmNvyl4l.js"; /** Options for the `splitByCase` function. */ interface SplitOptions extends LocaleOptions { /** Whether to handle ANSI escape sequences. (default: false) */ handleAnsi?: boolean; /** Whether to handle emoji sequences. (default: false) */ handleEmoji?: boolean; /** A list of known acronyms to preserve casing for. */ knownAcronyms?: ReadonlyArray<string>; /** Whether to normalize case (convert all‑upper tokens not in knownAcronyms to title case). */ normalize?: boolean; /** List of additional separators to split on. */ separators?: ReadonlyArray<string> | RegExp; /** Whether to strip ANSI escape sequences. (default: false) */ stripAnsi?: boolean; /** Whether to strip emoji sequences. (default: false) */ stripEmoji?: boolean; } /** * Splits a string into segments based on various criteria including case changes, * separators, Unicode scripts, ANSI codes, and emojis. * * This is the core splitting logic used by various case conversion functions. * @template T - The specific literal type of the input string, if known. * @param input The string to split. * @param options Configuration options for splitting behavior. * @returns An array of string segments. * @example * ```typescript * splitByCase("fooBarBaz") // => ["foo", "Bar", "Baz"] * splitByCase("foo_bar-baz") // => ["foo", "bar", "baz"] * splitByCase("HTMLElement") // => ["HTML", "Element"] * splitByCase("HTMLElement", { knownAcronyms: ["HTML"] }) // => ["HTML", "Element"] * splitByCase("\u001B[31mhello\u001B[0mWorld", { handleAnsi: true }) // => ["\u001B[31m", "hello", "\u001B[0m", "World"] * splitByCase("hello🌍world", { handleEmoji: true }) // => ["hello", "🌍", "world"] * ``` */ declare const splitByCase: <T extends string = string>(input: T, options?: SplitOptions) => SplitByCase<T>; export { SplitOptions, splitByCase };