UNPKG

@klodianimeri/pipejs

Version:

Pipe functions that provide convenient and efficient ways to work with iterators.

3 lines (2 loc) 17.9 kB
function n(n,r){this.v=n,this.k=r}function r(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 e(r){var e={},t=!1;function u(e,u){return t=!0,u=new Promise(function(n){n(r[e](u))}),{done:!1,value:new n(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 r.throw&&(e.throw=function(n){if(t)throw t=!1,n;return u("throw",n)}),"function"==typeof r.return&&(e.return=function(n){return t?(t=!1,n):u("return",n)}),e}function t(n){var r,e,t,o=2;for("undefined"!=typeof Symbol&&(e=Symbol.asyncIterator,t=Symbol.iterator);o--;){if(e&&null!=(r=n[e]))return r.call(n);if(t&&null!=(r=n[t]))return new u(r.call(n));e="@@asyncIterator",t="@@iterator"}throw new TypeError("Object is not async iterable")}function u(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 u=function(n){this.s=n,this.n=n.next},u.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 u(n)}function o(r){return new n(r,0)}function i(n,e){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,e){if(n){if("string"==typeof n)return r(n,e);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)?r(n,e):void 0}}(n))||e&&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 a(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(n){}return(a=function(){return!!n})()}function f(){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 c(f,"_invoke",function(e,t,u){var o,a,f,c=0,l=u||[],s=!1,v={p:0,n:0,v:n,a:p,f:p.bind(n,4),d:function(r,e){return o=r,a=0,f=n,v.n=e,i}};function p(e,t){for(a=e,f=t,r=0;!s&&c&&!u&&r<l.length;r++){var u,o=l[r],p=v.p,y=o[2];e>3?(u=y===t)&&(f=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=n):o[0]<=p&&((u=e<2&&p<o[1])?(a=0,v.v=t,v.n=o[1]):p<y&&(u=e<3||o[0]>t||t>y)&&(o[4]=e,o[5]=t,v.n=y,a=0))}if(u||e>1)return i;throw s=!0,t}return function(u,l,y){if(c>1)throw TypeError("Generator is already running");for(s&&1===l&&p(l,y),a=l,f=y;(r=a<2?n:f)||!s;){o||(a?a<3?(a>1&&(v.n=-1),p(a,f)):v.n=f:v.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=(s=v.n<0)?f:e.call(t,v))!==i)break}catch(r){o=n,a=1,f=r}finally{c=1}}return{value:r,done:s}}}(e,u,o),!0),f}var i={};function a(){}function l(){}function s(){}r=Object.getPrototypeOf;var v=[][t]?r(r([][t]())):(c(r={},t,function(){return this}),r),p=s.prototype=a.prototype=Object.create(v);function y(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,s):(n.__proto__=s,c(n,u,"GeneratorFunction")),n.prototype=Object.create(p),n}return l.prototype=s,c(p,"constructor",s),c(s,"constructor",l),l.displayName="GeneratorFunction",c(s,u,"GeneratorFunction"),c(p),c(p,u,"Generator"),c(p,t,function(){return this}),c(p,"toString",function(){return"[object Generator]"}),(f=function(){return{w:o,m:y}})()}function c(n,r,e,t){var u=Object.defineProperty;try{u({},"",{})}catch(n){u=0}c=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){c(n,r,function(n){return this._invoke(r,e,n)})}o("next",0),o("throw",1),o("return",2)}},c(n,r,e,t)}function l(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 v(r){var e,t;function u(e,t){try{var i=r[e](t),a=i.value,f=a instanceof n;Promise.resolve(f?a.v:a).then(function(n){if(f){var t="return"===e?"return":"next";if(!a.k||n.done)return u(t,n);n=r[t](n).value}o(i.done?"return":"normal",n)},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 r.return&&(this.return=void 0)}v.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},v.prototype.next=function(n){return this._invoke("next",n)},v.prototype.throw=function(n){return this._invoke("throw",n)},v.prototype.return=function(n){return this._invoke("return",n)};var p=/*#__PURE__*/f().m(y);function y(n){var r,e,t,u,o,a,c,s,v,y,d,h,b,x,m,w=arguments;return f().w(function(f){for(;;)switch(f.n){case 0:if(r=[].slice.call(w,1),n&&"function"==typeof n[Symbol.iterator]){f.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){f.n=3;break}return f.d(l(n),2);case 2:return f.a(2);case 3:for(e=new Array,t=i(r);!(u=t()).done;)e.push((0,u.value)());o=n[Symbol.iterator](),a=o.next();case 4:c=a.done,s=new Array(a),v=0;case 5:if(!(v<e.length)){f.n=15;break}y=new Array,d=0;case 6:if(!(d<s.length)){f.n=13;break}h=e[v](s[d]),h=Array.isArray(h)?h:[h],b=0;case 7:if(!(b<h.length)){f.n=12;break}if(void 0!==h[b]){f.n=8;break}return f.a(3,11);case 8:if(!(v<r.length-1)){f.n=9;break}return y.push(h[b]),f.a(3,11);case 9:if(null==(x=h[b])||!x.done){f.n=10;break}return f.a(2);case 10:if(null==(m=h[b])||!m.hasOwnProperty("value")){f.n=11;break}return f.n=11,h[b].value;case 11:b++,f.n=7;break;case 12:d++,f.n=6;break;case 13:s=y;case 14:v++,f.n=5;break;case 15:if(!c){f.n=16;break}return f.a(3,17);case 16:a=o.next(),f.n=4;break;case 17:return f.a(2)}},p)}function d(){var n;return n=/*#__PURE__*/f().m(function n(r){var u,a,c,s,v,p,y,d,h,b,x,m,w,k,S=arguments;return f().w(function(n){for(;;)switch(n.n){case 0:if(u=[].slice.call(S,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(u)&&0!==u.length){n.n=3;break}return n.d(l(e(t(r))),2);case 2:return n.a(2);case 3:for(a=new Array,c=i(u);!(s=c()).done;)a.push((0,s.value)());return v=r[Symbol.asyncIterator](),n.n=4,o(v.next());case 4:p=n.v;case 5:y=p.done,d=new Array(p),h=0;case 6:if(!(h<a.length)){n.n=16;break}b=new Array,x=0;case 7:if(!(x<d.length)){n.n=14;break}m=a[h](d[x]),m=Array.isArray(m)?m:[m],w=0;case 8:if(!(w<m.length)){n.n=13;break}if(void 0!==m[w]){n.n=9;break}return n.a(3,12);case 9:if(!(h<u.length-1)){n.n=10;break}return b.push(m[w]),n.a(3,12);case 10:if(null==(k=m[w])||!k.done){n.n=11;break}return n.a(2);case 11:if(!("value"in m[w])){n.n=12;break}return n.n=12,m[w].value;case 12:w++,n.n=8;break;case 13:x++,n.n=7;break;case 14:d=b;case 15:h++,n.n=6;break;case 16:if(!y){n.n=17;break}return n.a(3,19);case 17:return n.n=18,o(v.next());case 18:p=n.v,n.n=5;break;case 19:return n.a(2)}},n)}),d=function(){return new v(n.apply(this,arguments))},d.apply(this,arguments)}var h=function(n){return{value:n,done:!1}},b=function(n){for(var r=new Array,e=0;e<n.length;e++)r[e]={value:n[e],done:!1};return r},x=function(n){return Object({value:n,done:!0})},m=function(n){if(!n||"function"!=typeof n[Symbol.iterator])throw new Error("Value not a sync iterator: "+n)},w=function(n,r){return n.splice(n.length,0,r),n},k=function(){return Number.POSITIVE_INFINITY},S=function(){return Number.NEGATIVE_INFINITY};function A(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done?e:r===n?[e,x()]:void 0}}}function g(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 O=A;function I(n,r){return function(){var r=-1,e=-1;return function(t){if(++r,null!=t&&t.done)return[h(e),t];n(t.value)&&(e=r)}}}var j=g;exports.at=A,exports.average=function(){return function(){var n=0,r=0;return function(e){if(null!=e&&e.done)return 0===n?e:[h(r/n),e];"number"==typeof e.value&&(++n,r+=e.value)}}},exports.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?[h(e),t]:t;if(e.push(t.value),e.length===n){t.value=function(n,r,e){if(a())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}}}},exports.concat=function(n){return m(n),function(){return function(r){return null!=r&&r.done?w(b(Array.from(n)),r):r}}},exports.count=function(){return function(){var n=-1;return function(r){if(++n,null!=r&&r.done)return[h(n),r]}}},exports.defaultIfEmpty=function(n){return function(){var r=!0;return function(e){if(null!=e&&e.done){if(r)return[h(n),e]}else r=!1;return e}}},exports.difference=function(n){return m(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)}}},exports.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)}}},exports.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}}},exports.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}}},exports.drop=g,exports.elementAt=O,exports.endWith=function(){var n=arguments;return function(){return function(r){return r.done?w(b([].slice.call(n)),r):r}}},exports.entries=function(){return function(){var n=-1;return function(r){return++n,r.done||Array.isArray(r.value)||(r.value=[n,r.value]),r}}},exports.every=function(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done?[h(!0),e]:n(e.value,r)?void 0:[h(!1),x()]}}},exports.fill=function(n,r,e){return r="number"==typeof r?r:0,e="number"==typeof e?e:k(),function(){var t=-1;return function(u){return++t,(null==u||!u.done)&&t>=r&&t<e&&(u.value=n),u}}},exports.filter=function(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done||n(e.value,r)?e:void 0}}},exports.find=function(n){return function(){var r=-1;return function(e){return++r,null!=e&&e.done?e:n(e.value,r)?[e,x()]:void 0}}},exports.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)?[h(e),x()]:void 0}}},exports.findLast=function(n){return function(){var r,e=-1;return function(t){if(++e,null!=t&&t.done)return void 0===r?t:[h(r),t];n(t.value,e)&&(r=t.value)}}},exports.findLastIndex=I,exports.first=function(){return function(){return function(n){return null!=n&&n.done?n:[n,x()]}}},exports.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:b(Array.from(r.value).flat(n))}}},exports.ignoreElements=function(){return function(){return function(n){if(null!=n&&n.done)return n}}},exports.includes=function(n,r){return r="number"==typeof r?r:0,function(){var e=-1;return function(t){return++e,null!=t&&t.done?[h(!1),t]:e>=r&&t.value===n?[h(!0),x()]:void 0}}},exports.indexOf=function(n,r){return r="number"==typeof r?r:0,function(){var e=-1;return function(t){return++e,null!=t&&t.done?[h(-1),t]:e>=r&&n===t.value?[h(e),x()]:void 0}}},exports.intersection=function(n){return m(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}}},exports.isDisjointFrom=function(n){return m(n),function(){var r=n instanceof Set?n:new Set(n);return function(n){return null!=n&&n.done?[h(!0),n]:r.has(n.value)?[h(!1),x()]:void 0}}},exports.isEmpty=function(){return function(){return function(n){return null!=n&&n.done?[h(!0),n]:[h(!1),x()]}}},exports.isSubsetOf=function(n){return m(n),function(){var r=n instanceof Set?n:new Set(n);return function(n){return null!=n&&n.done?[h(!0),n]:r.has(n.value)?void 0:[h(!1),x()]}}},exports.isSupersetOf=function(n){return m(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?[h(!0),n]:[h(!1),n];r.has(n.value)&&++e}}},exports.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}}},exports.last=function(){return function(){var n,r=-1;return function(e){if(++r,null!=e&&e.done)return 0===r?e:[h(n),e];n=e.value}}},exports.lastIndexOf=function(n,r){return I(function(r){return r===n})},exports.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}}},exports.mapTo=function(n){return function(){return function(r){return r.value=n,r}}},exports.max=function(){return function(){var n=S();return function(r){if(null!=r&&r.done)return n===S()?r:[h(n),r];"number"==typeof r.value&&r.value>n&&(n=r.value)}}},exports.min=function(){return function(){var n=k();return function(r){if(null!=r&&r.done)return n===k()?r:[h(n),r];"number"==typeof r.value&&r.value<n&&(n=r.value)}}},exports.pipeAsync=function(n){return d.apply(this,arguments)},exports.pipeSync=y,exports.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}}},exports.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[h(e),u];e=n(e,u.value,t)}}},exports.reverse=function(){return function(){var n=new Array;return function(r){if(null!=r&&r.done)return[].concat(n,[r]);n.unshift(r)}}},exports.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}}},exports.size=function(){return function(){var n=-1;return function(r){if(++n,null!=r&&r.done)return[h(n),r]}}},exports.skip=j,exports.skipLast=function(n){return n="number"==typeof n&&n>0?n:S(),function(){var r=new Array;return function(e){return r.push(e),e.done?e:r.length>n?r.shift():void 0}}},exports.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?x():void 0}}},exports.some=function(n){return function(){return function(r){return null!=r&&r.done?[h(!1),r]:n(r.value)?[h(!0),x()]:void 0}}},exports.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)?b(e):void 0}}},exports.startWith=function(){var n=arguments;return function(){var r=!1;return function(e){return r?e:(r=!0,w(b([].slice.call(n)),e))}}},exports.sum=function(){return function(){var n=0;return function(r){if(null!=r&&r.done)return[h(n),r];"number"==typeof r.value&&(n+=r.value)}}},exports.symmetricDifference=function(n){m(n);var r=new Set;return function(){return function(e){if(null!=e&&e.done){for(var t,u=new Array,o=i(n);!(t=o()).done;){var a=t.value;r.has(a)||(r.add(a),u.push(a))}return w(b(u),e)}if(!r.has(e.value))return r.add(e.value),e}}},exports.take=function(n){return n="number"==typeof n&&n>0?n:k(),function(){var r=-1;return function(e){return++r>=n?x():e}}},exports.takeLast=function(n){return n="number"==typeof n&&n>0?n:k(),function(){var r=new Array;return function(e){if(null!=e&&e.done)return w(b(r),e);r.length===n&&r.shift(),r.push(e.value)}}},exports.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,x()]:x()}}},exports.toArray=function(){return function(){var n=new Array;return function(r){if(null!=r&&r.done)return[h(n),r];n.push(r.value)}}},exports.toSet=function(){return function(){var n=new Set;return function(r){if(null!=r&&r.done)return[h(n),r];n.add(r.value)}}},exports.union=function(n){return m(n),function(){var r=new Set;return function(e){if(null!=e&&e.done){for(var t,u=new Array,o=i(n);!(t=o()).done;){var a=t.value;r.has(a)||(r.add(a),u.push(a))}return w(b(u),e)}if(!r.has(e.value))return r.add(e.value),e}}},exports.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.cjs.map