Comparing version 4.2.1 to 4.2.2
@@ -13,3 +13,3 @@ 'use strict'; | ||
class Promish { | ||
class Promish extends Promise { | ||
constructor(f) { | ||
@@ -19,49 +19,20 @@ if (f instanceof Promish) { | ||
} else if ((f instanceof Promise) || (f.then instanceof Function)) { | ||
// wraping other promise | ||
this.inner = f; | ||
super(function(resolve, reject) { | ||
f.then(resolve, reject); | ||
}); | ||
} else if (f instanceof Error) { | ||
// sugar for 'rethrow' | ||
this.inner = new Promise((resolve,reject) => reject(f)); | ||
super(function(resolve, reject) { | ||
reject(f); | ||
}); | ||
} else if (f instanceof Function) { | ||
this.inner = new Promise(f); | ||
super(f); | ||
} else { | ||
// anything else, resolve with value | ||
this.inner = new Promise(resolve => resolve(f)); | ||
super(function(resolve, reject) { | ||
resolve(f); | ||
}); | ||
} | ||
} | ||
then(t, r) { | ||
var self = this; | ||
return new Promish(function(resolve, reject) { | ||
self.inner.then( | ||
function (value) { | ||
if (t) { | ||
try { | ||
resolve(t(value)); | ||
} | ||
catch(e) { | ||
reject(e); | ||
} | ||
} else { | ||
resolve(value); | ||
} | ||
}, | ||
function(error) { | ||
if (r) { | ||
try { | ||
//console.log('calling onReject with ', error) | ||
resolve(r(error)); | ||
} | ||
catch(e) { | ||
//console.log('caught handler exception', e) | ||
reject(e); | ||
} | ||
} else { | ||
reject(error); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
finally(h) { | ||
@@ -73,2 +44,3 @@ function fin() { return h(); } | ||
catch() { | ||
// extend catch with type-aware or matcher handling | ||
var args = Array.from(arguments); | ||
@@ -100,3 +72,3 @@ var h = args.pop(); | ||
// no match was found send this error to the next promise handler in the chain | ||
return new Promish(function(resolve, reject) { reject(error); }); | ||
return new Promish((resolve, reject) => reject(error)); | ||
}); | ||
@@ -121,17 +93,2 @@ } | ||
// Wrap Promise.all | ||
static all(promises) { | ||
return new Promish(Promise.all(promises)); | ||
} | ||
// Turn a value into a promish | ||
static resolve(value) { | ||
return new Promish(resolve => resolve(value)); | ||
} | ||
// Turn an error into a rejected promish | ||
static reject(error) { | ||
return new Promish((resolve,reject) => reject(error)); | ||
} | ||
// Wrap a synchronous method and resolve with its return value | ||
@@ -146,7 +103,2 @@ static method(f) { | ||
// Wrap Promise.race | ||
static race(promises) { | ||
return new Promish(Promise.race(promises)); | ||
}; | ||
// | ||
@@ -153,0 +105,0 @@ static apply(f, args) { |
{ | ||
"name": "promish", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "ES6 Promise Shim", | ||
@@ -5,0 +5,0 @@ "private": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
19612
4
0
448
222