Skip to content

camelCase

Edit

Converts text from common word boundaries into camel case.

camelCase.ts
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("");
};
Terminal
wget -O src/lib/camelCase.ts https://raw.githubusercontent.com/jrTilak/lazykit/HEAD/registry/functions/camelCase.ts
camelCase.example.ts
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.