Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-toolbox

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-toolbox - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

12

dist/index.js

@@ -61,6 +61,6 @@ 'use strict';Object.defineProperty(exports,"__esModule",{value:true});exports.TimeoutError=exports.finally=exports.fromCallback=exports.forOwn=exports.forIterable=exports.forIn=exports.forEach=exports.forArray=exports.makeAsyncIterator=exports.defer=exports.cancellable=exports.nodeify=exports.isPromise=undefined;var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj;};exports.all=all;exports.asCallback=asCallback;exports.catchPlus=catchPlus;exports.delay=delay;exports.join=join;exports.lastly=lastly;exports.promisify=promisify;exports.promisifyAll=promisifyAll;exports.reflect=reflect;exports.settle=settle;exports.some=some;exports.tap=tap;exports.timeout=timeout;exports.unpromisify=unpromisify;var _makeError=require('make-error');function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self,call){if(!self){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call&&(typeof call==="object"||typeof call==="function")?call:self;}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass;} // ===================================================================

// Usage: promise::lastly(cb)
function lastly(cb){return _wrap(this).then(function(value){return _wrap(cb()).then(function(){return value;});},function(reason){return _wrap(cb()).then(function(){throw reason;});});}exports.finally=lastly; // -------------------------------------------------------------------
function lastly(cb){var _this3=this;return _wrap(this).then(function(value){return _wrap(cb()).then(function(){return _this3;});},function(reason){return _wrap(cb()).then(function(){return _this3;});});}exports.finally=lastly; // -------------------------------------------------------------------
var _setFunctionNameAndLength=function(){var _defineProperties=Object.defineProperties;try{var f=_defineProperties(function(){},{length:{value:2},name:{value:'foo'}});if(f.length===2&&f.name==='foo'){return function(fn,name,length){return _defineProperties(fn,{length:{configurable:true,value:length},name:{configurable:true,value:name}});};}}catch(_){}return function(fn){return fn;};}(); // Usage: fn::promisify([ context ])
function promisify(context){var fn=this;return _setFunctionNameAndLength(function(){var _this3=this;var length=arguments.length;var args=new Array(length+1);for(var i=0;i<length;++i){args[i]=arguments[i];}return new Promise(function(resolve,reject){args[length]=function(error,result){return error?reject(error):resolve(result);};fn.apply(context||_this3,args);});},fn.name,fn.length&&fn.length-1);}var _DEFAULT_PALL_MAPPER=function _DEFAULT_PALL_MAPPER(name,fn){return !(_endsWith(name,'Sync')||_endsWith(name,'Async'))&&name;}; // Usage: obj::promisifyAll([ opts ])
function promisifyAll(){var _this4=this;var _ref=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var _ref$mapper=_ref.mapper;var mapper=_ref$mapper===undefined?_DEFAULT_PALL_MAPPER:_ref$mapper;var _ref$target=_ref.target;var target=_ref$target===undefined?{}:_ref$target;var _ref$context=_ref.context;var context=_ref$context===undefined?this:_ref$context;_forIn(this,function(value,name){var newName=void 0;if(typeof value==='function'&&(newName=mapper(name,value,_this4))){target[newName]=promisify.call(value,context);}});return target;} // -------------------------------------------------------------------
function promisify(context){var fn=this;return _setFunctionNameAndLength(function(){var _this4=this;var length=arguments.length;var args=new Array(length+1);for(var i=0;i<length;++i){args[i]=arguments[i];}return new Promise(function(resolve,reject){args[length]=function(error,result){return error?reject(error):resolve(result);};fn.apply(context||_this4,args);});},fn.name,fn.length&&fn.length-1);}var _DEFAULT_PALL_MAPPER=function _DEFAULT_PALL_MAPPER(name,fn){return !(_endsWith(name,'Sync')||_endsWith(name,'Async'))&&name;}; // Usage: obj::promisifyAll([ opts ])
function promisifyAll(){var _this5=this;var _ref=arguments.length<=0||arguments[0]===undefined?{}:arguments[0];var _ref$mapper=_ref.mapper;var mapper=_ref$mapper===undefined?_DEFAULT_PALL_MAPPER:_ref$mapper;var _ref$target=_ref.target;var target=_ref$target===undefined?{}:_ref$target;var _ref$context=_ref.context;var context=_ref$context===undefined?this:_ref$context;_forIn(this,function(value,name){var newName=void 0;if(typeof value==='function'&&(newName=mapper(name,value,_this5))){target[newName]=promisify.call(value,context);}});return target;} // -------------------------------------------------------------------
var FN_FALSE=function FN_FALSE(){return false;};var FN_TRUE=function FN_TRUE(){return true;};var _reflectResolution=function(__proto__){return function(_value){return {__proto__:__proto__,value:function value(){return _value;}};};}({isFulfilled:FN_TRUE,isPending:FN_FALSE,isRejected:FN_FALSE,isResolved:FN_TRUE,reason:function reason(){throw new Error('no reason, the promise has resolved');}});var _reflectRejection=function(__proto__){return function(_reason){return {__proto__:__proto__,reason:function reason(){return _reason;}};};}({isFulfilled:FN_FALSE,isPending:FN_FALSE,isRejected:FN_TRUE,isResolved:FN_FALSE,value:function value(){throw new Error('no value, the promise has rejected');}}); // Returns a promise that is always successful when this promise is

@@ -84,7 +84,7 @@ // settled. Its fulfillment value is an object that implements the

function some(count){return _wrap(this).then(function(promises){return _some(promises,count);});} // -------------------------------------------------------------------
function tap(onResolved,onRejected){var _this5=this;var forward=function forward(){return _this5;};return _wrap(this).then(onResolved&&function(value){return _wrap(onResolved(value)).then(forward);},onRejected&&function(reason){return _wrap(onRejected(reason)).then(forward);});} // -------------------------------------------------------------------
var TimeoutError=exports.TimeoutError=function(_BaseError){_inherits(TimeoutError,_BaseError);function TimeoutError(){_classCallCheck(this,TimeoutError);return _possibleConstructorReturn(this,Object.getPrototypeOf(TimeoutError).call(this,'operation timed out'));}return TimeoutError;}(_makeError.BaseError); // Usage: promise::timeout(ms)
function timeout(ms){var _this7=this;return new Promise(function(resolve,reject){var handle=setTimeout(function(){handle=null;reject(new TimeoutError());if(typeof _this7.cancel==='function'){_this7.cancel();}},ms);_wrap(_this7).then(function(value){handle!==null&&clearTimeout(handle);resolve(value);},function(reason){handle!==null&&clearTimeout(handle);reject(reason);});});} // -------------------------------------------------------------------
function tap(onResolved,onRejected){var _this6=this;var forward=function forward(){return _this6;};return _wrap(this).then(onResolved&&function(value){return _wrap(onResolved(value)).then(forward);},onRejected&&function(reason){return _wrap(onRejected(reason)).then(forward);});} // -------------------------------------------------------------------
var TimeoutError=exports.TimeoutError=function(_BaseError){_inherits(TimeoutError,_BaseError);function TimeoutError(){_classCallCheck(this,TimeoutError);return _possibleConstructorReturn(this,Object.getPrototypeOf(TimeoutError).call(this,'operation timed out'));}return TimeoutError;}(_makeError.BaseError); // Usage: promise::timeout(ms, cb)
function timeout(ms,cb){var _this8=this;return new Promise(function(resolve,reject){var handle=setTimeout(function(){handle=null;if(typeof _this8.cancel==='function'){_this8.cancel();}if(cb){resolve(cb());}else {reject(new TimeoutError());}},ms);_wrap(_this8).then(function(value){handle!==null&&clearTimeout(handle);resolve(value);},function(reason){handle!==null&&clearTimeout(handle);reject(reason);});});} // -------------------------------------------------------------------
// Usage: fn::unpromisify()
function unpromisify(){var fn=this;return _setFunctionNameAndLength(function(){var n=arguments.length-1;var cb=void 0;if(n<0||typeof (cb=arguments[n])!=='function'){throw new Error('missing callback');}var args=new Array(n);for(var i=0;i<n;++i){args[i]=arguments[i];}_wrapCall(fn,args,this).then(function(result){return cb(null,result);},function(reason){return cb(reason);});},fn.name,fn.length+1);}
//# sourceMappingURL=index.js.map

@@ -17,4 +17,4 @@ 'use strict';var _slicedToArray=function(){function sliceIterator(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally {try{if(!_n&&_i["return"])_i["return"]();}finally {if(_d)throw _e;}}return _arr;}return function(arr,i){if(Array.isArray(arr)){return arr;}else if(Symbol.iterator in Object(arr)){return sliceIterator(arr,i);}else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}(); /* eslint-env mocha */var _must=require('must');var _must2=_interopRequireDefault(_must);var _makeError=require('make-error');var _makeError2=_interopRequireDefault(_makeError);var _sinon=require('sinon');var _sinon2=_interopRequireDefault(_sinon);var _=require('./');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};} // ===================================================================

describe('tap(cb)',function(){it('call cb with the resolved value',function(){return new Promise(function(resolve){var _context14;(_context14=Promise.resolve('value'),_.tap).call(_context14,function(value){(0,_must2.default)(value).to.equal('value');resolve();});});});it('does not call cb if the promise is rejected',function(){var _context15;return (0,_must2.default)((_context15=Promise.reject('reason'),_.tap).call(_context15,function(){return Promise.reject('other reason');})).to.reject.to.equal('reason');});it('forwards the resolved value',function(){var _context16;return (0,_must2.default)((_context16=Promise.resolve('value'),_.tap).call(_context16,function(){return 'other value';})).to.resolve.to.equal('value');});it('rejects if cb rejects',function(){var _context17;return (0,_must2.default)((_context17=Promise.resolve('value'),_.tap).call(_context17,function(){return Promise.reject('reason');})).to.reject.to.equal('reason');});});describe('tap(null, cb)',function(){it('call cb with the rejected reason',function(){return new Promise(function(resolve){var _context18;(_context18=Promise.reject('reason'),_.tap).call(_context18,null,function(reason){(0,_must2.default)(reason).to.equal('reason');resolve();});});});it('does not call cb if the promise is resolved',function(){var _context19;return (0,_must2.default)((_context19=Promise.resolve('value'),_.tap).call(_context19,null,function(){return Promise.reject('other reason');})).to.resolve.to.equal('value');});it('forwards the rejected reason',function(){var _context20;return (0,_must2.default)((_context20=Promise.reject('reason'),_.tap).call(_context20,null,function(){return 'value';})).to.reject.to.equal('reason');});it('rejects if cb rejects',function(){var _context21;return (0,_must2.default)((_context21=Promise.reject('reason'),_.tap).call(_context21,null,function(){return Promise.reject('other reason');})).to.reject.to.equal('other reason');});}); // -------------------------------------------------------------------
describe('timeout()',function(){it('rejects a promise if not settled after a delay',function(){var _context22;return (0,_must2.default)((_context22=new Promise(function(){}),_.timeout).call(_context22,10)).to.reject.to.error(_.TimeoutError);});it('forwards the settlement if settled before a delay',function(){var _context23;return Promise.all([(0,_must2.default)((_context23=Promise.resolve('value'),_.timeout).call(_context23,10)).to.resolve.to.equal('value'),(0,_must2.default)((_context23=Promise.reject('reason'),_.timeout).call(_context23,10)).to.reject.to.equal('reason')]);});}); // -------------------------------------------------------------------
describe('timeout()',function(){it('rejects a promise if not settled after a delay',function(){var _context22;return (0,_must2.default)((_context22=new Promise(function(){}),_.timeout).call(_context22,10)).to.reject.to.error(_.TimeoutError);});it('call the callback if not settled after a delay',function(){var _context23;return (0,_must2.default)((_context23=new Promise(function(){}),_.timeout).call(_context23,10,function(){return 'bar';})).to.resolve.to.equal('bar');});it('forwards the settlement if settled before a delay',function(){var _context24;return Promise.all([(0,_must2.default)((_context24=Promise.resolve('value'),_.timeout).call(_context24,10)).to.resolve.to.equal('value'),(0,_must2.default)((_context24=Promise.reject('reason'),_.timeout).call(_context24,10)).to.reject.to.equal('reason')]);});}); // -------------------------------------------------------------------
describe('unpromisify()',function(){it('forwards the result',function(done){var fn=_.unpromisify.call(function(){return Promise.resolve('foo');});fn(function(error,result){(0,_must2.default)(error).to.not.exist();(0,_must2.default)(result).to.equal('foo');done();});});it('forwards the error',function(done){var fn=_.unpromisify.call(function(){return Promise.reject('foo');});fn(function(error){(0,_must2.default)(error).to.equal('foo');done();});});});
//# sourceMappingURL=index.spec.js.map
{
"name": "promise-toolbox",
"version": "0.5.0",
"version": "0.5.1",
"license": "ISC",

@@ -14,7 +14,7 @@ "description": "Essential utils for promises",

],
"homepage": "https://github.com/julien-f/js-promise-toolbox",
"bugs": "https://github.com/julien-f/js-promise-toolbox/issues",
"homepage": "https://github.com/JsCommunity/promise-toolbox",
"bugs": "https://github.com/JsCommunity/promise-toolbox/issues",
"repository": {
"type": "git",
"url": "https://github.com/julien-f/js-promise-toolbox"
"url": "https://github.com/JsCommunity/promise-toolbox"
},

@@ -46,6 +46,6 @@ "author": {

"julien-f-source-map-support": "0.0.0",
"mocha": "^2.3.4",
"mocha": "^3.0.0",
"must": "^0.13.1",
"native-promise-only": "^0.8.1",
"nyc": "^6.1.1",
"nyc": "^8.1.0",
"sinon": "^1.17.2",

@@ -52,0 +52,0 @@ "standard": "^7.0.0",

@@ -1,2 +0,2 @@

# promise-toolbox [![Build Status](https://travis-ci.org/julien-f/js-promise-toolbox.png?branch=master)](https://travis-ci.org/julien-f/js-promise-toolbox)
# promise-toolbox [![Build Status](https://travis-ci.org/JsCommunity/promise-toolbox.png?branch=master)](https://travis-ci.org/JsCommunity/promise-toolbox)

@@ -360,6 +360,9 @@ > Essential utils for promises.

#### promise::timeout(ms)
#### promise::timeout(ms, [cb])
> Automatically rejects a promise if it is still pending after `ms`
> milliseconds.
> Call a callback if the promise is still pending after `ms`
> milliseconds. Its resolution/rejection is forwarded.
>
> If the callback is omitted, the returned promise is rejected with a
> `Timeout` error.

@@ -369,2 +372,6 @@ ```js

await doLongOperation()::timeout(100, () => {
return doFallbackOperation()
})
await doLongOperation()::timeout(100)

@@ -402,3 +409,3 @@ ```

- report any [issue](https://github.com/julien-f/js-promise-toolbox/issues)
- report any [issue](https://github.com/JsCommunity/promise-toolbox/issues)
you've encountered;

@@ -405,0 +412,0 @@ - fork and create a pull request.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc