String Utilities
Comprehensive documentation and code examples for sc-fns/string.
The sc-fns/string module provides essential helpers for text transformations, casing conversions, sanitization, whitespace handling, and string masking.
ts
slugify
Converts a string into an SEO-friendly, URL-safe slug. Handles Unicode diacritics/accents, special characters, and repeated delimiters.
Signature
ts
Examples
ts
capitalize
Capitalizes the first character of a string while leaving the rest untouched.
Signature
ts
Examples
ts
capitalizeWords
Capitalizes the first character of each word in a string, preserving whitespace boundaries.
Signature
ts
Examples
ts
truncate
Truncates a string to a maximum character length, appending a customizable ellipsis suffix if cut.
Signature
ts
Parameters
str: The target string to truncate.length: The maximum length of the output string (including the suffix).suffix: The suffix to append if truncated (defaults to...).
Examples
ts
removeWhitespace
Removes all whitespace characters (spaces, tabs, newlines) from a string.
Signature
ts
Examples
ts
normalizeWhitespace
Collapses multiple consecutive whitespace characters into a single space and trims leading and trailing whitespace.
Signature
ts
Examples
ts
randomString
Generates a cryptographically strong random string of a specified length using an optional custom character set.
Signature
ts
Examples
ts
maskString
Masks sensitive parts of a string (such as email addresses, credit cards, or API keys) while preserving visible boundary characters.
Signature
ts
Examples
ts
How is this guide?
Last updated on October 25, 2026