@klodianimeri/pipejs
Version:
Pipe functions that provide convenient and efficient ways to work with iterators.
3 lines (2 loc) • 17.7 kB
JavaScript
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n||self).pipejs={})}(this,function(n){function r(n,r){this.v=n,this.k=r}function e(n,r){(null==r||r>n.length)&&(r=n.length);for(var e=0,t=Array(r);e<r;e++)t[e]=n[e];return t}function t(n){var e={},t=!1;function u(e,u){return t=!0,u=new Promise(function(r){r(n[e](u))}),{done:!1,value:new r(u,1)}}return e["undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator"]=function(){return this},e.next=function(n){return t?(t=!1,n):u("next",n)},"function"==typeof n.throw&&(e.throw=function(n){if(t)throw t=!1,n;return u("throw",n)}),"function"==typeof n.return&&(e.return=function(n){return t?(t=!1,n):u("return",n)}),e}function u(n){var r,e,t,u=2;for("undefined"!=typeof Symbol&&(e=Symbol.asyncIterator,t=Symbol.iterator);u--;){if(e&&null!=(r=n[e]))return r.call(n);if(t&&null!=(r=n[t]))return new o(r.call(n));e="@@asyncIterator",t="@@iterator"}throw new TypeError("Object is not async iterable")}function o(n){function r(n){if(Object(n)!==n)return Promise.reject(new TypeError(n+" is not an object."));var r=n.done;return Promise.resolve(n.value).then(function(n){return{value:n,done:r}})}return o=function(n){this.s=n,this.n=n.next},o.prototype={s:null,n:null,next:function(){return r(this.n.apply(this.s,arguments))},return:function(n){var e=this.s.return;return void 0===e?Promise.resolve({value:n,done:!0}):r(e.apply(this.s,arguments))},throw:function(n){var e=this.s.return;return void 0===e?Promise.reject(n):r(e.apply(this.s,arguments))}},new o(n)}function i(n){return new r(n,0)}function a(n,r){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,r){if(n){if("string"==typeof n)return e(n,r);var t={}.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?e(n,r):void 0}}(n))||r&&n&&"number"==typeof n.length){t&&(n=t);var u=0;return function(){return u>=n.length?{done:!0}:{done:!1,value:n[u++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(n){}return(f=function(){return!!n})()}function c(){var n,r,e="function"==typeof Symbol?Symbol:{},t=e.iterator||"@@iterator",u=e.toStringTag||"@@toStringTag";function o(e,t,u,o){var f=Object.create((t&&t.prototype instanceof a?t:a).prototype);return l(f,"_invoke",function(e,t,u){var o,a,f,c=0,l=u||[],v=!1,s={p:0,n:0,v:n,a:y,f:y.bind(n,4),d:function(r,e){return o=r,a=0,f=n,s.n=e,i}};function y(e,t){for(a=e,f=t,r=0;!v&&c&&!u&&r<l.length;r++){var u,o=l[r],y=s.p,d=o[2];e>3?(u=d===t)&&(f=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=n):o[0]<=y&&((u=e<2&&y<o[1])?(a=0,s.v=t,s.n=o[1]):y<d&&(u=e<3||o[0]>t||t>d)&&(o[4]=e,o[5]=t,s.n=d,a=0))}if(u||e>1)return i;throw v=!0,t}return function(u,l,d){if(c>1)throw TypeError("Generator is already running");for(v&&1===l&&y(l,d),a=l,f=d;(r=a<2?n:f)||!v;){o||(a?a<3?(a>1&&(s.n=-1),y(a,f)):s.n=f:s.v=f);try{if(c=2,o){if(a||(u="next"),r=o[u]){if(!(r=r.call(o,f)))throw TypeError("iterator result is not an object");if(!r.done)return r;f=r.value,a<2&&(a=0)}else 1===a&&(r=o.return)&&r.call(o),a<2&&(f=TypeError("The iterator does not provide a '"+u+"' method"),a=1);o=n}else if((r=(v=s.n<0)?f:e.call(t,s))!==i)break}catch(r){o=n,a=1,f=r}finally{c=1}}return{value:r,done:v}}}(e,u,o),!0),f}var i={};function a(){}function f(){}function v(){}r=Object.getPrototypeOf;var s=[][t]?r(r([][t]())):(l(r={},t,function(){return this}),r),y=v.prototype=a.prototype=Object.create(s);function d(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,v):(n.__proto__=v,l(n,u,"GeneratorFunction")),n.prototype=Object.create(y),n}return f.prototype=v,l(y,"constructor",v),l(v,"constructor",f),f.displayName="GeneratorFunction",l(v,u,"GeneratorFunction"),l(y),l(y,u,"Generator"),l(y,t,function(){return this}),l(y,"toString",function(){return"[object Generator]"}),(c=function(){return{w:o,m:d}})()}function l(n,r,e,t){var u=Object.defineProperty;try{u({},"",{})}catch(n){u=0}l=function(n,r,e,t){if(r)u?u(n,r,{value:e,enumerable:!t,configurable:!t,writable:!t}):n[r]=e;else{function o(r,e){l(n,r,function(n){return this._invoke(r,e,n)})}o("next",0),o("throw",1),o("return",2)}},l(n,r,e,t)}function v(n){if(null!=n){var r=n["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],e=0;if(r)return r.call(n);if("function"==typeof n.next)return n;if(!isNaN(n.length))return{next:function(){return n&&e>=n.length&&(n=void 0),{value:n&&n[e++],done:!n}}}}throw new TypeError(typeof n+" is not iterable")}function s(n,r){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},s(n,r)}function y(n){var e,t;function u(e,t){try{var i=n[e](t),a=i.value,f=a instanceof r;Promise.resolve(f?a.v:a).then(function(r){if(f){var t="return"===e?"return":"next";if(!a.k||r.done)return u(t,r);r=n[t](r).value}o(i.done?"return":"normal",r)},function(n){u("throw",n)})}catch(n){o("throw",n)}}function o(n,r){switch(n){case"return":e.resolve({value:r,done:!0});break;case"throw":e.reject(r);break;default:e.resolve({value:r,done:!1})}(e=e.next)?u(e.key,e.arg):t=null}this._invoke=function(n,r){return new Promise(function(o,i){var a={key:n,arg:r,resolve:o,reject:i,next:null};t?t=t.next=a:(e=t=a,u(n,r))})},"function"!=typeof n.return&&(this.return=void 0)}y.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},y.prototype.next=function(n){return this._invoke("next",n)},y.prototype.throw=function(n){return this._invoke("throw",n)},y.prototype.return=function(n){return this._invoke("return",n)};var d=/*#__PURE__*/c().m(p);function p(n){var r,e,t,u,o,i,f,l,s,y,p,h,b,m,w,k=arguments;return c().w(function(c){for(;;)switch(c.n){case 0:if(r=[].slice.call(k,1),n&&"function"==typeof n[Symbol.iterator]){c.n=1;break}throw new Error("Source "+n+" not a sync iterator!");case 1:if(Array.isArray(r)&&0!==(r=r.filter(function(n){return"function"==typeof n})).length){c.n=3;break}return c.d(v(n),2);case 2:return c.a(2);case 3:for(e=new Array,t=a(r);!(u=t()).done;)e.push((0,u.value)());o=n[Symbol.iterator](),i=o.next();case 4:f=i.done,l=new Array(i),s=0;case 5:if(!(s<e.length)){c.n=15;break}y=new Array,p=0;case 6:if(!(p<l.length)){c.n=13;break}h=e[s](l[p]),h=Array.isArray(h)?h:[h],b=0;case 7:if(!(b<h.length)){c.n=12;break}if(void 0!==h[b]){c.n=8;break}return c.a(3,11);case 8:if(!(s<r.length-1)){c.n=9;break}return y.push(h[b]),c.a(3,11);case 9:if(null==(m=h[b])||!m.done){c.n=10;break}return c.a(2);case 10:if(null==(w=h[b])||!w.hasOwnProperty("value")){c.n=11;break}return c.n=11,h[b].value;case 11:b++,c.n=7;break;case 12:p++,c.n=6;break;case 13:l=y;case 14:s++,c.n=5;break;case 15:if(!f){c.n=16;break}return c.a(3,17);case 16:i=o.next(),c.n=4;break;case 17:return c.a(2)}},d)}function h(){var n;return n=/*#__PURE__*/c().m(function n(r){var e,o,f,l,s,y,d,p,h,b,m,w,k,S,g=arguments;return c().w(function(n){for(;;)switch(n.n){case 0:if(e=[].slice.call(g,1),r&&"function"==typeof r[Symbol.asyncIterator]){n.n=1;break}throw new Error("Source "+r+" not an async iterator!");case 1:if(Array.isArray(e)&&0!==e.length){n.n=3;break}return n.d(v(t(u(r))),2);case 2:return n.a(2);case 3:for(o=new Array,f=a(e);!(l=f()).done;)o.push((0,l.value)());return s=r[Symbol.asyncIterator](),n.n=4,i(s.next());case 4:y=n.v;case 5:d=y.done,p=new Array(y),h=0;case 6:if(!(h<o.length)){n.n=16;break}b=new Array,m=0;case 7:if(!(m<p.length)){n.n=14;break}w=o[h](p[m]),w=Array.isArray(w)?w:[w],k=0;case 8:if(!(k<w.length)){n.n=13;break}if(void 0!==w[k]){n.n=9;break}return n.a(3,12);case 9:if(!(h<e.length-1)){n.n=10;break}return b.push(w[k]),n.a(3,12);case 10:if(null==(S=w[k])||!S.done){n.n=11;break}return n.a(2);case 11:if(!("value"in w[k])){n.n=12;break}return n.n=12,w[k].value;case 12:k++,n.n=8;break;case 13:m++,n.n=7;break;case 14:p=b;case 15:h++,n.n=6;break;case 16:if(!d){n.n=17;break}return n.a(3,19);case 17:return n.n=18,i(s.next());case 18:y=n.v,n.n=5;break;case 19:return n.a(2)}},n)}),h=function(){return new y(n.apply(this,arguments))},h.apply(this,arguments)}var b=function(n){return{value:n,done:!1}},m=function(n){for(var r=new Array,e=0;e<n.length;e++)r[e]={value:n[e],done:!1};return r},w=function(n){return Object({value:n,done:!0})},k=function(n){if(!n||"function"!=typeof n[Symbol.iterator])throw new Error("Value not a sync iterator: "+n)},S=function(n,r){return n.splice(n.length,0,r),n},g=function(){return Number.POSITIVE_INFINITY},A=function(){return Number.NEGATIVE_INFINITY};function x(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done?e:r===n?[e,w()]:void 0}}}function O(n){return n="number"==typeof n?n:0,function(){var r=-1;return function(e){return++r,null!=e&&e.done||r>=n?e:void 0}}}var j=x;function I(n,r){return function(){var r=-1,e=-1;return function(t){if(++r,null!=t&&t.done)return[b(e),t];n(t.value)&&(e=r)}}}var P=O;n.at=x,n.average=function(){return function(){var n=0,r=0;return function(e){if(null!=e&&e.done)return 0===n?e:[b(r/n),e];"number"==typeof e.value&&(++n,r+=e.value)}}},n.bufferCount=function(n,r){return function(){var e=new Array;return n="number"==typeof n&&n>1?n:1,r="number"==typeof r&&r>1?r:n,function(t){if(null!=t&&t.done)return e.length>0?[b(e),t]:t;if(e.push(t.value),e.length===n){t.value=function(n,r,e){if(f())return Reflect.construct.apply(null,arguments);var t=[null];t.push.apply(t,r);var u=new(n.bind.apply(n,t));return e&&s(u,e.prototype),u}(Array,e);for(var u=0;u<r;u++)e.shift();return t}}}},n.concat=function(n){return k(n),function(){return function(r){return null!=r&&r.done?S(m(Array.from(n)),r):r}}},n.count=function(){return function(){var n=-1;return function(r){if(++n,null!=r&&r.done)return[b(n),r]}}},n.defaultIfEmpty=function(n){return function(){var r=!0;return function(e){if(null!=e&&e.done){if(r)return[b(n),e]}else r=!1;return e}}},n.difference=function(n){return k(n),function(){var r=n instanceof Set?n:new Set(n);return function(n){return null!=n&&n.done?n:r.has(n.value)?void 0:(r.add(n.value),n)}}},n.distinct=function(n){return n="function"==typeof n?n:function(n){return n},function(){var r=new Set;return function(e){return null!=e&&e.done?e:r.has(n(e.value))?void 0:(r.add(n(e.value)),e)}}},n.distinctUntilChanged=function(n){return n="function"==typeof n?n:function(n,r){return n===r},function(){var r;return function(e){if(null!=e&&e.done||!n(e.value,r))return r=e.value,e}}},n.distinctUntilKeyChanged=function(n,r){return r="function"==typeof r?r:function(n,r){return n===r},function(){var e;return function(t){var u,o;if(null!=t&&t.done||null==(u=t.value)||!u.hasOwnProperty(n)||null==(o=e)||!o.hasOwnProperty(n)||!r(t.value[n],e[n]))return e=t.value,t}}},n.drop=O,n.elementAt=j,n.endWith=function(){var n=arguments;return function(){return function(r){return r.done?S(m([].slice.call(n)),r):r}}},n.entries=function(){return function(){var n=-1;return function(r){return++n,r.done||Array.isArray(r.value)||(r.value=[n,r.value]),r}}},n.every=function(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done?[b(!0),e]:n(e.value,r)?void 0:[b(!1),w()]}}},n.fill=function(n,r,e){return r="number"==typeof r?r:0,e="number"==typeof e?e:g(),function(){var t=-1;return function(u){return++t,(null==u||!u.done)&&t>=r&&t<e&&(u.value=n),u}}},n.filter=function(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done||n(e.value,r)?e:void 0}}},n.find=function(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done?e:n(e.value,r)?[e,w()]:void 0}}},n.findIndex=function(n,r){return r="number"==typeof r?r:0,function(){var e=-1;return function(t){return++e,null!=t&&t.done?t:e>=r&&n(t.value,e)?[b(e),w()]:void 0}}},n.findLast=function(n){return function(){var r,e=-1;return function(t){if(++e,null!=t&&t.done)return void 0===r?t:[b(r),t];n(t.value,e)&&(r=t.value)}}},n.findLastIndex=I,n.first=function(){return function(){return function(n){return null!=n&&n.done?n:[n,w()]}}},n.flat=function(n){return n="number"==typeof n&&n>=1?n:1,function(){return function(r){return null!=r&&r.done||"function"!=typeof r.value[Symbol.iterator]?r:m(Array.from(r.value).flat(n))}}},n.ignoreElements=function(){return function(){return function(n){if(null!=n&&n.done)return n}}},n.includes=function(n,r){return r="number"==typeof r?r:0,function(){var e=-1;return function(t){return++e,null!=t&&t.done?[b(!1),t]:e>=r&&t.value===n?[b(!0),w()]:void 0}}},n.indexOf=function(n,r){return r="number"==typeof r?r:0,function(){var e=-1;return function(t){return++e,null!=t&&t.done?[b(-1),t]:e>=r&&n===t.value?[b(e),w()]:void 0}}},n.intersection=function(n){return k(n),function(){var r=n instanceof Set?n:new Set(n);return function(n){return null!=n&&n.done?n:r.has(n.value)?(r.delete(n.value),n):void 0}}},n.isDisjointFrom=function(n){return k(n),function(){var r=n instanceof Set?n:new Set(n);return function(n){return null!=n&&n.done?[b(!0),n]:r.has(n.value)?[b(!1),w()]:void 0}}},n.isEmpty=function(){return function(){return function(n){return null!=n&&n.done?[b(!0),n]:[b(!1),w()]}}},n.isSubsetOf=function(n){return k(n),function(){var r=n instanceof Set?n:new Set(n);return function(n){return null!=n&&n.done?[b(!0),n]:r.has(n.value)?void 0:[b(!1),w()]}}},n.isSupersetOf=function(n){return k(n),function(){var r=n instanceof Set?n:new Set(n),e=0;return function(n){if(null!=n&&n.done)return e===r.size?[b(!0),n]:[b(!1),n];r.has(n.value)&&++e}}},n.keys=function(){return function(){var n=-1;return function(r){return++n,null!=r&&r.done||(r.value=Array.isArray(r.value)&&2==r.value.length?r.value[0]:n),r}}},n.last=function(){return function(){var n,r=-1;return function(e){if(++r,null!=e&&e.done)return 0===r?e:[b(n),e];n=e.value}}},n.lastIndexOf=function(n,r){return I(function(r){return r===n})},n.map=function(n){return n="function"==typeof n?n:function(n){return n},function(){var r=-1;return function(e){return++r,null!=e&&e.done||(e.value=n(e.value,r)),e}}},n.mapTo=function(n){return function(){return function(r){return r.value=n,r}}},n.max=function(){return function(){var n=A();return function(r){if(null!=r&&r.done)return n===A()?r:[b(n),r];"number"==typeof r.value&&r.value>n&&(n=r.value)}}},n.min=function(){return function(){var n=g();return function(r){if(null!=r&&r.done)return n===g()?r:[b(n),r];"number"==typeof r.value&&r.value<n&&(n=r.value)}}},n.pipeAsync=function(n){return h.apply(this,arguments)},n.pipeSync=p,n.pop=function(){return function(){var n;return function(r){if(null!=r&&r.done)return r;var e=n;return void 0!==(n=r)?e:void 0}}},n.reduce=function(n,r){return function(){var e,t=-1;return function(u){if(0===++t&&(e=null!=r?r:u.value),null!=u&&u.done)return[b(e),u];e=n(e,u.value,t)}}},n.reverse=function(){return function(){var n=new Array;return function(r){if(null!=r&&r.done)return[].concat(n,[r]);n.unshift(r)}}},n.scan=function(n,r){return function(){var e,t=-1;return function(u){return 0===++t&&(e=null!=r?r:u.value),null!=u&&u.done||(u.value=e=n(e,u.value,t)),u}}},n.size=function(){return function(){var n=-1;return function(r){if(++n,null!=r&&r.done)return[b(n),r]}}},n.skip=P,n.skipLast=function(n){return n="number"==typeof n&&n>0?n:A(),function(){var r=new Array;return function(e){return r.push(e),e.done?e:r.length>n?r.shift():void 0}}},n.slice=function(n,r){return n="number"==typeof n&&n>=0?n:0,r="number"==typeof r&&r>n?r:Infinity,function(){var e=-1;return function(t){return++e,null!=t&&t.done||e>=n&&e<r?t:e===r?w():void 0}}},n.some=function(n){return function(){return function(r){return null!=r&&r.done?[b(!1),r]:n(r.value)?[b(!0),w()]:void 0}}},n.splice=function(n,r){var e=[].slice.call(arguments,2);return n="number"==typeof n&&n>=0?n:0,r="number"==typeof r&&r>=0?r:0,function(){var t=-1;return function(u){return++t<n||t>=n+r?u:t===n&&Array.isArray(e)?m(e):void 0}}},n.startWith=function(){var n=arguments;return function(){var r=!1;return function(e){return r?e:(r=!0,S(m([].slice.call(n)),e))}}},n.sum=function(){return function(){var n=0;return function(r){if(null!=r&&r.done)return[b(n),r];"number"==typeof r.value&&(n+=r.value)}}},n.symmetricDifference=function(n){k(n);var r=new Set;return function(){return function(e){if(null!=e&&e.done){for(var t,u=new Array,o=a(n);!(t=o()).done;){var i=t.value;r.has(i)||(r.add(i),u.push(i))}return S(m(u),e)}if(!r.has(e.value))return r.add(e.value),e}}},n.take=function(n){return n="number"==typeof n&&n>0?n:g(),function(){var r=-1;return function(e){return++r>=n?w():e}}},n.takeLast=function(n){return n="number"==typeof n&&n>0?n:g(),function(){var r=new Array;return function(e){if(null!=e&&e.done)return S(m(r),e);r.length===n&&r.shift(),r.push(e.value)}}},n.takeWhile=function(n,r){return r="boolean"==typeof r&&r,function(){var e=-1;return function(t){return++e,null!=t&&t.done||n(t.value,e)?t:r?[t,w()]:w()}}},n.toArray=function(){return function(){var n=new Array;return function(r){if(null!=r&&r.done)return[b(n),r];n.push(r.value)}}},n.toSet=function(){return function(){var n=new Set;return function(r){if(null!=r&&r.done)return[b(n),r];n.add(r.value)}}},n.union=function(n){return k(n),function(){var r=new Set;return function(e){if(null!=e&&e.done){for(var t,u=new Array,o=a(n);!(t=o()).done;){var i=t.value;r.has(i)||(r.add(i),u.push(i))}return S(m(u),e)}if(!r.has(e.value))return r.add(e.value),e}}},n.values=function(){return function(){return function(n){return n.done||Array.isArray(n.value)&&2==n.value.length&&(n.value=n.value[1]),n}}}});
//# sourceMappingURL=index.umd.js.map