@braintree/wrap-promise

WebJar for @braintree/wrap-promise

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

braintree__wrap-promise
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

@braintree/wrap-promise
WebJar for @braintree/wrap-promise
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/braintree/wrap-promise

Download braintree__wrap-promise

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/braintree__wrap-promise/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>braintree__wrap-promise</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/braintree__wrap-promise/
implementation 'org.webjars.npm:braintree__wrap-promise:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/braintree__wrap-promise/
implementation ("org.webjars.npm:braintree__wrap-promise:2.0.0")
'org.webjars.npm:braintree__wrap-promise:jar:2.0.0'
<dependency org="org.webjars.npm" name="braintree__wrap-promise" rev="2.0.0">
  <artifact name="braintree__wrap-promise" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='braintree__wrap-promise', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "braintree__wrap-promise" % "2.0.0"
[org.webjars.npm/braintree__wrap-promise "2.0.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

wrap-promise

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

Example

// 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

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.

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

module.exports = wrapPromise.wrapPrototype(MyObject, {
  transformPrivateMethods: true,
});
org.webjars.npm

Braintree

Versions

Version
2.0.0
1.1.1