---
title: "kebabCase"
description: "将字符串转换为短横线式 (hello-world)。"
seo_title: "kebabCase"
seo_description: "Convert a string to kebab-case, lowercasing words and joining them with hyphens, ideal for URLs, file names, and CSS classes."
canonical_url: "https://core.mhaibaraai.cn/docs/transformers/string/kebab-case"
---
# kebabCase

> 将字符串转换为短横线式 (hello-world)。

## 用法

将字符串转换为短横线命名格式（kebab-case）。

```ts
import { kebabCase } from '@movk/core'

kebabCase('firstName') // => 'first-name'
kebabCase('First Name') // => 'first-name'
kebabCase('first_name') // => 'first-name'
kebabCase('XMLHttpRequest') // => 'xml-http-request'
```

## API

`kebabCase(str: string): string`

### 参数

**str** (`string`) *required*: 要转换的字符串。

### 返回值

**string**: 返回短横线式格式的字符串。

## Changelog

See commit history for [src/transformers/string/kebabCase.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/transformers/string/kebabCase.ts).


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
