es-shims / Promise.try

ES Proposal spec-compliant shim for Promise.try

Home Page:https://github.com/tc39/proposal-promise-try

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

promise.try Version Badge

github actions coverage License Downloads

npm badge

ES Proposal spec-compliant shim for Promise.try. Invoke its "shim" method to shim Promise.try 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:

var assert = require('assert');
var promiseTry = require('promise.try');

promiseTry(function (e) {
	throw e;
}, 42).catch(function (e) {
	assert.equal(e, 42);
});

promiseTry(function () {
	return Infinity;
}).then(function (x) {
	assert.equal(x, Infinity);
});

promiseTry.shim(); // will be a no-op if not needed

Promise.try(function () {
	throw 42;
}).catch(function (e) {
	assert.equal(e, 42);
});

Promise.try(function () {
	return Infinity;
}).then(function (x) {
	assert.equal(x, Infinity);
});

Tests

Simply clone the repo, npm install, and run npm test

About

ES Proposal spec-compliant shim for Promise.try

https://github.com/tc39/proposal-promise-try

License:MIT License


Languages

Language:JavaScript 100.0%