Skip to content

Strings ​

Strings: case conversion, word splitting, truncation, escaping, templating, number extraction.

ExportWhat it does
camelCaseConverts a string to camelCase; acronyms are words (XMLHttpRequest → xmlHttpRequest).
capitalizeUpper-cases the first character of a string, even outside the basic Unicode plane.
constantCaseConverts a string to CONSTANT_CASE: uppercase words joined with _, as in constants and environment variables.
createIdGeneratorCreates a generator of readable unique ids: gauge-1, gauge-2… for SVG gradients, clip paths or markers.
dotCaseConverts a string to dot.case: lower-case words joined with ., as in translation keys and property paths.
escapeHtmlEscapes the characters that have a meaning in HTML (& < > " '), to insert a text in markup.
escapeRegExpEscapes a text so that it matches literally in a regular expression, v flag included.
extractNumberExtracts the first number of a text, with . or , before the decimals: 1,234 is 1.234.
extractNumbersExtracts every number of a text, with the rules of extractNumber.
formatTemplateReplaces the {key} placeholders of a template with values.
isBlankChecks whether a text is missing or holds only whitespace: a required field left empty.
kebabCaseConverts a string to kebab-case: lowercase words joined with -, as in file names, CSS classes and URLs.
lowerCaseConverts a string to lower-case words separated by spaces, splitting identifiers such as camelCase.
pascalCaseConverts a string to PascalCase: words joined, each capitalized, the rest in lower case.
pluralizePicks the singular or plural form of a word for a count.
removeDiacriticsRemoves the accents of a text (Été → Ete), to search or sort without them.
sentenceCaseConverts an identifier to a sentence, to turn a key into a label: the first word capitalized, the others in lower case, acronyms kept.
slugifyTurns a text into a URL- and id-friendly slug: accents removed, lower-case words joined with -.
snakeCaseConverts a string to snake_case: lowercase words joined with _, as in database columns and JSON keys.
splitWordsSplits a string into words, whatever its case style (camelCase, kebab-case, snake_case, spaces…), in one pass.
squishTrims a text and collapses every run of whitespace, line breaks included, into a single space.
titleCaseConverts a string to Title Case: words separated by spaces, each capitalized, acronyms kept.
toCsvBuilds CSV text (RFC 4180): fields are quoted when needed, lines end with CRLF.
trainCaseConverts a string to Train-Case: capitalized words joined with -, as in HTTP header names.
truncateShortens a string to a maximum length, with an ellipsis when it is cut.
uncapitalizeLower-cases the first character of a string and leaves the rest unchanged: the reverse of capitalize.
upperCaseConverts a string to upper-case words separated by spaces, splitting identifiers such as camelCase.

Generated from the JSDoc of the sources.