camelCase
EditConverts text from common word boundaries into camel case.
const words = (value: string): string[] => { return value .replace(/([\p{Ll}\d])(\p{Lu}(?=\p{Ll}))/gu, "$1 $2") .replace(/(\p{Lu}+)(\p{Lu}\p{Ll})/gu, "$1 $2") .match(/[\p{L}\p{N}]+/gu) ?? [];};
/** Converts text from common word boundaries into camel case. */export const camelCase = (value: string): string => { return words(value) .map((word, index) => { const lower = word.toLocaleLowerCase(); return index === 0 ? lower : lower.charAt(0).toLocaleUpperCase() + lower.slice(1); }) .join("");};Download
Section titled “Download”wget -O src/lib/camelCase.ts https://raw.githubusercontent.com/jrTilak/lazykit/HEAD/registry/functions/camelCase.tstemp_dir="$(mktemp -d)" && bunx degit jrTilak/lazykit/registry/functions "$temp_dir" && mv "$temp_dir/camelCase.ts" src/lib/camelCase.ts && rm -r "$temp_dir"Examples
Section titled “Examples”import { camelCase } from "./camelCase";
const key = camelCase("HTTP response-code");// "httpResponseCode"value(string) — Text containing spaces, punctuation, camel-case boundaries, or acronyms.- Returns a Unicode-aware camel-case string.