# 2-thenable

> Convert any object to thenable

Latest version **1.0.0** (published 2019-01-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install 2-thenable
pnpm add 2-thenable
yarn add 2-thenable
bun add 2-thenable
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-01-16 |
| First published | 2019-01-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Mariusz Nowak |
| Maintainers | medikoo |
| Keywords | async, promise, thenable, then |

## Links

- npm: https://www.npmjs.com/package/2-thenable
- Repository: https://github.com/medikoo/2-thenable
- Homepage: https://github.com/medikoo/2-thenable#readme
- Issues: https://github.com/medikoo/2-thenable/issues
- npm.io page: https://npm.io/package/2-thenable

## Dependencies (2)

- [d](https://npm.io/package/d.md) 1
- [es5-ext](https://npm.io/package/es5-ext.md) ^0.10.47

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2019-01-16

## README

[![*nix build status][nix-build-image]][nix-build-url]
[![Windows build status][win-build-image]][win-build-url]
[![Tests coverage][cov-image]][cov-url]
![Transpilation status][transpilation-image]

# 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

```bash
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

```javascript
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

```bash
npm test
```

[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/2-thenable/branches/master/shields_badge.svg
[nix-build-url]: https://semaphoreci.com/medikoo-org/2-thenable
[win-build-image]: https://ci.appveyor.com/api/projects/status/?svg=true
[win-build-url]: https://ci.appveyor.com/api/project/medikoo/2-thenable
[cov-image]: https://img.shields.io/codecov/c/github/medikoo/2-thenable.svg
[cov-url]: https://codecov.io/gh/medikoo/2-thenable
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
[npm-image]: https://img.shields.io/npm/v/2-thenable.svg

---
_Source: https://npm.io/package/2-thenable · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
