2-thenable

中文文档
1.0.0发布于 2019/01/17ISC近 30 天下载 285万

Convert any object to thenable

原始使用文档
文档目录4 节
  1. Convert object into a thenable
  2. Installation
  3. How it works
  4. Tests

*nix build status Windows build status Tests coverage Transpilation status

2-thenable

Convert object into a thenable

Useful when we want to imply an asynchronous representation onto some non-promise object.

Having that target object can be combined into promise chains or async/await syntax. One use case would be turning a stream instance so it's also a promise.

Installation

npm install 2-thenable

How it works

Utility takes target and promise arguments. target is object to be extended with then, catch and finally methods. While promise is expected to be a native promise instance that reflects resolution which should be mapped onto target

Usage

Example of converting stream to thenable

const toThenable = require("2-thenable");

// Example of converting a simple utf8 string stream to thenable
toThenable(stream, new Promise((resolve, reject) => {
    let result = '';
    stream.on('error', reject);
    stream.on('data', data => (result += data));
    stream.on('end', () => resolve(result));
});

stream.then(result => {
    console.log("Cumulated string data", result);
});

Tests

npm test

版本与发布记录

2-thenable 共发布 1 个版本,首次发布于 2019/01/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2019/01/177 年前

关于 2-thenable 的常见问题

2-thenable 是什么?

Convert any object to thenable

如何安装 2-thenable?

在项目目录运行 npm install 2-thenable,或使用 pnpm add / yarn add / bun add。

2-thenable 支持 TypeScript 吗?

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

2-thenable 可以商用吗?

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

2-thenable 的下载量有多少?

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

2-thenable 还在维护吗?

最新版本 1.0.0 发布于 2019/01/17(7 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/01/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。