# @aashutoshrathi/word-wrap 中文文档

规范地址：https://npmcn.com/package/%40aashutoshrathi/word-wrap/

版本：1\.2\.6
npm 元数据更新时间：2023-06-28T07:39:37.241Z
中文译文更新时间：2026-11-05T16:50:04.590Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aashutoshrathi/word-wrap
原文对照：https://npmcn.com/package/%40aashutoshrathi/word-wrap/?lang=original
项目主页：https://github.com/aashutoshrathi/word-wrap
源码仓库：https://github.com/aashutoshrathi/word-wrap

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：10.9 kB，5 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=0\.10\.0
- 运行依赖：0 个
- 首次发布：2023-04-15T09:31:05.240Z
- 最新版本发布：2023-06-28T07:39:37.091Z
- 近 30 天下载量：24028367（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：3（近 12 个月 0 个）

## 中文简介

将单词包成指定的长度 .

## 安装

```sh
npm install @aashutoshrathi/word-wrap
```

也可以使用：`pnpm add @aashutoshrathi/word-wrap`、`yarn add @aashutoshrathi/word-wrap`、`bun add @aashutoshrathi/word-wrap`

## README

# 字形包装 [![NPM version](https://img.shields.io/npm/v/word-wrap.svg?style=flat)](https://www.npmjs.com/package/word-wrap) [![NPM monthly downloads](https://img.shields.io/npm/dm/word-wrap.svg?style=flat)](https://npmjs.org/package/word-wrap) [![NPM total downloads](https://img.shields.io/npm/dt/word-wrap.svg?style=flat)](https://npmjs.org/package/word-wrap) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/word-wrap.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/word-wrap)

> 将单词包成指定的长度 .

## 安装

安装方式 [无](https://www.npmjs.com/)数字 :

```sh
$ npm install --save word-wrap
```

## 使用量

```js
var wrap = require('word-wrap');

wrap('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
```

成果:

```
  Lorem ipsum dolor sit amet, consectetur adipiscing
  elit, sed do eiusmod tempor incididunt ut labore
  et dolore magna aliqua. Ut enim ad minim veniam,
  quis nostrud exercitation ullamco laboris nisi ut
  aliquip ex ea commodo consequat.
```

## 选项

![image](https://cloud.githubusercontent.com/assets/383994/6543728/7a381c08-c4f6-11e4-8b7d-b6ba197569c9.png)

### 选项。 宽度

类型 : `Number`

默认 : `50`

将文本的宽度在被包裹到新行之前 .

**示例**

```js
wrap(str, {width: 60});
```

### 选项。 缩进

类型 : `String`

默认 :"(无)

每行开头要使用的字符串 .

**示例**

```js
wrap(str, {indent: '      '});
```

### 选项。新行

类型 : `String`

默认 : `\n`

每行末尾使用的字符串 .

**示例**

```js
wrap(str, {newline: '\n\n'});
```

### 选项

类型 : `function`

默认 : `function(str){return str;}`

每行拆分后运行的逃生功能.

**示例**

```js
var xmlescape = require('xml-escape');
wrap(str, {
  escape: function(string){
    return xmlescape(string);
  }
});
```

### 选项.trim

类型 : `Boolean`

默认 : `false`

从返回的字符串中拖入白空间 。 之所以列入这一选项,是因为 `.trim()` 也可以将主缩进从一行剥去.

**示例**

```js
wrap(str, {trim: true});
```

### 选项。剪切

类型 : `Boolean`

默认 : `false`

当单词比指定的宽度长时,在任意两个字母之间断开一个单词.

**示例**

```js
wrap(str, {cut: true});
```

## 关于

### 相关项目

-   [常用词](https://www.npmjs.com/package/common-words):英语最常用的100个单词的更新列表(JSON). 有用吗.. [更多](https://github.com/jonschlinkert/common-words) | [主页](https://github.com/jonschlinkert/common-words "Updated list (JSON) of the 100 most common words in the English language. Useful for excluding these words from arrays.")
-   [洗牌词](https://www.npmjs.com/package/shuffle-words):将字串中的单词打散,并可以选择使用 [更多](https://github.com/jonschlinkert/shuffle-words) | [主页](https://github.com/jonschlinkert/shuffle-words "Shuffle the words in a string and optionally the letters in each word using the Fisher-Yates algorithm. Useful for creating test fixtures, benchmarking samples, etc.")
-   [单词](https://www.npmjs.com/package/unique-words): 返回字符串或数组中唯一的单词。 | [主页](https://github.com/jonschlinkert/unique-words "Return the unique words in a string or array.")
-   [字数](https://www.npmjs.com/package/wordcount):用一串来计算词. 支持英语、CJK和西里尔语 [主页](https://github.com/jonschlinkert/wordcount "Count the words in a string. Support for english, CJK and Cyrillic.")

### 捐款

拉出请求和星星总是受欢迎的. 对于错误和特性请求, [请创建一个问题](https://npmcn.com/package/issues/new)。 。 。 .

### 贡献者

| **提交** | **贡献者** | | -- -- -- -- -- -- -- 第43页 [扬施林克特](https://github.com/jonschlinkert) | |2| [领主](https://github.com/lordvlad) | |2| [希尔德吉](https://github.com/hildjj) | | 1 | [达尼洛桑帕约](https://github.com/danilosampaio) | | 1 | [2个fd](https://github.com/2fd) | | 1 | [移动自己](https://github.com/toddself) | | 1 | [狼冈42](https://github.com/wolfgang42) | | 1 | [扎查尔](https://github.com/zachhale) |

### 大楼文件

_(此工程的 readme.md 由 [动词](https://github.com/verbose/verb-generate-readme)请不要直接编辑读取器。 读取器的任何改动必须在 [动词 md](https://npmcn.com/package/%40aashutoshrathi/word-wrap/.verb.md) 读取我的模板。 )_

要生成读取, 请运行以下命令 :

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### 正在测试

运行和审查单元测试是熟悉图书馆及其API的好办法。 您可以使用以下命令安装依赖性并运行测试:

```sh
$ npm install && npm test
```

### 作者

**乔恩·斯林克特**

-   [千兆克/正弦链路](https://github.com/jonschlinkert)
-   [推特/简斯林克特](https://twitter.com/jonschlinkert)

### 许可证

版权:2017年, [乔恩·斯林克特](https://github.com/jonschlinkert)。 。 。 . 释放 [MIT 许可证](https://npmcn.com/package/%40aashutoshrathi/word-wrap/LICENSE)。 。 。 .

* * *

_此文件由 [动词基因读取器](https://github.com/verbose/verb-generate-readme),v 6.0,于2017年6月02日查阅._

## 常见问题

### @aashutoshrathi/word-wrap 是什么？

将单词包成指定的长度 \.

### 如何安装 @aashutoshrathi/word-wrap？

在项目目录运行 npm install @aashutoshrathi/word-wrap，或使用 pnpm add / yarn add / bun add。

### @aashutoshrathi/word-wrap 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @aashutoshrathi/word-wrap 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @aashutoshrathi/word-wrap 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=0\.10\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @aashutoshrathi/word-wrap 可以商用吗？

@aashutoshrathi/word-wrap 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @aashutoshrathi/word-wrap 的下载量有多少？

根据 npm 官方下载统计，@aashutoshrathi/word-wrap 在 2026/10/05 – 2026/11/03 这 30 天内被下载 24,028,367 次，日均约 800,946 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @aashutoshrathi/word-wrap 还在维护吗？

最新版本 1\.2\.6 发布于 2023/06/28（3 年前）；至今共发布 3 个版本，其中过去 12 个月发布了 0 个；首次发布于 2023/04/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

