Skip to content

kebabCase

Edit

Converts text from common word boundaries into lowercase kebab case.

kebabCase.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 lowercase kebab case. */
export const kebabCase = (value: string): string => {
return words(value).map((word) => word.toLocaleLowerCase()).join("-");
};
Terminal
wget -O src/lib/kebabCase.ts https://raw.githubusercontent.com/jrTilak/lazykit/HEAD/registry/functions/kebabCase.ts
kebabCase.example.ts
import { kebabCase } from "./kebabCase";
const path = kebabCase("HTTPResponse Code");
// "http-response-code"
  • value (string) — Text containing common word boundaries.
  • Returns lowercase words separated by hyphens.