# @apaleslimghost/boxen 中文文档

规范地址：https://npmcn.com/package/%40apaleslimghost/boxen/

版本：5\.1\.3
npm 元数据更新时间：2024-04-22T17:12:24.251Z
中文译文更新时间：2026-11-08T07:23:56.435Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40apaleslimghost/boxen
原文对照：https://npmcn.com/package/%40apaleslimghost/boxen/?lang=original
项目主页：https://github.com/sindresorhus/boxen#readme
源码仓库：https://github.com/sindresorhus/boxen

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

- 包体积（解压后）：18.4 kB，5 个文件
- TypeScript 类型：包内自带
- Node.js 要求：\>=10
- 运行依赖：8 个
- 首次发布：2024-04-22T17:12:23.601Z
- 最新版本发布：2024-04-22T17:12:23.875Z
- 近 30 天下载量：1873（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：1（近 12 个月 0 个）

## 中文简介

在终端中创建框

## 安装

```sh
npm install @apaleslimghost/boxen
```

也可以使用：`pnpm add @apaleslimghost/boxen`、`yarn add @apaleslimghost/boxen`、`bun add @apaleslimghost/boxen`

## README

# 条形

> 在终端中创建框

![](https://npmcn.com/package/%40apaleslimghost/boxen/screenshot.png)

## 安装

```
$ npm install boxen
```

## 使用量

```js
const boxen = require('boxen');

console.log(boxen('unicorn', {padding: 1}));
/*
┌─────────────┐
│             │
│   unicorn   │
│             │
└─────────────┘
*/

console.log(boxen('unicorn', {padding: 1, margin: 1, borderStyle: 'double'}));
/*

   ╔═════════════╗
   ║             ║
   ║   unicorn   ║
   ║             ║
   ╚═════════════╝

*/

console.log(boxen('unicorns love rainbows', {title: 'magical', titleAlignment: 'center'}));
/*
┌────── magical ───────┐
│unicorns love rainbows│
└──────────────────────┘
*/
```

## API 密码

### boxen( 文本, 选项 )

#### 文本

类型 : `string`

箱内有文字.

#### 选项

类型 : `object`

##### 边框颜色

类型 : `string`  
数值 : `'black'` `'red'` `'green'` `'yellow'` `'blue'` `'magenta'` `'cyan'` `'white'` `'gray'` 或十六进制值 `'#ff0000'`

框边框的颜色.

##### 边框样式

类型 : `string | object`  
默认 : `'single'`  
数值 :

-   `'single'`

```
┌───┐
│foo│
└───┘
```

-   `'double'`

```
╔═══╗
║foo║
╚═══╝
```

-   `'round'` (单位:千美元)`'single'` 圆角相接)

```
╭───╮
│foo│
╰───╯
```

-   `'bold'`

```
┏━━━┓
┃foo┃
┗━━━┛
```

-   `'singleDouble'` (单位:千美元)`'single'` 上下两地, `'double'` 左右两侧)

```
╓───╖
║foo║
╙───╜
```

-   `'doubleSingle'` (单位:千美元)`'double'` 上下两地, `'single'` 左右两侧)

```
╒═══╕
│foo│
╘═══╛
```

-   `'classic'`

```
+---+
|foo|
+---+
```

框边框的样式.

可以是上面任何预先定义的样式,也可以是带有以下密钥的对象:

```js
{
    topLeft: '+',
    topRight: '+',
    bottomLeft: '+',
    bottomRight: '+',
    horizontal: '-',
    vertical: '|'
}
```

##### 淡出边界

类型 : `boolean`  
默认 : `false`

减少边界的不透明度.

##### 标题

类型 : `string`

框上方显示标题. 如果需要,框会横向扩展以适应标题.

示例

```js
console.log(boxen('foo bar', {title: 'example'}));
/*
┌ example ┐
│foo bar  │
└─────────┘
*/
```

##### 标题对齐

类型 : `string`  
默认 : `'left'`

在上行对齐标题 .

数值 :

-   `'left'`

```js
/*
┌ example ──────┐
│foo bar foo bar│
└───────────────┘
*/
```

-   `'center'`

```js
/*
┌─── example ───┐
│foo bar foo bar│
└───────────────┘
*/
```

-   `'right'`

```js
/*
┌────── example ┐
│foo bar foo bar│
└───────────────┘
*/
```

##### 粘贴

类型 : `number | object`  
默认 : `0`

文本和框边框之间的空格 .

接受带有其中任何一个数字或对象 `top`, (中文(简体) ), `right`, (中文(简体) ), `bottom`, (中文(简体) ), `left` 属性。 当指定一个数字时, 左/ 右粘接是上/ 下相加的3 倍, 使其看起来不错 .

##### 边距

类型 : `number | object`  
默认 : `0`

围绕盒子的空间.

接受带有其中任何一个数字或对象 `top`, (中文(简体) ), `right`, (中文(简体) ), `bottom`, (中文(简体) ), `left` 属性。 当指定一个数字时,左/右比值为上/下相差3倍,使其看起来不错.

##### 浮动

类型 : `string`  
默认 : `'left'`  
数值 : `'right'` `'center'` `'left'`

在可用的终端屏幕空间上浮出盒子.

##### 背景颜色

类型 : `string`  
数值 : `'black'` `'red'` `'green'` `'yellow'` `'blue'` `'magenta'` `'cyan'` `'white'` `'gray'` 或十六进制值 `'#ff0000'`

背景颜色 .

##### 文本对齐

类型 : `string`  
默认 : `'left'`  
数值 : `'left'` `'center'` `'right'`

基于最宽行对齐框中的文本 .

## 相关

-   [盒状颜色](https://github.com/sindresorhus/boxen-cli) - 本单元的CLI
-   [cli 选项](https://github.com/sindresorhus/cli-boxes) - 供终端使用的盒子
-   [墨水库](https://github.com/sindresorhus/ink-box) - 使用此软件包的墨水盒组件

* * *

**[使用 Tidelift 订阅软件包获得专业支持](https://tidelift.com/subscription/pkg/npm-boxen?utm_source=npm-boxen&utm_medium=referral&utm_campaign=readme)**  
Tidelift 有助于让开源为维护者持续提供,同时给公司  
保证其依赖性的安全、维持和许可证发放.

## 常见问题

### @apaleslimghost/boxen 是什么？

在终端中创建框

### 如何安装 @apaleslimghost/boxen？

在项目目录运行 npm install @apaleslimghost/boxen，或使用 pnpm add / yarn add / bun add。

### @apaleslimghost/boxen 支持 TypeScript 吗？

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

### @apaleslimghost/boxen 需要什么版本的 Node\.js？

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

### @apaleslimghost/boxen 可以商用吗？

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

### @apaleslimghost/boxen 的下载量有多少？

根据 npm 官方下载统计，@apaleslimghost/boxen 在 2026/10/06 – 2026/11/04 这 30 天内被下载 1,873 次，日均约 62 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @apaleslimghost/boxen 还在维护吗？

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

