# @develohpanda/fluent-builder 中文文档

规范地址：https://npmcn.com/package/%40develohpanda/fluent-builder/

版本：2\.1\.2
npm 元数据更新时间：2022-04-05T04:04:32.506Z
中文译文更新时间：2026-11-12T02:43:15.080Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：8.5 kB，6 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2019-10-07T12:08:04.586Z
- 最新版本发布：2020-10-15T03:59:19.760Z
- 近 30 天下载量：13245（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：15（近 12 个月 0 个）

## 中文简介

用于在 Typescript 中创建对象的已打入、流畅的构建器

## 安装

```sh
npm install @develohpanda/fluent-builder
```

也可以使用：`pnpm add @develohpanda/fluent-builder`、`yarn add @develohpanda/fluent-builder`、`bun add @develohpanda/fluent-builder`

## README

# \* 流利建设者

[![npm](https://img.shields.io/npm/v/@develohpanda/fluent-builder?logo=npm)](https://www.npmjs.com/package/@develohpanda/fluent-builder)

### 生成任意接口或类型的流畅,打出的对象构建器.

`fluent-builder` 使用种子设计,并生成一个与所建类型完全相同的签名的构建器,但带有 `mutate` 函数,对对象进行迭代修改。 建造者还有两处地产, `reset()` 财务报告和审定财务报表 `build()`。 。 。 .

```ts
createBuilder<Product>(schema).name('Shirt').price(42).build();
```

## 为什么?

`fluent-builder` 旨在简化使用 [构建器模式](https://sourcemaking.com/design_patterns/builder) 用于Typescript,使用通用名. 这种模式允许迭代构造复杂而常被嵌入的物体. 通常情况下,每个独特的接口或类型都需要执行一个独特的构建器类,以确保有正确的打字功能.

## 安装

和平常一样

```
yarn add -D @develohpanda/fluent-builder

npm i --save-dev @develohpanda/fluent-builder
```

### 抓到他们了!

为了在 VS 代码中正确检测类型( 如悬浮时的IntelliSense), 任何使用文件 `fluent-builder` 包含在默认项目中 `tsconfig` 待编纂。 如果你知道如何解决这个问题,请提交公关

## 使用量

#### 定义您的接口/ 类型

```ts
interface Product {
  name: string;
  price: number;
  color?: string;
  buy: () => void;
}
```

#### 定义一个方案

```ts
import {Schema} from '@develohpanda/fluent-builder';

const schema: Schema<Product> = {
  name: () => 'Shirt',
  price: () => 2,
  color: () => undefined,
  buy: () => jest.fn(),
}
```

#### 创建构建器

```ts
import {createBuilder} from '@develohpanda/fluent-builder';

const builder = createBuilder(schema);
```

#### 旋转

```ts
describe('suite', () => {
  beforeEach(() => builder.reset());

  it('test', () => {
    const mock = jest.fn();
    const instance = builder.price(4).buy(mock).build();

    // use instance and mock
  });
});
```

建造新建筑工的间接费用可通过使用 `builder.reset()` 方法。 这个将变异的图案重回原作,并且可以被连锁.

```ts
builder.reset().price(5).build();
```

## 捐款

请通过 [Github 问题跟踪器](https://github.com/develohpanda/fluent-builder/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc)。 。 。 .

你可以随心所欲地提出拉动请求!

```
yarn install
yarn test
```

## 许可证

[麻省理工学院](https://npmcn.com/package/%40develohpanda/fluent-builder/LICENSE)

## 常见问题

### @develohpanda/fluent-builder 是什么？

用于在 Typescript 中创建对象的已打入、流畅的构建器

### 如何安装 @develohpanda/fluent-builder？

在项目目录运行 npm install @develohpanda/fluent-builder，或使用 pnpm add / yarn add / bun add。

### @develohpanda/fluent-builder 支持 TypeScript 吗？

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

### @develohpanda/fluent-builder 支持 ESM 还是 CommonJS？

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

### @develohpanda/fluent-builder 可以商用吗？

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

### @develohpanda/fluent-builder 的下载量有多少？

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

### @develohpanda/fluent-builder 还在维护吗？

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

