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
Appendstextto the end of this string, repeatedcounttimes. -
chunkify(
int size) → List< String> -
Available on String, provided by the Composition extension
Splits the string into chunks of sizesize. -
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 withmaskChar, 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
Prependstextto the start of this string, repeatedcounttimes. -
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 firstcountcharacters 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 lastcountcharacters 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 stringcounttimes 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 firstcountcharacters of the string. -
takeLast(
int count) → String -
Available on String, provided by the Composition extension
Returns the lastcountcharacters of the string. -
truncate(
int maxLength, [bool ellipsis = false]) → String -
Available on String, provided by the Composition extension
Truncates the string tomaxLengthcharacters, optionally adding '...' at the end.