# @braintree/wrap-promise

> A small lib to return promises or use callbacks

Latest version **3.0.4** (published 2026-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @braintree/wrap-promise
pnpm add @braintree/wrap-promise
yarn add @braintree/wrap-promise
bun add @braintree/wrap-promise
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.0.4 |
| Published | 2026-01-29 |
| First published | 2017-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Braintree |
| Maintainers | braintree |

## Links

- npm: https://www.npmjs.com/package/@braintree/wrap-promise
- Repository: https://github.com/braintree/wrap-promise
- Homepage: https://github.com/braintree/wrap-promise#readme
- Issues: https://github.com/braintree/wrap-promise/issues
- npm.io page: https://npm.io/package/@braintree/wrap-promise

## Recent versions

- 3.0.4 (latest) — 2026-01-29
- 3.0.2 — 2024-12-20
- 3.0.1 — 2024-06-18
- 3.0.0 — 2023-12-05
- 2.1.0 — 2020-07-13
- 2.0.0 — 2019-04-17
- 1.1.1 — 2017-06-01

## README

# wrap-promise

Small module to help support APIs that return a promise or use a callback.

### Example

```js
// my-method.js
var wrapPromise = require("wrap-promise");

function myMethod(arg) {
  return new Promise(function (resolve, reject) {
    doSomethingAsync(arg, function (err, response) {
      if (err) {
        reject(err);
        return;
      }

      resolve(response);
    });
  });
}

module.exports = wrapPromise(myMethod);

// my-app.js
var myMethod = require("./my-method");

myMethod("foo")
  .then(function (response) {
    // do something with response
  })
  .catch(function (err) {
    // handle error
  });

myMethod("foo", function (err, response) {
  if (err) {
    // handle error
    return;
  }

  // do something with response
});
```

### Wrap All Methods on the Prototype

```js
function MyObject() {}

MyObject.prototype.myAsyncMethod = function () {
  return new Promise(function (resolve, reject) {
    //
  });
};

MyObject.prototype.myOtherAsyncMethod = function () {
  return new Promise(function (resolve, reject) {
    //
  });
};

module.exports = wrapPromise.wrapPrototype(MyObject);
```

Static methods, sync methods on the prototype (though if you pass a function as the last argument of your sync method, you will get an error), and non-function properties on the prototype are ignored.

If there are certain methods you want ignored, you can pass an `ignoreMethods` array.

```js
module.exports = wrapPromise.wrapPrototype(MyObject, {
  ignoreMethods: ["myMethodOnThePrototypeIDoNotWantTransformed"],
});
```

By default, `wrapPrototype` ignores methods that begin with an underscore. You can override this behavior by passing: `transformPrivateMethods: true`

```js
module.exports = wrapPromise.wrapPrototype(MyObject, {
  transformPrivateMethods: true,
});
```

---
_Source: https://npm.io/package/@braintree/wrap-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
