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
textwithinwidthusingcharfor padding. -
countOccurrences(
String text, String pattern) → int -
Count non-overlapping occurrences of
patternintext. -
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
oldTextandnewText. -
humanize(
String text) → String - Convert a programmatic identifier to human-readable text.
-
indent(
String text, int level, {String char = ' '}) → String -
Indent every line of
textbylevelrepetitions ofchar. -
jaccardSimilarity(
String a, String b) → double -
Compute the Jaccard similarity between the word sets of
aandb. -
kebabCase(
String text) → String - Convert to kebab-case.
-
levenshteinDistance(
String a, String b) → int -
Compute the Levenshtein edit distance between
aandb. -
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
texton the left towidthwithchar. -
padRight(
String text, int width, {String char = ' '}) → String -
Pad
texton the right towidthwithchar. -
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
aandbbased on Levenshtein distance. -
snakeCase(
String text) → String - Convert to snake_case.
-
splitLines(
String text, {bool preserveNewlines = false}) → List< String> -
Split
textinto 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
texttomaxLencharacters, appendingellipsisif truncated. -
unescapeHtml(
String text) → String - Unescape HTML entities back to characters.
-
wordWrap(
String text, int width) → String -
Word-wrap
textto the givenwidth.