Capitalize a string
Uppercase the first Unicode code point and preserve the remaining text.
function capitalize(value) { const [first, ...rest] = Array.from(value); return first ? first.t…stringCollection · 51 utilities
Text can be code points, graphemes or normalized words. Choose the contract before applying a transformation.
Uppercase the first Unicode code point and preserve the remaining text.
function capitalize(value) { const [first, ...rest] = Array.from(value); return first ? first.t…stringReverse Unicode code points without splitting surrogate pairs.
function reverse(value) { return Array.from(value).reverse().join(''); }stringCompare a string with its code-point reversal.
function palindrome(value) { return value === Array.from(value).reverse().join(''); }stringNormalize a Latin-text label into lowercase ASCII words separated by hyphens.
function slugify(value) { return value.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowe…stringUppercase a lowercase ASCII letter immediately after an underscore.
function camelCase(value) { return value.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase…stringKeep the first occurrence of every exact line while normalizing CRLF to LF.
function uniqueLines(value) { return [...new Set(value.split(/\r?\n/))].join('\n'); }stringDetect a scheme such as https: at the start of a URL string.
function isAbsoluteUrl(url) { return /^[a-z][a-z0-9+.-]*:/i.test(url); }stringReturn true unless the path starts with a slash or backslash, optionally after a drive or scheme.
function isRelative(path) { return !/^([a-z]+:)?[\\/]/i.test(path); }stringDecode base64 into its byte values.
function base64ToBytes(base64) { return Array.from(atob(base64), char => char.charCodeAt(0)); }…stringEncode byte values as base64 with btoa.
function bytesToBase64(bytes) { return btoa(String.fromCharCode(...bytes)); }stringFind the string inside itself doubled, past the first position.
function consistsRepeatedSubstring(text) { return `${text}${text}`.indexOf(text, 1) !== text.le…stringCompare the sorted, lowercased characters of both strings.
function areAnagram({ first, second }) { const sorted = text => Array.from(text.toLowerCase()).…stringMap a–z to the regional indicator symbols 🇦–🇿.
function letterToEmoji(letter) { return String.fromCodePoint(letter.toLowerCase().charCodeAt(0)…stringSort code points with an explicit English collation.
function sortCharacters(text) { return Array.from(text).sort((a, b) => a.localeCompare(b, 'en')…stringCompute the 32-bit hash Java’s String.hashCode uses.
function hashString(text) { return text.split('').reduce((hash, char) => (Math.imul(31, hash) +…stringCount UTF-8 bytes rather than characters.
function byteLength(text) { return new TextEncoder().encode(text).length; }stringRemove terminal color and cursor escape sequences.
function stripAnsi(text) { return text.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0…stringUppercase lowercase letters and lowercase the rest.
function swapCase(text) { return Array.from(text).map(char => char === char.toLowerCase() ? cha…stringJoin alphanumeric words, each starting with an uppercase letter.
function toPascalCase(text) { return (text.match(/[a-zA-Z0-9]+/g) || []).map(word => `${word.ch…stringUse forward slashes and drop a drive letter or leading ./.
function toUnixPath(path) { return path.replace(/[\\/]+/g, '/').replace(/^([a-zA-Z]+:|\.\/)/, '…stringSwitch a single identifier between camelCase and kebab-case.
function convertCase({ value, to }) { return to === 'kebab' ? value.replace(/([a-z0-9])([A-Z])/…stringCount runs of non-whitespace characters.
function countWords(text) { return (text.match(/\S+/g) || []).length; }stringReturn the text after the last dot, or an empty string.
function fileExtension(name) { const dot = name.lastIndexOf('.'); return dot > 0 ? name.slice(d…stringTake the last path segment, ignoring the query and fragment.
function fileNameFromUrl(url) { const path = url.split(/[?#]/)[0]; return path.slice(path.lastI…stringSplit on a character and count the pieces.
function characterCount({ text, char }) { return text.split(char).length - 1; }stringCollapse runs of slashes and backslashes into single forward slashes.
function normalizePath(path) { return path.replace(/[\\/]+/g, '/'); }stringDelete every whitespace character, including tabs and line breaks.
function removeSpaces(text) { return text.replace(/\s/g, ''); }stringConcatenate a string with itself a given number of times.
function repeat({ text, times }) { return text.repeat(times); }stringTurn LF and CRLF line breaks into <br>.
function nl2br(text) { return text.replace(/\r?\n/g, '<br>'); }stringReplace each tab with a fixed number of spaces.
function tabsToSpaces({ text, spaces }) { return text.replaceAll('\t', ' '.repeat(spaces)); }stringReplace the first count characters with a mask character, keeping the length.
function maskStart({ text, count, mask }) { return text.slice(count).padStart(text.length, mask…stringSplit on LF or CRLF and reverse the lines.
function reverseLines(text) { return text.split(/\r?\n/).reverse().join('\n'); }stringSplit into lines and sort them by UTF-16 code units.
function sortLines(text) { return text.split(/\r?\n/).sort().join('\n'); }stringRemove leading and trailing forward slashes.
function trimSlashes(text) { return text.replace(/^\/+|\/+$/g, ''); }stringRemove the text from the last dot onward.
function trimExtension(name) { const dot = name.lastIndexOf('.'); return dot > 0 ? name.slice(0…stringRemove separators and uppercase the character after each one.
function toCamelCase(text) { return text.trim().replace(/[-_\s]+(.)?/g, (_, char) => char ? cha…stringRead a column name as a base-26 number where A is 1.
function columnNumber(column) { return column.split('').reduce((total, letter) => total * 26 + …stringCount code points equal to a given character.
function countOccurrences({ text, char }) { return Array.from(text).filter(item => item === cha…stringLowercase the first code point and keep the rest.
function decapitalize(text) { const [first = '', ...rest] = Array.from(text); return first.toLo…stringReplace & < > " and ' with HTML entities.
function escapeHtml(text) { return text.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<…stringReplace {0}, {1}… placeholders with values in order.
function format({ template, values }) { return values.reduce((text, value, i) => text.replaceAl…stringDrop the query string and fragment.
function baseUrl(url) { return url.split(/[?#]/)[0]; }stringLowercase only the first character.
function lowercaseFirst(text) { return `${text.charAt(0).toLowerCase()}${text.slice(1)}`; }stringNumber lines from 1, right-aligned to two characters.
function prependNumbers(text) { return text.split(/\r?\n/).map((line, i) => `${String(i + 1).pa…stringCollapse runs of two or more whitespace characters.
function collapseSpaces(text) { return text.replace(/\s\s+/g, ' '); }stringRemove a repeated character from the start and the end only.
function trimCharacter({ text, char }) { const escaped = char.replace(/[.*+?^${}()|[\]\\]/g, '\…stringCut at the last space that fits, then add a suffix.
function truncateWords({ text, max, suffix }) { if (text.length <= max) return text; const cut …stringTurn & < > " and ' back into characters in one pass.
function unescapeHtml(text) { return text.replace(/&(?:amp|lt|gt|quot|#0*39);/g, entity => ({ '…stringCapitalize every space-separated word.
function uppercaseWords(text) { return text.split(' ').map(word => `${word.charAt(0).toUpperCas…stringDrop lines that are empty or whitespace only.
function removeEmptyLines(text) { return text.split(/\r?\n/).filter(line => line.trim() !== '')…stringTurn é and é style references into characters.
function decodeNumericEntities(text) { return text.replace(/&#(x[0-9a-f]+|\d+);/gi, (entity, co…stringTry a function in the local code lab, then read its limits before using it in an application.