Skip to content

String Helpers

Utility functions for working with string operations.

FunctionDescription
camelCaseConverts a string to camelCase.
capitalizeCapitalizes the first letter of a string.
dedentStrips the common leading whitespace from every line of a multi-line string, and trims a single leading/trailing blan…
escapeHtmlEscapes the HTML special characters `&`, `<`, `>`, `”`, and `’` in a string.
escapeRegExpEscapes regular expression metacharacters (`.
extractErrorMessageConvert an error to a readable message.
formatProgressBarFormats a value as a text progress bar, repeating `filledChar`/`emptyChar` across `width` cells proportional to `valu…
injectWordBreaksAdds word-break opportunities to a string so it can wrap cleanly in narrow UI containers such as side panels or table…
isBlankChecks if a string is blank — empty or contains only whitespace characters.
isEmptyChecks if a string is empty (`""`), `null`, or `undefined`.
isNonEmptyChecks if a string is non-empty (has at least one character).
isNotBlankChecks if a string is not blank — non-empty and contains at least one non-whitespace character.
kebabCaseConverts a string to kebab-case.
leadingSentenceExtracts the leading sentence from a string.
padStart / padEndnative JS String.prototype.padStart() / padEnd() (ES2017)
pascalCaseConverts a string to PascalCase.
removeDiacriticsRemoves diacritical marks (accents) from a string, e.g.
repeatnative JS String.prototype.repeat() (ES2015)
slugifyConverts a string into a URL-friendly slug.
snakeCaseConverts a string to snake_case.
startsWith / endsWithnative JS String.prototype.startsWith() / endsWith() (ES2015)
templateInterpolates `{{key}}` placeholders in a template string with values from a data record.
titleCaseConverts a string to Title Case.
trim / trimStart / trimEndnative JS String.prototype.trim() / trimStart() / trimEnd() (ES2019)
truncateTruncates a string to `maxLength` characters, appending an ellipsis when cut.
unescapeHtmlUnescapes the HTML entities `&`, `<`, `>`, `”`, and `&#39;` back to `&`, `<`, `>`, `”`, and `’`.
wordsSplits a string into an array of words.