arbitrary-promise
Advanced tools
Comparing version 0.0.0-semantic-release to 0.0.1
@@ -59,21 +59,100 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function hello() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'World'; | ||
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"); } }; }(); | ||
return 'Hello, ' + name + '!'; | ||
} | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function goodbye() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'World'; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
return 'Bye ' + name + '.'; | ||
} | ||
var ArbitraryPromise = function () { | ||
function ArbitraryPromise(passReceivePairs) { | ||
_classCallCheck(this, ArbitraryPromise); | ||
exports.default = { | ||
hello: hello, | ||
goodbye: goodbye | ||
}; | ||
if (!this._validatePassReceivePairs(passReceivePairs)) throw new Error("must pass in tuples of function names like [['handleData', 'onData'], ...]"); | ||
this._createState(); | ||
passReceivePairs.forEach(this._processPassReceivePair.bind(this)); | ||
} | ||
// Remove all state. Useful for applications making heavy repeated use | ||
// of single promises. | ||
_createClass(ArbitraryPromise, [{ | ||
key: 'clear', | ||
value: function clear() { | ||
this._resetState(); | ||
} | ||
}, { | ||
key: '_createState', | ||
value: function _createState() { | ||
this._state = {}; | ||
} | ||
}, { | ||
key: '_resetState', | ||
value: function _resetState() { | ||
var _this = this; | ||
Object.keys(this._state).forEach(function (stateKey) { | ||
_this._state[stateKey] = []; | ||
}); | ||
} | ||
}, { | ||
key: '_processPassReceivePair', | ||
value: function _processPassReceivePair(pair) { | ||
var _this2 = this; | ||
var _pair = _slicedToArray(pair, 2), | ||
pass = _pair[0], | ||
receive = _pair[1]; | ||
var stateKey = '__state_' + pass; | ||
var handlerKey = '__handler_' + receive; | ||
// This will contain the data from every pass call | ||
this._state[stateKey] = []; | ||
this[receive] = function (handler) { | ||
// set local handler for pass funk to call | ||
_this2[handlerKey] = handler; | ||
// Get all data previously called from pass funk | ||
_this2._state[stateKey].forEach(handler); | ||
}; | ||
this[pass] = function (data) { | ||
// Save data for future receive assignments to get | ||
_this2._state[stateKey].push(data); | ||
// Call receive function with data | ||
_this2[handlerKey] && _this2[handlerKey](data); | ||
}; | ||
} | ||
}, { | ||
key: '_validatePassReceivePairs', | ||
value: function _validatePassReceivePairs(passReceivePairs) { | ||
var isArray = Array.isArray(passReceivePairs); | ||
if (!isArray) return false; | ||
var hasSomeEntries = passReceivePairs.length >= 1; | ||
if (!hasSomeEntries) return false; | ||
var isTuples = passReceivePairs.every(function (pair) { | ||
return pair.length === 2; | ||
}); | ||
if (!isTuples) return false; | ||
var areStrings = passReceivePairs.every(function (pair) { | ||
return typeof pair[0] === 'string' && typeof pair[1] === 'string'; | ||
}); | ||
if (!areStrings) return false; | ||
return true; | ||
} | ||
}]); | ||
return ArbitraryPromise; | ||
}(); | ||
module.exports = ArbitraryPromise; | ||
@@ -80,0 +159,0 @@ /***/ }) |
@@ -1,2 +0,2 @@ | ||
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.arbitraryPromise=o():e.arbitraryPromise=o()}(this,function(){return function(e){function o(r){if(t[r])return t[r].exports;var n=t[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,o),n.loaded=!0,n.exports}var t={};return o.m=e,o.c=t,o.p="",o(0)}([function(e,o){"use strict";function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"World";return"Hello, "+e+"!"}function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"World";return"Bye "+e+"."}Object.defineProperty(o,"__esModule",{value:!0}),o.default={hello:t,goodbye:r}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.arbitraryPromise=e():t.arbitraryPromise=e()}(this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return t[n].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var n=function(){function t(t,e){var r=[],n=!0,i=!1,a=void 0;try{for(var o,s=t[Symbol.iterator]();!(n=(o=s.next()).done)&&(r.push(o.value),!e||r.length!==e);n=!0);}catch(t){i=!0,a=t}finally{try{!n&&s.return&&s.return()}finally{if(i)throw a}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),i=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),a=function(){function t(e){if(r(this,t),!this._validatePassReceivePairs(e))throw new Error("must pass in tuples of function names like [['handleData', 'onData'], ...]");this._createState(),e.forEach(this._processPassReceivePair.bind(this))}return i(t,[{key:"clear",value:function(){this._resetState()}},{key:"_createState",value:function(){this._state={}}},{key:"_resetState",value:function(){var t=this;Object.keys(this._state).forEach(function(e){t._state[e]=[]})}},{key:"_processPassReceivePair",value:function(t){var e=this,r=n(t,2),i=r[0],a=r[1],o="__state_"+i,s="__handler_"+a;this._state[o]=[],this[a]=function(t){e[s]=t,e._state[o].forEach(t)},this[i]=function(t){e._state[o].push(t),e[s]&&e[s](t)}}},{key:"_validatePassReceivePairs",value:function(t){var e=Array.isArray(t);if(!e)return!1;var r=t.length>=1;if(!r)return!1;var n=t.every(function(t){return 2===t.length});if(!n)return!1;var i=t.every(function(t){return"string"==typeof t[0]&&"string"==typeof t[1]});return!!i}}]),t}();t.exports=a}])}); | ||
//# sourceMappingURL=arbitrary-promise.min.js.map |
110
lib/index.js
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function hello() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'World'; | ||
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"); } }; }(); | ||
return 'Hello, ' + name + '!'; | ||
} | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function goodbye() { | ||
var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'World'; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
return 'Bye ' + name + '.'; | ||
} | ||
var ArbitraryPromise = function () { | ||
function ArbitraryPromise(passReceivePairs) { | ||
_classCallCheck(this, ArbitraryPromise); | ||
exports.default = { | ||
hello: hello, | ||
goodbye: goodbye | ||
}; | ||
module.exports = exports['default']; | ||
if (!this._validatePassReceivePairs(passReceivePairs)) throw new Error("must pass in tuples of function names like [['handleData', 'onData'], ...]"); | ||
this._createState(); | ||
passReceivePairs.forEach(this._processPassReceivePair.bind(this)); | ||
} | ||
// Remove all state. Useful for applications making heavy repeated use | ||
// of single promises. | ||
_createClass(ArbitraryPromise, [{ | ||
key: 'clear', | ||
value: function clear() { | ||
this._resetState(); | ||
} | ||
}, { | ||
key: '_createState', | ||
value: function _createState() { | ||
this._state = {}; | ||
} | ||
}, { | ||
key: '_resetState', | ||
value: function _resetState() { | ||
var _this = this; | ||
Object.keys(this._state).forEach(function (stateKey) { | ||
_this._state[stateKey] = []; | ||
}); | ||
} | ||
}, { | ||
key: '_processPassReceivePair', | ||
value: function _processPassReceivePair(pair) { | ||
var _this2 = this; | ||
var _pair = _slicedToArray(pair, 2), | ||
pass = _pair[0], | ||
receive = _pair[1]; | ||
var stateKey = '__state_' + pass; | ||
var handlerKey = '__handler_' + receive; | ||
// This will contain the data from every pass call | ||
this._state[stateKey] = []; | ||
this[receive] = function (handler) { | ||
// set local handler for pass funk to call | ||
_this2[handlerKey] = handler; | ||
// Get all data previously called from pass funk | ||
_this2._state[stateKey].forEach(handler); | ||
}; | ||
this[pass] = function (data) { | ||
// Save data for future receive assignments to get | ||
_this2._state[stateKey].push(data); | ||
// Call receive function with data | ||
_this2[handlerKey] && _this2[handlerKey](data); | ||
}; | ||
} | ||
}, { | ||
key: '_validatePassReceivePairs', | ||
value: function _validatePassReceivePairs(passReceivePairs) { | ||
var isArray = Array.isArray(passReceivePairs); | ||
if (!isArray) return false; | ||
var hasSomeEntries = passReceivePairs.length >= 1; | ||
if (!hasSomeEntries) return false; | ||
var isTuples = passReceivePairs.every(function (pair) { | ||
return pair.length === 2; | ||
}); | ||
if (!isTuples) return false; | ||
var areStrings = passReceivePairs.every(function (pair) { | ||
return typeof pair[0] === 'string' && typeof pair[1] === 'string'; | ||
}); | ||
if (!areStrings) return false; | ||
return true; | ||
} | ||
}]); | ||
return ArbitraryPromise; | ||
}(); | ||
module.exports = ArbitraryPromise; |
{ | ||
"name": "arbitrary-promise", | ||
"version": "0.0.0-semantic-release", | ||
"version": "0.0.1", | ||
"description": "ArbitraryPromise is a simple Promise library that allows you to make your own arbitrarily named resolve/then functions.", | ||
@@ -10,4 +10,4 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"test": "cross-env BABEL_ENV=test mocha --compilers js:babel-core/register --recursive", | ||
"test:with-coverage": "npm run clean:coverage && cross-env BABEL_ENV=test nyc --reporter=lcov mocha --compilers js:babel-core/register --recursive", | ||
"test": "cross-env BABEL_ENV=test mocha --require babel-core/register --recursive", | ||
"test:with-coverage": "npm run clean:coverage && cross-env BABEL_ENV=test nyc --reporter=lcov mocha --require babel-core/register --recursive", | ||
"test:check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100", | ||
@@ -14,0 +14,0 @@ "test:publish-coverage": "codecov", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
54911
247