Skip to content

String Helpers

Utility functions for working with string operations.

FunctionDescription
camelCaseConverts kebab-case to camelCase
capitalizeCapitalizes the first letter of a string.
escapeHtmlEscapes the HTML special characters &, <, >, ", and ' in a string.
extractErrorMessageConvert an error to a readable message.
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 ("").
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 camelCase to kebab-case
leadingSentenceExtracts the leading sentence from a string.
padStart / padEndnative JS String.prototype.padStart() / padEnd() (ES2017)
pascalCaseConverts a string to PascalCase.
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.
wordsSplits a string into an array of words.