Socket
Socket
Sign inDemoInstall

thenify

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    thenify

Globally make everything a promise!


Version published
Weekly downloads
12M
increased by2.34%
Maintainers
1
Install size
4.17 kB
Created
Weekly downloads
 

Package description

What is thenify?

The thenify npm package is designed to convert Node.js callback-style functions to functions that return a promise. This is particularly useful when working with older Node.js APIs or third-party libraries that do not natively support promises, allowing developers to write cleaner, more modern asynchronous code using async/await or .then() syntax.

What are thenify's main functionalities?

Converting a callback-style function to a promise-returning function

This feature allows you to wrap a traditional Node.js callback-style function, such as `fs.readFile`, in a way that it returns a promise. This enables the use of `.then()` and `.catch()` for cleaner asynchronous control flow.

const thenify = require('thenify');
const fs = require('fs');
const readFile = thenify(fs.readFile);

readFile('example.txt', 'utf8').then(contents => {
  console.log(contents);
}).catch(err => {
  console.error(err);
});

Other packages similar to thenify

Readme

Source

thenify

NPM version build status Test coverage Gittip

Globally make everything a promise!

Promise.resolve([
  Promise.resolve(0),
  Promise.resolve(1)
]).then(function (results) {
  assert.equal(0, results[0])
  assert.equal(1, results[1])
})

DO NOT USE THIS IN LIBRARIES! THIS ADDS METHODS TO THE NATIVE PROTOTYPES AND IS CONSIDERED TERRORISM! ONLY USE THIS IN YOUR APP AND TEST THOROUGHLY!

Context

The current async/await proposal does not support await [], which is co's signature to support yielding multiple asynchronous functions in parallel. There is very little chance of having this overloading being included in the specifications.

However, @domenic had a crazy idea: globally make arrays a promise!. This is what this repository does.

async function () {
  var results = await [
    true,
    Promise.resolve(1)
  ];

  // results[0] === true
  // results[1] === 1
}

Usage

Just somehow get index.js included in your app.

Node:

require('thenify')

HTML:

<script src="https://cdn.rawgit.com/thenables/thenify/master/index.js"></script>

Keywords

FAQs

Last updated on 09 Aug 2014

Did you know?

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc