Socket
Socket
Sign inDemoInstall

2-thenable

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

2-thenable

Convert any object to thenable


Version published
Weekly downloads
929K
decreased by-6.93%
Maintainers
1
Weekly downloads
 
Created
Source

*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

Keywords

FAQs

Package last updated on 16 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc