Socket
Socket
Sign inDemoInstall

thenify-all

Package Overview
Dependencies
2
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    thenify-all

Promisifies all the selected functions in an object


Version published
Weekly downloads
12M
increased by2.29%
Maintainers
3
Install size
38.6 kB
Created
Weekly downloads
 

Package description

What is thenify-all?

The thenify-all npm package is used to promisify entire modules or specific sets of functions. This means it can convert callback-based functions or methods to return promises instead, allowing for more modern, cleaner asynchronous code using promises or async/await syntax.

What are thenify-all's main functionalities?

Promisifying an entire module

This code sample demonstrates how to promisify all methods of the Node.js 'fs' module. After promisifying, methods like 'readFile' return a promise that can be used with '.then()' and '.catch()' for handling asynchronous operations.

const thenifyAll = require('thenify-all');
const fs = thenifyAll(require('fs'));

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

Promisifying selected functions

This code sample shows how to promisify only selected functions from the 'fs' module. In this case, only 'readFile' and 'writeFile' are promisified, and they can be used with promise syntax.

const thenifyAll = require('thenify-all');
const fs = require('fs');
const promisifiedFs = thenifyAll(fs, {}, ['readFile', 'writeFile']);

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

Other packages similar to thenify-all

Readme

Source

thenify-all

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Promisifies all the selected functions in an object.

var thenifyAll = require('thenify-all');

var fs = thenifyAll(require('fs'), {}, [
  'readFile',
  'writeFile',
]);

fs.readFile(__filename).then(function (buffer) {
  console.log(buffer.toString());
});

API

var obj = thenifyAll(source, [obj], [methods])

Promisifies all the selected functions in an object.

  • source - the source object for the async functions
  • obj - the destination to set all the promisified methods
  • methods - an array of method names of source

var obj = thenifyAll.withCallback(source, [obj], [methods])

Promisifies all the selected functions in an object and backward compatible with callback.

  • source - the source object for the async functions
  • obj - the destination to set all the promisified methods
  • methods - an array of method names of source

thenifyAll.thenify

Exports thenify this package uses.

Keywords

FAQs

Last updated on 10 Jan 2015

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc