ES Proposal spec-compliant shim for Promise.prototype.finally
npm install promise.prototype.finally[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
ES Proposal spec-compliant shim for Promise.prototype.finally. Invoke its "shim" method to shim Promise.prototype.finally if it is unavailable or noncompliant. Note: a global Promise must already exist: the es6-shim is recommended.
This package implements the es-shim API interface. It works in an ES3-supported environment that has Promise available globally, and complies with the proposed spec.
Most common usage:
``js
var assert = require('assert');
var promiseFinally = require('promise.prototype.finally');
var resolved = Promise.resolve(42);
var rejected = Promise.reject(-1);
promiseFinally(resolved, function () {
assert.equal(arguments.length, 0);
return Promise.resolve(true);
}).then(function (x) {
assert.equal(x, 42);
});
promiseFinally(rejected, function () {
assert.equal(arguments.length, 0);
}).catch(function (e) {
assert.equal(e, -1);
});
promiseFinally(rejected, function () {
assert.equal(arguments.length, 0);
throw false;
}).catch(function (e) {
assert.equal(e, false);
});
promiseFinally.shim(); // will be a no-op if not needed
resolved.finally(function () {
assert.equal(arguments.length, 0);
return Promise.resolve(true);
}).then(function (x) {
assert.equal(x, 42);
});
rejected.finally(function () {
assert.equal(arguments.length, 0);
}).catch(function (e) {
assert.equal(e, -1);
});
rejected.finally(function () {
assert.equal(arguments.length, 0);
throw false;
}).catch(function (e) {
assert.equal(e, false);
});
`
, and run npm test`[package-url]: https://npmjs.com/package/promise.prototype.finally
[npm-version-svg]: http://versionbadg.es/es-shims/Promise.prototype.finally.svg
[deps-svg]: https://david-dm.org/es-shims/Promise.prototype.finally.svg
[deps-url]: https://david-dm.org/es-shims/Promise.prototype.finally
[dev-deps-svg]: https://david-dm.org/es-shims/Promise.prototype.finally/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/Promise.prototype.finally#info=devDependencies
[testling-svg]: https://ci.testling.com/es-shims/Promise.prototype.finally.png
[testling-url]: https://ci.testling.com/es-shims/Promise.prototype.finally
[npm-badge-png]: https://nodei.co/npm/promise.prototype.finally.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/promise.prototype.finally.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/promise.prototype.finally.svg
[downloads-url]: http://npm-stat.com/charts.html?package=promise.prototype.finally
[v1-repo-url]: https://github.com/matthew-andrews/Promise.prototype.finally
[v1-branch-url]: https://github.com/es-shims/Promise.prototype.finally/tree/v1
[codecov-image]: https://codecov.io/gh/es-shims/Promise.prototype.finally/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/Promise.prototype.finally/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Promise.prototype.finally
[actions-url]: https://github.com/es-shims/Promise.prototype.finally/actions