iterize
Version:
Use JavaScript Iterator, Easily
1 lines • 18.3 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Iterize=e():t.Iterize=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=7)}([function(t,e,r){var n,o,i;o=[e,r(5),r(9),r(6),r(12),r(13)],void 0===(i="function"==typeof(n=function(t,e,n,o,i,u){"use strict";var a=r(1);Object.defineProperty(t,"__esModule",{value:!0}),t.BehaviorError=t.ArgumentError=void 0,e=a(e),n=a(n),o=a(o),i=a(i);var c=function(t){function r(t){var i;return(0,e.default)(this,r),(i=(0,n.default)(this,(0,o.default)(r).call(this,t))).name="Argument Error",i}return(0,i.default)(r,t),r}((0,(u=a(u)).default)(Error));t.ArgumentError=c;var f=function(t){function r(t){var i;return(0,e.default)(this,r),(i=(0,n.default)(this,(0,o.default)(r).call(this,t))).name="IteratorBehavior Error",i}return(0,i.default)(r,t),r}((0,u.default)(Error));t.BehaviorError=f})?n.apply(e,o):n)||(t.exports=i)},function(t,e){t.exports=function(t){return t&&t.__esModule?t:{default:t}}},function(t,e,r){var n,o,i;o=[e,r(5),r(16),r(17),r(0)],void 0===(i="function"==typeof(n=function(t,e,n,o,i){"use strict";var u=r(1);Object.defineProperty(t,"__esModule",{value:!0}),t.RangeIterator=t.RepeatIterator=t.ArrayIterator=t.PrimitiveIterator=void 0,e=u(e),n=u(n),o=u(o);var a=Symbol.iterator,c=function(){function t(r){(0,e.default)(this,t),(0,o.default)(this,"value",void 0),(0,o.default)(this,"done",!1),this.value=r}return(0,n.default)(t,[{key:a,value:function(){return this}},{key:"next",value:function(){return this.done?{value:void 0,done:!0}:(this.done=!0,{value:this.value,done:!1})}},{key:"clone",value:function(){return new t(this.value)}}]),t}();t.PrimitiveIterator=c;var f=Symbol.iterator,s=function(){function t(r){(0,e.default)(this,t),(0,o.default)(this,"arr",void 0),(0,o.default)(this,"arrIterator",void 0),this.arr=r,this.arrIterator=r[Symbol.iterator]()}return(0,n.default)(t,[{key:f,value:function(){return this}},{key:"next",value:function(){return this.arrIterator.next()}},{key:"clone",value:function(){return new t(this.arr)}}]),t}();t.ArrayIterator=s;var l=Symbol.iterator,p=function(){function t(r,n){(0,e.default)(this,t),(0,o.default)(this,"iterator",void 0),(0,o.default)(this,"repeatLimit",void 0),(0,o.default)(this,"repeatCount",1),this.iterator=r,this.repeatLimit=n}return(0,n.default)(t,[{key:l,value:function(){return this}},{key:"next",value:function(){var e=this.iterator.next();if(!e.done)return e;if(this.repeatLimit!==t.FOREVER&&!(this.repeatCount<this.repeatLimit))return{value:void 0,done:!0};if(this.iterator=this.iterator.clone(),(e=this.iterator.next()).done)throw new i.BehaviorError("Iterator should iterable more than once.");return this.repeatCount++,e}},{key:"clone",value:function(){return new t(this.iterator,this.repeatLimit)}}]),t}();t.RepeatIterator=p,(0,o.default)(p,"FOREVER",-1);var h=Symbol.iterator,y=function(){function t(r,n,i){(0,e.default)(this,t),(0,o.default)(this,"start",void 0),(0,o.default)(this,"end",void 0),(0,o.default)(this,"step",void 0),(0,o.default)(this,"current",void 0),this.start=r,this.end=n,this.step=i,this.current=r}return(0,n.default)(t,[{key:h,value:function(){return this}},{key:"next",value:function(){if(this.hasNext()){var t=this.current;return this.current=this.step(this.current),{value:t,done:!1}}return{value:void 0,done:!0}}},{key:"hasNext",value:function(){return this.start<this.end?this.current<this.end:this.current>this.end}},{key:"clone",value:function(){return new t(this.start,this.end,this.step)}}]),t}();t.RangeIterator=y})?n.apply(e,o):n)||(t.exports=i)},function(t,e){function r(e,n){return t.exports=r=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},r(e,n)}t.exports=r},function(t,e,r){var n,o,i;o=[e,r(2)],void 0===(i="function"==typeof(n=function(t,e){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isIterator=function(t){return void 0!==t.next&&void 0!==t.clone},t.isRepeatIterator=function(t){return t instanceof e.RepeatIterator}})?n.apply(e,o):n)||(t.exports=i)},function(t,e){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}},function(t,e){function r(e){return t.exports=r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},r(e)}t.exports=r},function(t,e,r){var n,o,i;o=[e,r(8),r(18),r(19),r(23)],void 0===(i="function"==typeof(n=function(t,e,n,o,i){"use strict";var u=r(1);Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"range",{enumerable:!0,get:function(){return e.default}}),Object.defineProperty(t,"cycle",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(t,"take",{enumerable:!0,get:function(){return o.take}}),Object.defineProperty(t,"takeWhile",{enumerable:!0,get:function(){return o.takeWhile}}),Object.defineProperty(t,"repeat",{enumerable:!0,get:function(){return i.default}}),e=u(e),n=u(n),i=u(i)})?n.apply(e,o):n)||(t.exports=i)},function(t,e,r){var n,o,i;o=[e,r(0),r(2)],void 0===(i="function"==typeof(n=function(t,e,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default=function(t,n,o){if(void 0===n&&(n=t,t=0),void 0===o&&(o=t<n?1:-1),function(t,e){return t===e}(t,n))throw new e.ArgumentError("The range parameter is same.");if(function(t,e,r){return"number"!=typeof t||"number"!=typeof e||"number"!=typeof r&&"function"!=typeof r}(t,n,o))throw new e.ArgumentError("Please check arguments type.");var i=o;if("number"==typeof o){var u=o;i=function(t){return t+u}}return new r.RangeIterator(t,n,i)}})?n.apply(e,o):n)||(t.exports=i)},function(t,e,r){var n=r(10),o=r(11);t.exports=function(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?o(t):e}},function(t,e){function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(e){return"function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?t.exports=n=function(t){return r(t)}:t.exports=n=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)},n(e)}t.exports=n},function(t,e){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}},function(t,e,r){var n=r(3);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)}},function(t,e,r){var n=r(6),o=r(3),i=r(14),u=r(15);function a(e){var r="function"==typeof Map?new Map:void 0;return t.exports=a=function(t){if(null===t||!i(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return u(t,arguments,n(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),o(e,t)},a(e)}t.exports=a},function(t,e){t.exports=function(t){return-1!==Function.toString.call(t).indexOf("[native code]")}},function(t,e,r){var n=r(3);function o(e,r,i){return!function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}()?t.exports=o=function(t,e,r){var o=[null];o.push.apply(o,e);var i=new(Function.bind.apply(t,o));return r&&n(i,r.prototype),i}:t.exports=o=Reflect.construct,o.apply(null,arguments)}t.exports=o},function(t,e){function r(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)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),t}},function(t,e){t.exports=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}},function(t,e,r){var n,o,i;o=[e,r(0),r(2),r(4)],void 0===(i="function"==typeof(n=function(t,e,r,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default=function(t){if(function(t){return"string"!=typeof t&&!Array.isArray(t)&&!(0,n.isIterator)(t)}(t))throw new e.ArgumentError("Please check arguments type.");if(Array.isArray(t)&&0===t.length)throw new e.ArgumentError("Array is empty.");if((0,n.isRepeatIterator)(t))throw new e.ArgumentError("Do not use infinite type iterator.");var o;return o=Array.isArray(t)?new r.ArrayIterator(t):"string"==typeof t?new r.ArrayIterator(t.split("")):t,new r.RepeatIterator(o,r.RepeatIterator.FOREVER)}})?n.apply(e,o):n)||(t.exports=i)},function(t,e,r){var n,o,i;o=[e,r(20),r(0),r(4)],void 0===(i="function"==typeof(n=function(t,e,n,o){"use strict";var i=r(1);function u(t,r){var o;return e.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!c(t,r)){e.next=2;break}throw new n.ArgumentError("Please check arguments type.");case 2:o=0;case 3:if(!(o++<t)){e.next=8;break}return e.next=6,r.next().value;case 6:e.next=3;break;case 8:case"end":return e.stop()}},s,this)}function a(t,r){var o;return e.default.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!f(t,r)){e.next=2;break}throw new n.ArgumentError("Please check arguments type.");case 2:if(!(o=r.next()).done){e.next=6;break}return e.abrupt("break",11);case 6:if(!t(o.value)){e.next=9;break}return e.next=9,o.value;case 9:e.next=2;break;case 11:case"end":return e.stop()}},l,this)}function c(t,e){return"number"!=typeof t||!(0,o.isIterator)(e)}function f(t,e){return"function"!=typeof t||!(0,o.isIterator)(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.take=u,t.takeWhile=a;var s=(e=i(e)).default.mark(u),l=e.default.mark(a)})?n.apply(e,o):n)||(t.exports=i)},function(t,e,r){t.exports=r(21)},function(t,e,r){var n=function(){return this||"object"==typeof self&&self}()||Function("return this")(),o=n.regeneratorRuntime&&Object.getOwnPropertyNames(n).indexOf("regeneratorRuntime")>=0,i=o&&n.regeneratorRuntime;if(n.regeneratorRuntime=void 0,t.exports=r(22),o)n.regeneratorRuntime=i;else try{delete n.regeneratorRuntime}catch(t){n.regeneratorRuntime=void 0}},function(t,e){!function(e){"use strict";var r,n=Object.prototype,o=n.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},u=i.iterator||"@@iterator",a=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag",f="object"==typeof t,s=e.regeneratorRuntime;if(s)f&&(t.exports=s);else{(s=e.regeneratorRuntime=f?t.exports:{}).wrap=w;var l="suspendedStart",p="suspendedYield",h="executing",y="completed",d={},v={};v[u]=function(){return this};var m=Object.getPrototypeOf,b=m&&m(m(S([])));b&&b!==n&&o.call(b,u)&&(v=b);var g=_.prototype=E.prototype=Object.create(v);O.prototype=g.constructor=_,_.constructor=O,_[c]=O.displayName="GeneratorFunction",s.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===O||"GeneratorFunction"===(e.displayName||e.name))},s.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,_):(t.__proto__=_,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(g),t},s.awrap=function(t){return{__await:t}},j(k.prototype),k.prototype[a]=function(){return this},s.AsyncIterator=k,s.async=function(t,e,r,n){var o=new k(w(t,e,r,n));return s.isGeneratorFunction(e)?o:o.next().then(function(t){return t.done?t.value:o.next()})},j(g),g[c]="Generator",g[u]=function(){return this},g.toString=function(){return"[object Generator]"},s.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},s.values=S,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(R),!t)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,o){return a.type="throw",a.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var u=this.tryEntries[i],a=u.completion;if("root"===u.tryLoc)return n("end");if(u.tryLoc<=this.prev){var c=o.call(u,"catchLoc"),f=o.call(u,"finallyLoc");if(c&&f){if(this.prev<u.catchLoc)return n(u.catchLoc,!0);if(this.prev<u.finallyLoc)return n(u.finallyLoc)}else if(c){if(this.prev<u.catchLoc)return n(u.catchLoc,!0)}else{if(!f)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return n(u.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(u)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),R(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;R(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:S(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),d}}}function w(t,e,r,n){var o=e&&e.prototype instanceof E?e:E,i=Object.create(o.prototype),u=new L(n||[]);return i._invoke=function(t,e,r){var n=l;return function(o,i){if(n===h)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw i;return A()}for(r.method=o,r.arg=i;;){var u=r.delegate;if(u){var a=P(u,r);if(a){if(a===d)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var c=x(t,e,r);if("normal"===c.type){if(n=r.done?y:p,c.arg===d)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=y,r.method="throw",r.arg=c.arg)}}}(t,r,u),i}function x(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}function E(){}function O(){}function _(){}function j(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function k(t){var e;this._invoke=function(r,n){function i(){return new Promise(function(e,i){!function e(r,n,i,u){var a=x(t[r],t,n);if("throw"!==a.type){var c=a.arg,f=c.value;return f&&"object"==typeof f&&o.call(f,"__await")?Promise.resolve(f.__await).then(function(t){e("next",t,i,u)},function(t){e("throw",t,i,u)}):Promise.resolve(f).then(function(t){c.value=t,i(c)},function(t){return e("throw",t,i,u)})}u(a.arg)}(r,n,e,i)})}return e=e?e.then(i,i):i()}}function P(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,P(t,e),"throw"===e.method))return d;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=x(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,d;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,d):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function I(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function S(t){if(t){var e=t[u];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(o.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=r,e.done=!0,e};return i.next=i}}return{next:A}}function A(){return{value:r,done:!0}}}(function(){return this||"object"==typeof self&&self}()||Function("return this")())},function(t,e,r){var n,o,i;o=[e,r(0),r(2),r(4)],void 0===(i="function"==typeof(n=function(t,e,r,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0,t.default=function(t,o){if(function(t,e){return"number"!=typeof e||"number"!=typeof t&&"string"!=typeof t&&"function"!=typeof t&&!(0,n.isIterator)(t)}(t,o))throw new e.ArgumentError("Please check arguments type.");if(function(t){return 1>t}(o))throw new e.ArgumentError("Repeat count must be larger than 1.");if((0,n.isRepeatIterator)(t))throw new e.ArgumentError("Do not use infinite type iterator.");var i;return i=(0,n.isIterator)(t)?t:new r.PrimitiveIterator(t),new r.RepeatIterator(i,o)}})?n.apply(e,o):n)||(t.exports=i)}])});