---
title: "kebabCase"
description: "Convert any common string casing to kebab-case - handles camelCase, PascalCase, snake_case, spaces and consecutive capitals."
package: "@maz-ui/utils"
url: "https://maz-ui.com/ecosystem/utils/kebab-case"
---

# kebabCase

> Convert any common string casing to kebab-case - handles camelCase, PascalCase, snake_case, spaces and consecutive capitals.

- Package: `@maz-ui/utils`
- Import: `import { kebabCase } from '@maz-ui/utils/helpers/kebabCase'`
- Web: https://maz-ui.com/ecosystem/utils/kebab-case

## Usage

```ts
import { kebabCase } from '@maz-ui/utils'

kebabCase('myComponent') // → 'my-component'
kebabCase('MyComponent') // → 'my-component'
kebabCase('XMLParser') // → 'xml-parser'
kebabCase('hello_world') // → 'hello-world'
kebabCase('hello world') // → 'hello-world'
```

## API

```ts
function kebabCase(str: string): string
```

| Parameter | Type     | Description           |
| --------- | -------- | --------------------- |
| `str`     | `string` | The string to convert |

## Notes

- Consecutive uppercase letters are handled (e.g. `XMLParser` → `xml-parser`).
- Leading and trailing dashes are stripped.
- Multiple separators collapse into a single dash.
