Strings
Strings: case conversion, word splitting, truncation, escaping, templating, number extraction.
| Export | What it does |
|---|---|
camelCase | Converts a string to camelCase; acronyms are words (XMLHttpRequest → xmlHttpRequest). |
capitalize | Upper-cases the first character of a string, even outside the basic Unicode plane. |
constantCase | Converts a string to CONSTANT_CASE: uppercase words joined with _, as in constants and environment variables. |
createIdGenerator | Creates a generator of readable unique ids: gauge-1, gauge-2… for SVG gradients, clip paths or markers. |
dotCase | Converts a string to dot.case: lower-case words joined with ., as in translation keys and property paths. |
escapeHtml | Escapes the characters that have a meaning in HTML (& < > " '), to insert a text in markup. |
escapeRegExp | Escapes a text so that it matches literally in a regular expression, v flag included. |
extractNumber | Extracts the first number of a text, with . or , before the decimals: 1,234 is 1.234. |
extractNumbers | Extracts every number of a text, with the rules of extractNumber. |
formatTemplate | Replaces the {key} placeholders of a template with values. |
isBlank | Checks whether a text is missing or holds only whitespace: a required field left empty. |
kebabCase | Converts a string to kebab-case: lowercase words joined with -, as in file names, CSS classes and URLs. |
lowerCase | Converts a string to lower-case words separated by spaces, splitting identifiers such as camelCase. |
pascalCase | Converts a string to PascalCase: words joined, each capitalized, the rest in lower case. |
pluralize | Picks the singular or plural form of a word for a count. |
removeDiacritics | Removes the accents of a text (Été → Ete), to search or sort without them. |
sentenceCase | Converts an identifier to a sentence, to turn a key into a label: the first word capitalized, the others in lower case, acronyms kept. |
slugify | Turns a text into a URL- and id-friendly slug: accents removed, lower-case words joined with -. |
snakeCase | Converts a string to snake_case: lowercase words joined with _, as in database columns and JSON keys. |
splitWords | Splits a string into words, whatever its case style (camelCase, kebab-case, snake_case, spaces…), in one pass. |
squish | Trims a text and collapses every run of whitespace, line breaks included, into a single space. |
titleCase | Converts a string to Title Case: words separated by spaces, each capitalized, acronyms kept. |
toCsv | Builds CSV text (RFC 4180): fields are quoted when needed, lines end with CRLF. |
trainCase | Converts a string to Train-Case: capitalized words joined with -, as in HTTP header names. |
truncate | Shortens a string to a maximum length, with an ellipsis when it is cut. |
uncapitalize | Lower-cases the first character of a string and leaves the rest unchanged: the reverse of capitalize. |
upperCase | Converts a string to upper-case words separated by spaces, splitting identifiers such as camelCase. |