Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
any-promise
Advanced tools
The `any-promise` npm package allows you to register and use any ES6-compatible Promise library in a generic way, enabling the use of a preferred promise implementation without being locked into a specific library. This is particularly useful in library code where the developer wants to leave the choice of Promise implementation to the user.
Registering a preferred Promise implementation
This code demonstrates how to register Bluebird as the Promise implementation to be used wherever `any-promise` is required. This allows for the use of Bluebird's API and performance benefits in an application or library that abstracts over the specific Promise implementation.
require('any-promise/register/bluebird');
const Promise = require('any-promise');
Using any-promise in a library
This code snippet shows how a library can use `any-promise` to return a Promise from an asynchronous operation without hardcoding a dependency on a specific Promise library. This allows the consumer of the library to choose the Promise implementation.
const Promise = require('any-promise');
module.exports = function asyncOperation() {
return new Promise(function(resolve, reject) {
// async operation here
});
};
Bluebird is a fully-featured Promise library with a focus on innovative features and performance. Unlike `any-promise`, Bluebird is a specific implementation rather than a way to abstract over different Promise libraries. It offers utilities for concurrency, such as `Promise.map`, and debugging features.
Q is one of the earliest Promise libraries that provided an implementation of the Promises/A+ spec before native Promises were widely available in JavaScript engines. Compared to `any-promise`, Q is a standalone Promise library rather than a means to utilize any Promise implementation. It includes features like `Q.allSettled`.
The `es6-promise` library is a polyfill for ES6-style Promises, aiming to provide a lightweight and efficient implementation of the standard Promise specification. In contrast to `any-promise`, `es6-promise` focuses on compatibility and providing a specific implementation, rather than enabling the use of any Promise library.
Let your library support any ES6 compatible Promise library or polyfill and leave the choice to the end user. The end user can install a polyfill or npm install
their preference before using this library and the installed library will be automatically detected.
Prefers a global Promise
object (native or polyfill). If one is not detected, attempts to load libraries in the following order. The first successful require
will be exported.
If you have multiple libraries installed (e.g. for testing), and would like to specify one you can use the PROMISE_IMPL
env variable.
var Promise = require('any-promise');
return Promise
.all([xf, f, init, coll])
.then(fn);
return new Promise(function(resolve, reject){
try {
resolve(item);
} catch(e){
reject(e);
}
});
FAQs
Resolve any installed ES6 compatible promise
The npm package any-promise receives a total of 3,019,680 weekly downloads. As such, any-promise popularity was classified as popular.
We found that any-promise demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.