---
title: "words"
description: "将字符串按空格、驼峰、连字符等分隔规则分解为单词数组，支持多种命名格式。"
seo_title: "words"
seo_description: "Split a string into an array of words, recognizing camelCase, snake_case, and kebab-case boundaries for reliable tokenization."
canonical_url: "https://core.mhaibaraai.cn/docs/transformers/string/words"
---
# words

> 将字符串按空格、驼峰、连字符等分隔规则分解为单词数组，支持多种命名格式。

## 用法

`words` 函数是所有大小写转换函数的基础。它接收一个字符串，并将其分解为一个由单词组成的数组。它能处理驼峰式、下划线式、短横线式以及缩写词。

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

words('helloWorld') // => ['hello', 'World']
words('hello_world') // => ['hello', 'world']
words('hello-world') // => ['hello', 'world']
words('XMLHttpRequest') // => ['XML', 'Http', 'Request']
```

## API

`words(str: string): string[]`

### 参数

**str** (`string`) *required*: 要分解的字符串。

### 返回值

**string\[\]**: 返回一个包含从输入字符串中提取的单词的数组。

## Changelog

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


## Sitemap

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