Composition extension

String composition and decomposition operations.

Provides methods for building, splitting, cleaning, and transforming strings through appending, prepending, word extraction, accent normalization, and more.

on

Methods

append(String text, [int count = 1]) String

Available on String, provided by the Composition extension

Appends text to the end of this string, repeated count times.
chunkify(int size) List<String>

Available on String, provided by the Composition extension

Splits the string into chunks of size size.
firstWord() String

Available on String, provided by the Composition extension

Extracts the first word from the string.
lastWord() String

Available on String, provided by the Composition extension

Extracts the last word from the string.
mask({int revealStart = 0, int revealEnd = 0, String maskChar = '*'}) String

Available on String, provided by the Composition extension

Masks a portion of the string with maskChar, revealing only the edges.
normaliseAccents() String

Available on String, provided by the Composition extension

Removes accents and special diacritical marks, converting to basic Latin.
normaliseWhitespace() String

Available on String, provided by the Composition extension

Normalises whitespace by collapsing multiple spaces, tabs, and newlines into single spaces, then trimming.
onlyLetters([bool removeSpaces = false]) String

Available on String, provided by the Composition extension

Extracts only alphabetic characters (and accented letters), removing everything else.
onlyNumbers([bool removeSpaces = false]) String

Available on String, provided by the Composition extension

Extracts only digit characters, removing everything else.
prefix(String text, [int count = 1]) String

Available on String, provided by the Composition extension

Prepends text to the start of this string, repeated count times.
removeAllWhitespace() String

Available on String, provided by the Composition extension

Removes all whitespace characters (spaces, tabs, newlines, etc.) from the string.
removeFirst(int count) String

Available on String, provided by the Composition extension

Removes the first count characters from the string.
removeFirstWord() String

Available on String, provided by the Composition extension

Removes the first word and its surrounding punctuation, leaving the rest of the string.
removeLast(int count) String

Available on String, provided by the Composition extension

Removes the last count characters from the string.
removeLastWord() String

Available on String, provided by the Composition extension

Removes the last word and its surrounding punctuation, leaving the rest of the string.
removeSpecialCharacters([bool removeSpaces = false]) String

Available on String, provided by the Composition extension

Removes all non-alphanumeric characters, leaving spaces or joining words.
repeat(int count) String

Available on String, provided by the Composition extension

Repeats the string count times and returns the result.
reverse() String

Available on String, provided by the Composition extension

Reverses the characters in the string, one code unit at a time.
safeReverse() String

Available on String, provided by the Composition extension

Reverses the string while preserving grapheme clusters (emoji-safe).
slugify() String

Available on String, provided by the Composition extension

Converts the string to a URL-safe slug.
takeFirst(int count) String

Available on String, provided by the Composition extension

Returns the first count characters of the string.
takeLast(int count) String

Available on String, provided by the Composition extension

Returns the last count characters of the string.
truncate(int maxLength, [bool ellipsis = false]) String

Available on String, provided by the Composition extension

Truncates the string to maxLength characters, optionally adding '...' at the end.