kebabCase()
kebabCase(
str):string
Converts a string to kebab-case.
note
Handles camelCase, PascalCase, acronyms, snake_case, and spaces.
Parametersโ
str: stringโ
The string to convert.
Returns: stringโ
The string in kebab-case.
Sinceโ
2.0.0
Performanceโ
O(n) where n is string length. Single regex pass with match + join.
Also known asโ
dash (Radashi) ยท kebabCase (Lodash, es-toolkit, Modern Dash) ยท toKebabCase (Remeda) ยท โ (Ramda, Effect, Antfu)
Exampleโ
kebabCase('backgroundColor'); // => 'background-color'
kebabCase('XMLHttpRequest'); // => 'xml-http-request'
kebabCase('hello world'); // => 'hello-world'
kebabCase('foo_bar'); // => 'foo-bar'
kebabCase('--foo--bar--'); // => 'foo-bar'
How it works?โ
Converts a string to kebab-case format. All lowercase, words separated by hyphens.
Conversion Examplesโ
| Input | Output |
|---|---|
backgroundColor | background-color |
XMLHttpRequest | xml-http-request |
hello world | hello-world |
foo_bar | foo-bar |
Processโ
Use Casesโ
Format CSS classes ๐โ
Convert strings to kebab-case for CSS class names or URL slugs.
Essential for frontend development and SEO-friendly URLs.
const className = kebabCase('MenuList'); // 'menu-list'
const slug = kebabCase('Hello World Post'); // 'hello-world-post'
Generate URL slugs from titlesโ
Convert article or product titles into SEO-friendly URL slugs. Essential for blogs, CMS platforms, and any content with human-readable URLs.
const articleTitle = "How to Build a REST API with TypeScript";
const slug = kebabCase(articleTitle);
// => "how-to-build-a-rest-api-with-type-script"
const url = `/blog/${slug}`;
// => "/blog/how-to-build-a-rest-api-with-type-script"