Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@braintree/wrap-promise

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@braintree/wrap-promise

A small lib to return promises or use callbacks

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
323K
decreased by-2.51%
Maintainers
1
Weekly downloads
 
Created

What is @braintree/wrap-promise?

@braintree/wrap-promise is a utility library that helps in converting callback-based functions into promise-based ones. This is particularly useful for modernizing codebases and making asynchronous code easier to read and maintain.

What are @braintree/wrap-promise's main functionalities?

Wrap a callback-based function

This feature allows you to wrap a traditional callback-based function and convert it into a promise-based function. This makes it easier to work with asynchronous code using modern JavaScript syntax.

const wrapPromise = require('@braintree/wrap-promise');

function callbackFunction(arg, callback) {
  setTimeout(() => {
    if (arg) {
      callback(null, 'Success');
    } else {
      callback('Error');
    }
  }, 1000);
}

const promiseFunction = wrapPromise(callbackFunction);

promiseFunction(true)
  .then(result => console.log(result))
  .catch(error => console.error(error));

Wrap a function with multiple arguments

This feature demonstrates how to wrap a function that takes multiple arguments before the callback. The wrapped function can then be used as a promise-based function.

const wrapPromise = require('@braintree/wrap-promise');

function multiArgFunction(arg1, arg2, callback) {
  setTimeout(() => {
    if (arg1 && arg2) {
      callback(null, 'Success');
    } else {
      callback('Error');
    }
  }, 1000);
}

const promiseFunction = wrapPromise(multiArgFunction);

promiseFunction('arg1', 'arg2')
  .then(result => console.log(result))
  .catch(error => console.error(error));

Other packages similar to @braintree/wrap-promise

FAQs

Package last updated on 18 Jun 2024

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