# thenify 中文文档

规范地址：https://npmcn.com/package/thenify/

版本：3\.3\.1
npm 元数据更新时间：2022-06-27T06:03:49.795Z
中文译文更新时间：2026-11-05T16:25:25.050Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：7.9 kB，5 个文件
- TypeScript 类型：未声明
- 运行依赖：1 个
- 首次发布：2014-08-09T23:34:21.073Z
- 最新版本发布：2020-06-17T17:30:57.152Z
- 近 30 天下载量：211611526（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：9（近 12 个月 0 个）

## 中文简介

推动基于召回的函数

## 安装

```sh
npm install thenify
```

也可以使用：`pnpm add thenify`、`yarn add thenify`、`bun add thenify`

## README

# 指针

[![NPM version](https://img.shields.io/npm/v/thenify.svg?style=flat-square)](https://npmjs.org/package/thenify) [![Build status](https://img.shields.io/travis/thenables/thenify.svg?style=flat-square)](https://travis-ci.org/thenables/thenify) [![Test coverage](https://img.shields.io/coveralls/thenables/thenify.svg?style=flat-square)](https://coveralls.io/r/thenables/thenify) [![Dependency Status](http://img.shields.io/david/thenables/thenify.svg?style=flat-square)](https://david-dm.org/thenables/thenify) [![License](http://img.shields.io/npm/l/thenify.svg?style=flat-square)](https://npmcn.com/package/thenify/LICENSE) [![Downloads](http://img.shields.io/npm/dm/thenify.svg?style=flat-square)](https://npmjs.org/package/thenify)

使用 [`any-promise`](https://github.com/kevinbeaty/any-promise)。 。 。 .

-   保留函数名称
-   利用本地承诺(如果有的话),并试图回到承诺(如: `bluebird`
-   将调用中的多个参数转换为 `Array`,也支持通过 `options.multiArgs`
-   生成函数从不优化
-   支持回调和承诺样式

另外一个好处是 `throw`n 自动函数的错误会被承诺抓住 !

## API 密码

### fn = (fn, 选项)

推动一个函数.

### 选项

`options` 是可选的.

-   `options.withCallback` - 支持召回和许诺风格,默认为 `false`。 。 。 .
    
-   `options.multiArgs` - 当召回有多个参数时改变行为. 默认为 `true`。 。 。 .
    
    -   `true` - 将多个参数转换为数组
    -   `false`\- 总是用第一个论据
    -   `Array` - 将多个参数转换为有键的对象 `options.multiArgs`
-   将同步函数变成承诺
    

```js
var thenify = require('thenify');

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
});
```

-   与回调兼容

```js
var thenify = require('thenify');

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
}, { withCallback: true });

// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);
// somethingAsync(a, b, c, function () {});
```

或用途 `thenify.withCallback()`

```js
var thenify = require('thenify').withCallback;

var somethingAsync = thenify(function somethingAsync(a, b, c, callback) {
  callback(null, a, b, c);
});

// somethingAsync(a, b, c).then(onFulfilled).catch(onRejected);
// somethingAsync(a, b, c, function () {});
```

-   总是回调第一个参数

```js
var thenify = require('thenify');

var promise = thenify(function (callback) {
  callback(null, 1, 2, 3);
}, { multiArgs: false });

// promise().then(function onFulfilled(value) {
//   assert.equal(value, 1);
// });
```

-   将调用参数转换为对象

```js
var thenify = require('thenify');

var promise = thenify(function (callback) {
  callback(null, 1, 2, 3);
}, { multiArgs: [ 'one', 'tow', 'three' ] });

// promise().then(function onFulfilled(value) {
//   assert.deepEqual(value, {
//     one: 1,
//     tow: 2,
//     three: 3
//   });
// });
```

## 常见问题

### thenify 是什么？

推动基于召回的函数

### 如何安装 thenify？

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

### thenify 支持 TypeScript 吗？

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

### thenify 可以商用吗？

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

### thenify 的下载量有多少？

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

### thenify 还在维护吗？

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

