utils/text/text_utils library

Text manipulation utilities.

Provides string transformations, case conversions, similarity metrics, extraction helpers, and formatting functions.

Classes

Span
A span of text optionally highlighted.

Functions

camelCase(String text) String
Convert to camelCase.
center(String text, int width, {String char = ' '}) String
Center text within width using char for padding.
countOccurrences(String text, String pattern) int
Count non-overlapping occurrences of pattern in text.
dedent(String text) String
Remove the common leading whitespace from all non-empty lines.
escapeHtml(String text) String
Escape HTML special characters.
escapeRegex(String text) String
Escape special regex characters.
escapeShell(String text) String
Escape a string for safe use in shell commands.
extractCodeBlocks(String text) List<({String code, String language})>
Extract fenced code blocks from Markdown text.
extractEmails(String text) List<String>
Extract all email addresses from text.
extractUrls(String text) List<String>
Extract all URLs from text.
highlightDifferences(String oldText, String newText) → (List<Span>, List<Span>)
Produce a pair of Span lists highlighting character-level differences between oldText and newText.
humanize(String text) String
Convert a programmatic identifier to human-readable text.
indent(String text, int level, {String char = ' '}) String
Indent every line of text by level repetitions of char.
jaccardSimilarity(String a, String b) double
Compute the Jaccard similarity between the word sets of a and b.
kebabCase(String text) String
Convert to kebab-case.
levenshteinDistance(String a, String b) int
Compute the Levenshtein edit distance between a and b.
normalizeWhitespace(String text) String
Collapse runs of whitespace into single spaces and trim.
ordinalize(int number) String
Convert a number to its ordinal string (1st, 2nd, 3rd, etc.).
padLeft(String text, int width, {String char = ' '}) String
Pad text on the left to width with char.
padRight(String text, int width, {String char = ' '}) String
Pad text on the right to width with char.
pascalCase(String text) String
Convert to PascalCase.
pluralize(String word, int count) String
Simple English pluralization.
removeComments(String text, {String? language}) String
Remove comments from source text.
similarity(String a, String b) double
Compute a similarity score between a and b based on Levenshtein distance.
snakeCase(String text) String
Convert to snake_case.
splitLines(String text, {bool preserveNewlines = false}) List<String>
Split text into lines.
stripAnsi(String text) String
Remove ANSI escape codes from text.
titleCase(String text) String
Convert to Title Case.
truncate(String text, int maxLen, {String ellipsis = '...'}) String
Truncate text to maxLen characters, appending ellipsis if truncated.
unescapeHtml(String text) String
Unescape HTML entities back to characters.
wordWrap(String text, int width) String
Word-wrap text to the given width.