# @caiogondim/pipeline 中文文档

规范地址：https://npmcn.com/package/%40caiogondim/pipeline/

版本：1\.0\.6
npm 元数据更新时间：2022-06-12T15:37:05.241Z
中文译文更新时间：2026-11-09T19:02:53.233Z
软件包许可：MIT

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

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

弃用说明：This package was renamed to \*tubo\*

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

- 模块格式：CommonJS
- TypeScript 类型：未声明
- 运行依赖：0 个
- 首次发布：2016-09-22T22:01:46.055Z
- 最新版本发布：2016-10-17T21:32:21.423Z
- 近 30 天下载量：1830（2026-10-09 至 2026-11-07，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

您的功能( 同步/ 同步) 管道 QQ 运算符

## 安装

```sh
npm install @caiogondim/pipeline
```

也可以使用：`pnpm add @caiogondim/pipeline`、`yarn add @caiogondim/pipeline`、`bun add @caiogondim/pipeline`

## README

![](http://rawgit.com/caiogondim/pipeline.js/master/img/icon.svg)

# 输油管.js

![Travis CI](http://travis-ci.org/caiogondim/pipeline.js.svg?branch=master) [![codecov](https://codecov.io/gh/caiogondim/obstructed.js/branch/master/graph/badge.svg)](https://codecov.io/gh/caiogondim/obstructed.js)

管道像管道操作器在功能编程中更为常见 语言,如埃克西尔语.

这个 lib 支持 **同步** 财务报告和审定财务报表 **自动同步** 参数.

如果所有参数都是同步函数或字面的,则管道将正常运行 函数返回最后计算值。 如果其中一个论点是 函数返回一个承诺或承诺实例(当时可以使用的对象),a 承诺会在最后归还.

## 使用量

### 同步

```js
function double(x) {
  return x * 2
}

function square(x) {
  return x * x
}

var output = pipeline(
  2,
  double,
  square
)
console.log(output) // => 16
```

### 自动同步

```js
pipeline(
  bookingDetails.userId,
  fetchUserById, // async
  JSON.parse
)
  .then(function(result) {
    console.log(result)
  })
  .catch(function(error) {
    console.log(error)
  })
```

### 混合

也可以混合同步和同步参数. 只要发现一个能产生承诺或承诺的功能, lib 切换到 async 模式,然后返回 a `Promise`。 。 。 .

## 安装

要使用库,请通过 npm 安装

```bash
npm install @caiogondim/pipeline --save
```

要将其移植到浏览器或任何其他(非 CJS) 环境, 请使用您最喜欢的 CJS bundle. 没有最喜欢的吗? 尝试: [浏览器](http://browserify.org/), (中文(简体) ), [网络制作](https://github.com/medikoo/modules-webmake) 或者说 [网络软件包](http://webpack.github.io/)。 。 。 .

## 实例

### 验证(同步和同步)

```js
// Before
function validateEmail(email) {
  email = trim(email)
  validateEmailTld(email)
  validateEmailFormat(email)
}

// After
function validateEmail(email) {
  return pipeline(
    email,
    trim,
    validateEmailTld,
    validateEmailFormat
  )
}

try {
  validateEmail('john@email.com')
} catch (error) {
  console.log(error)
}
```

### 直发案件

```js
// Before
if (cache && localStorage.getItem(endpoint)) {
  return m.prop( JSON.parse( localStorage.get(endpoint) ) )
}

// After
if (cache && localStorage.getItem(endpoint)) {
  return pipeline(
    localStorage.get(endpoint),
    JSON.parse,
    m.prop
  )
}
```

### 与 const 用法

```js
// Before
let items = base64ToJSON(response.data.content)
items = Array.isArray(items) ? items : [items]

// After
const items = pipeline(
  base64ToJSON(response.data.content),
  x => Array.isArray(x) ? x : [x]
)
```

### 功能更新

```js
// Before
return Event.create(
  Object.assign(attrs, { parent_id: parentId, status: 'draft' })
)

// After
return pipeline(
  Object.assign(attrs, { parent_id: parentId, status: 'draft' }),
  Event.create
)
```

## 参考资料和贷项

-   [Ramda.js 烟斗](http://ramdajs.com/docs/#pipe)
-   [罗达什.js流](https://lodash.com/docs#flow)
-   [烟管.py](https://github.com/JulienPalard/Pipe)
-   一些考试从 [https://github.com/mindeavor/es-pipeline-operator/wiki/example-use-Cases 互联网档案馆的存檔,存档日期2013-12-21](https://github.com/mindeavor/es-pipeline-operator/wiki/Example-Use-Cases)

* * *

[cariogondim.com 互联网档案馆的存檔,存档日期2013-12-02](https://caiogondim.com/)  • 妇女  GitHub 图像 [@caiogondim (英语)](https://github.com/caiogondim)  • 妇女  微博 [@caio gondim (英语)](https://twitter.com/caio_gondim)

## 常见问题

### @caiogondim/pipeline 是什么？

您的功能\( 同步/ 同步\) 管道 QQ 运算符注意：该包已被作者标记为弃用——This package was renamed to \*tubo\*

### 如何安装 @caiogondim/pipeline？

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

### @caiogondim/pipeline 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/caiogondim\_\_pipeline 是否存在。

### @caiogondim/pipeline 支持 ESM 还是 CommonJS？

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

### @caiogondim/pipeline 可以商用吗？

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

### @caiogondim/pipeline 的下载量有多少？

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

### @caiogondim/pipeline 还在维护吗？

最新版本 1\.0\.6 发布于 2016/10/18（10 年前）；至今共发布 7 个版本，其中过去 12 个月发布了 0 个；首次发布于 2016/09/23。作者已将其标记为弃用，新项目建议寻找替代方案。

