Catalog npm
PACKAGE EXPLORERView in registry

2-thenable

npm

Convert any object to thenable

asyncpromisethenthenable
Versions collected1
Direct dependencies7From release 1.0.0
Last observed20 Oct, 18:49 UTC

README

Current package documentation

*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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.0Registry latest16 Jan 20197

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
medikoo/2-thenable

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:49 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:f76f8766594967793875b288a79e5b9a78b5f23844a857ca6a67254957f1e85c