UNPKG

ix

Version:

The Interactive Extensions for JavaScript

32 lines (30 loc) 16.9 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (factory(global.Ix = global.Ix || {})); }(this, (function (exports) {function g(a){return a}async function k(a){return a};function l(a,b){return"undefined"===typeof b?a:function(c,d){return a.call(b,c,d)}};const p=a=>"function"===typeof a,q=a=>null!=a&&Object(a)===a;function r(a){return q(a)&&"number"===typeof a.length}function u(a){return null!=a&&p(a[Symbol.iterator])}function v(a){return q(a)&&!p(a[Symbol.iterator])&&p(a.next)}function w(a){return null!=a&&Object(a)===a&&"function"===typeof a.subscribe}const x=a=>q(a)&&p(a.pipe)&&p(a._read)&&"boolean"===typeof a.readable&&q(a._readableState),y=a=>q(a)&&p(a.end)&&p(a._write)&&"boolean"===typeof a.writable&&q(a._writableState);function z(a){a=Number(a);return isNaN(a)?0:0!==a&&isFinite(a)?(0<a?1:-1)*Math.floor(Math.abs(a)):a};const A=Math.pow(2,53)-1;class B{forEach(a,b){a=l(a,b);b=0;for(const c of this)a(c,b++)}pipe(...a){let b=-1;const c=a.length;let d=this;for(;++b<c;)d=a[b](B.as(d));return d}static as(a){return a instanceof B?a:"string"===typeof a?new C([a],g):u(a)||r(a)?new C(a,g):new C([a],g)}static from(a,b=g,c){b=l(b,c);if(u(a)||r(a))return new C(a,b);if(v(a))return new C({[Symbol.iterator]:()=>a},b);throw new TypeError("Input type not supported");}}B.prototype[Symbol.toStringTag]="IterableX"; Object.defineProperty(B,Symbol.hasInstance,{writable:!0,configurable:!0,value(a){return!(!a||"IterableX"!==a[Symbol.toStringTag])}});class C extends B{constructor(a,b){super();this.g=a;this.m=b}*[Symbol.iterator](){let a=0;if(u(this.g))for(var b of this.g)yield this.m(b,a++);else for(b=Math.min(Math.max(z(this.g.length),0),A);a<b;)yield this.m(this.g[a],a++)}} try{(a=>{if(!a){B.prototype.pipe=function(...c){let d=-1;const e=c.length;let f=this,h;for(;++d<e;)if(h=c[d],"function"===typeof h)f=h(B.as(f));else if(y(h))return{end:c=!0}=c[d+1]||{},x(f)?f.pipe(h,{end:c}):B.as(f).V(b(h)).pipe(h,{end:c});return f};var b=(c,d=c.S||{U:!0})=>d}})("object"===typeof window&&"object"===typeof document&&9===document.nodeType)}catch(a){}const aa=B.as,ba=B.from;function D(a){"function"===typeof a?.return&&a.return()};class E extends B{constructor(a){super();this.g=a}*[Symbol.iterator](){let a=null,b=!1;for(const c of this.g){const d=c[Symbol.iterator]();a=null;for(b=!1;;){let e={};try{const {done:f,value:h}=d.next();if(f){D(d);break}e=h}catch(f){a=f;b=!0;D(d);break}yield e}if(!b)break}if(b)throw a;}};class ca extends B{constructor(a){super();this.g=a}*[Symbol.iterator](){for(const a of this.g)yield*a}};class da extends B{constructor(a){super();this.m=a}[Symbol.iterator](){return this.m()}};class ea extends B{constructor(a){super();this.m=a}*[Symbol.iterator](){for(const a of this.m())yield a}}function F(a){return new ea(a)};class fa extends B{*[Symbol.iterator](){}}function G(){return new fa};class ha extends B{constructor(a,b,c,d){super();this.M=a;this.D=b;this.N=c;this.P=d}*[Symbol.iterator](){for(let a=this.M;this.D(a);a=this.N(a))yield this.P(a)}};function H(a,b){return a===b||"number"===typeof a&&"number"===typeof b&&isNaN(a)&&isNaN(b)}function I(a,b){return a>b?1:a<b?-1:0};function J(a,b,c){let d=[];a=a[Symbol.iterator]();const {value:e,done:f}=a.next();if(f)throw Error("Sequence contains no elements");let h=b(e);d.push(e);for(var m;!(m=a.next()).done;){m=m.value;const n=b(m),t=c(n,h);0===t?d.push(m):0<t&&(d=[m],h=n)}return d};function K(...a){return new ia(a)}class ia extends B{constructor(a){super();this.L=a}*[Symbol.iterator](){yield*this.L}};class ja extends B{constructor(a){super();this.g=a}*[Symbol.iterator](){for(const a of this.g){const b=a[Symbol.iterator]();for(;;){let c;try{c=b.next()}catch(d){break}if(c.done)break;yield c.value}}}};class la extends B{constructor(a,b){super();this.J=a;this.j=b}*[Symbol.iterator](){for(let a=this.J,b=this.J+this.j;a<b;a++)yield a}};function L(a){const b=[];for(const c of a)b.push(c);return b};class ma extends B{constructor(a,b){super();this.g=a;this.j=b}*[Symbol.iterator](){if(-1===this.j)for(;;)for(var a of this.g)yield a;else for(a=0;a<this.j;a++)for(const b of this.g)yield b}};class na extends B{constructor(a){super();this.l=a}*[Symbol.iterator](){throw this.l;}};class M extends Error{constructor(a="The operation has been aborted"){super(a);Object.setPrototypeOf(this,M.prototype);Error.captureStackTrace(this,this.constructor);this.name="AbortError"}get [Symbol.toStringTag](){return"AbortError"}}function N(a){if(a&&a.aborted)throw new M;}Object.defineProperty(M,Symbol.hasInstance,{writable:!0,configurable:!0,value(a){return q(a)&&("AbortError"===a.constructor.name||"AbortError"===a[Symbol.toStringTag])}});class O{async forEach(a,b,c){const d=c?new P(this,c):this;let e=0;for await(const f of d)await a.call(b,f,e++,c)}pipe(...a){let b=-1;const c=a.length;let d=this;for(;++b<c;)d=a[b](O.as(d));return d}static from(a,b=k,c){b=l(b,c);if(u(a)||q(a)&&p(a[Symbol.asyncIterator]))return new Q(a,b);if(q(a)&&p(a.then))return new R(a,b);if(w(a))return new S(a,b);if(r(a))return new T(a,b);if(v(a))return new Q({[Symbol.asyncIterator]:()=>a},b);throw new TypeError("Input type not supported");}static as(a){return a instanceof O?a:"string"===typeof a?new T([a],k):u(a)||q(a)&&p(a[Symbol.asyncIterator])?new Q(a,k):q(a)&&p(a.then)?new R(a,k):w(a)?new S(a,k):r(a)?new T(a,k):new T([a],k)}}O.prototype[Symbol.toStringTag]="AsyncIterableX";Object.defineProperty(O,Symbol.hasInstance,{writable:!0,configurable:!0,value(a){return!(!a||"AsyncIterableX"!==a[Symbol.toStringTag])}}); function U(a,b){if(a.F)throw Error("AsyncSink already ended");if(0<a.u.length){const {resolve:c,reject:d}=a.u.shift();"error"===b.type?d(b.error):c({done:!1,value:b.value})}else a.G.push(b)} class oa{constructor(){this.F=!1;this.G=[];this.u=[]}[Symbol.asyncIterator](){return this}write(a){U(this,{type:"value",value:a})}error(a){U(this,{type:"error",error:a})}next(){if(0<this.G.length){const {type:a,value:b,error:c}=this.G.shift();return"error"===a?Promise.reject(c):Promise.resolve({done:!1,value:b})}return this.F?Promise.resolve({done:!0}):new Promise((a,b)=>{this.u.push({resolve:a,reject:b})})}end(){for(;0<this.u.length;)this.u.shift().resolve({done:!0});this.F=!0}} class T extends O{constructor(a,b){super();this.g=a;this.i=b}async*[Symbol.asyncIterator](){let a=0;const b=Math.min(Math.max(z(this.g.length),0),A);for(;a<b;)yield await this.i(this.g[a],a++)}}class Q extends O{constructor(a,b){super();this.g=a;this.i=b}async*[Symbol.asyncIterator](a){let b=0;if(a&&this.g instanceof O)for await(var c of new P(this.g,a))yield await this.i(c,b++);else{N(a);for await(const d of this.g)N(a),c=await this.i(d,b++),N(a),yield c}}} class R extends O{constructor(a,b){super();this.g=a;this.i=b}async*[Symbol.asyncIterator](){const a=await this.g;yield await this.i(a,0)}} class S extends O{constructor(a,b){super();this.O=a;this.i=b}async*[Symbol.asyncIterator](a){function b(){c.error(new M)}N(a);const c=new oa,d=this.O.subscribe({next(f){c.write(f)},error(f){c.error(f)},complete(){c.end()}});a&&a.addEventListener("abort",b);let e=0;try{for(let f;!(f=await c.next()).done;)N(a),yield await this.i(f.value,e++)}finally{a&&a.removeEventListener("abort",b),d.unsubscribe()}}} class P{constructor(a,b){this.g=a;this.R=b}[Symbol.asyncIterator](){return this.g[Symbol.asyncIterator](this.R)}}try{(a=>{if(!a){O.prototype.pipe=function(...c){let d=-1;const e=c.length;let f=this,h;for(;++d<e;)if(h=c[d],"function"===typeof h)f=h(O.as(f));else if(y(h))return{end:c=!0}=c[d+1]||{},x(f)?f.pipe(h,{end:c}):O.as(f).V(b(h)).pipe(h,{end:c});return f};var b=(c,d=c.S||{U:!0})=>d}})("object"===typeof window&&"object"===typeof document&&9===document.nodeType)}catch(a){};class pa{constructor(){this.A=this.j=0;this.s=new Map}clear(){this.s.clear()}get count(){return this.j}get H(){return this.A}set H(a){this.A=a}done(){this.A--}get(a){if(!this.s.has(a))throw Error("Element no longer available in the buffer.");const b=this.s.get(a),c=b.value;0===--b.count&&this.s.delete(a);return c}push(a){this.s.set(this.j++,{value:a,count:this.A})}};class qa extends B{constructor(a){super();this.o=!1;this.g=a;this.h=new pa}*v(a){try{for(;;){let b=!1,c={};if(a>=this.h.count){if(!this.o)try{const d=this.g.next();if(b=!d.done)c=d.value}catch(d){this.l=d,this.o=!0}if(this.o){if(this.l)throw this.l;break}b&&this.h.push(c)}else b=!0;if(b)yield this.h.get(a);else break;a++}}finally{this.h.done()}}[Symbol.iterator](){this.h.H++;return this.v(this.h.count)[Symbol.iterator]()}}function ra(){return function(a){return new qa(a[Symbol.iterator]())}};class sa extends O{constructor(a){var b=new pa;super();this.B=this.l=null;this.o=!1;this.g=a;this.h=b}[Symbol.asyncIterator](a){N(a);return this.v(0)}async *v(a=0){--a;let b=!1;const c=this.h;try{do if(++a<c.count)yield c.get(a);else{if(this.o)throw this.l;null===this.B&&(this.B=this.g.next().then(d=>{this.B=null;d.done||c.push(d.value);return d}));({done:b}=await this.B.catch(d=>{this.l=d;this.o=!0;throw d;}));b||(yield c.get(a))}while(!b)}finally{c.done()}}};class ta extends sa{[Symbol.asyncIterator](a){N(a);this.h.H++;return this.v(this.h.count)[Symbol.asyncIterator]()}}function ua(){return function(a){return new ta(a[Symbol.asyncIterator]())}};const va="undefined"!==typeof SharedArrayBuffer?SharedArrayBuffer:ArrayBuffer;class wa extends O{constructor(a){super();this.K=a}[Symbol.asyncIterator](){const a=this.K,b=a.getReader();return xa(a,b,ya(b))}}class za extends wa{[Symbol.asyncIterator](){var a=this.K;let b;try{b=a.getReader({mode:"byob"})}catch(c){return super[Symbol.asyncIterator]()}a=xa(a,b,Aa(b));a.next();return a}} async function*xa(a,b,c){let d=!1;try{yield*c}catch(e){(d=!0,b)&&await b.cancel(e)}finally{if(b&&(d||await b.cancel(),a.locked))try{b.closed.catch(()=>{}),b.releaseLock()}catch(e){}}}async function*ya(a){let b;for(;!(b=await a.read()).done;)yield b.value}async function*Aa(a){var b;for(b=yield null;!(b=await Ba(a,b)).done;)b=yield b.value} async function Ba(a,b){let c;if("number"===typeof b)c=new ArrayBuffer(b);else if(b instanceof ArrayBuffer)b=(c=b).byteLength;else if(b instanceof va)b=(c=b).byteLength;else return{done:!0,value:void 0};return await Ca(a,c,0,b)}async function Ca(a,b,c,d){if(c>=d)return{done:!1,value:new Uint8Array(b,0,d)};const {done:e,value:f}=await a.read(new Uint8Array(b,c,d-c));return(c+=f.byteLength)<d&&!e?await Ca(a,f.buffer,c,d):{done:e,value:new Uint8Array(f.buffer,0,c)}} function Da(a,b){return b&&"byob"===b.mode?new za(a):new wa(a)};function Ea(a,b,c=0,d=b.byteLength){const e=a.byteLength;a=new Uint8Array(a.buffer,a.byteOffset,e);b=new Uint8Array(b.buffer,b.byteOffset,Math.min(d,e,b.buffer.byteLength-b.byteOffset));a.set(b,c);return b.byteLength}class Fa{constructor(a){this.g=a}async cancel(){const a=this.g;a&&a.return&&await a.return();this.g=null}}class Ga extends Fa{async pull(a){var b=this.g;if(b&&(b=await b.next(a.desiredSize),!b.done))return a.enqueue(b.value);a.close()}} class Ha extends Fa{constructor(a,b={}){super(a);this.type="bytes";this.autoAllocateChunkSize=b.autoAllocateChunkSize;this.T=new Ga(a)}async pull(a){if(!a.byobRequest)return await this.T.pull(a);if(this.g){const b=a.byobRequest.view,{done:c,value:d}=await this.g.next(b);if(!c){if("number"===typeof d)return a.byobRequest.respond(d);if(ArrayBuffer.isView(d))return d.buffer===b.buffer?a.byobRequest.respondWithNewView(d):a.byobRequest.respond(Ea(b,d))}}a.close()}} const Ia=(()=>{let a,b,c=(e,f)=>{class h extends ReadableStream{[Symbol.asyncIterator](){return Da(this)[Symbol.asyncIterator]()}}class m extends ReadableStream{[Symbol.asyncIterator](){return Da(this,{mode:"byob"})[Symbol.asyncIterator]()}}a=m;b=h;c=d;return d(e,f)};const d=(e,f)=>e instanceof Ha?new a(e,f):new b(e,f);return(e,f)=>c(e,f)})();function V(a,b){return b&&"type"in b&&"bytes"===b.type?Ia(new Ha(a[Symbol.asyncIterator](),b),b):Ia(new Ga(a[Symbol.asyncIterator]()),b)}O.prototype.tee=function(){return W(this).tee()}; O.prototype.pipeTo=function(a,b){return W(this).pipeTo(a,b)};O.prototype.pipeThrough=function(a,b){return W(this).pipeThrough(a,b)};function W(a){return a.C||(a.C=a.pipe(ua(),V))}O.prototype.toDOMStream=function(a){return a?V(this,a):V(this)};function X(a,b){return V(O.as(a),b)}B.prototype.tee=function(){return Y(this).tee()};B.prototype.pipeTo=function(a,b){return Y(this).pipeTo(a,b)};B.prototype.pipeThrough=function(a,b){return Y(this).pipeThrough(a,b)};function Y(a){return a.C||(a.C=a.pipe(ra(),X))}B.prototype.toDOMStream=function(a){return a?X(this,a):X(this)};class Ja extends B{constructor(a,b){super();this.D=a;this.g=b}*[Symbol.iterator](){for(;this.D();)yield*this.g}};class Ka extends B{constructor(a){super();this.I=a}*[Symbol.iterator](){const a=this.I.length,b=this.I.map(c=>c[Symbol.iterator]());for(;0<a;){const c=Array(a);for(let d=-1;++d<a;){const e=b[d].next();if(e.done){b.forEach(D);return}c[d]=e.value}yield c}}};var Z={};Z.IterableX=B;Z.as=aa;Z.average=function(a,b){const {selector:c=g,thisArg:d}=b||{};let e=b=0;for(const f of a)b+=c.call(d,f),e++;if(0===e)throw Error("Empty collection");return b/e};Z.catchAll=function(a){return new E(a)};Z.catchError=function(...a){return new E(a)};Z.concat=function(...a){return new ca(a)};Z.count=function(a,b){const {thisArg:c,predicate:d=()=>!0}=b||{};b=0;for(const e of a)d.call(c,e,b)&&b++;return b};Z.create=function(a){return new da(a)};Z.defer=F; Z.elementAt=function(a,b){for(const c of a){if(0===b)return c;b--}};Z.empty=G;Z.every=function(a,b){const {thisArg:c,predicate:d}=b;b=0;for(const e of a)if(!d.call(c,e,b++))return!1;return!0};Z.find=function(a,b){const {thisArg:c,predicate:d}=b;b=0;for(const e of a)if(d.call(c,e,b++))return e};Z.findIndex=function(a,b){const {thisArg:c,predicate:d}=b;b=0;for(const e of a)if(d.call(c,e,b++))return b;return-1}; Z.first=function(a,b){const {thisArg:c,predicate:d=()=>!0}=b||{};b=0;for(const e of a)if(d.call(c,e,b++))return e};Z.from=ba;Z.generate=function(a,b,c,d){return new ha(a,b,c,d)};Z.iif=function(a,b,c=G()){return F(()=>a()?b:c)};Z.includes=function(a,b,c=0){let d=0;Math.abs(c)&&(c=0);for(const e of a)if(d++>c&&H(e,b))return!0;return!1};Z.isEmpty=function(a){for(const b of a)return!1;return!0}; Z.last=function(a,b){const {thisArg:c,predicate:d=()=>!0}=b||{};b=0;let e;for(const f of a)d.call(c,f,b++)&&(e=f);return e};Z.max=function(a,b){const {comparer:c=I,selector:d=g}=b||{};a=a[Symbol.iterator]();var e=a.next();if(e.done)throw Error("Sequence contains no elements");for(b=d(e.value);!(e=a.next()).done;)e=d(e.value),0<c(e,b)&&(b=e);return b};Z.maxBy=function(a,b){const {comparer:c=I,selector:d}=b||{};return J(a,d,c)}; Z.min=function(a,b){const {comparer:c=I,selector:d=g}=b||{};a=a[Symbol.iterator]();var e=a.next();if(e.done)throw Error("Sequence contains no elements");for(b=d(e.value);!(e=a.next()).done;)e=d(e.value),0>c(e,b)&&(b=e);return b};Z.minBy=function(a,b){const {comparer:c=I,selector:d}=b||{};return J(a,d,(e,f)=>-c(e,f))};Z.of=K;Z.onErrorResumeNext=function(...a){return new ja(a)};Z.range=function(a,b){return new la(a,b)}; Z.reduce=function(a,b,c){var d="function"===typeof b?2<arguments.length?{callback:b,seed:c}:{callback:b}:b;const {seed:e,callback:f}=d;d=d.hasOwnProperty("seed");let h=0,m=!1,n=e;for(const t of a)(m||=d)?n=f(n,t,h++):(n=t,m=!0,h++);if(!d&&!m)throw Error("Sequence contains no elements");return n}; Z.reduceRight=function(a,b,c){var d="function"===typeof b?2<arguments.length?{callback:b,seed:c}:{callback:b}:b;const {seed:e,callback:f}=d;d=d.hasOwnProperty("seed");const h=L(a);let m=!1,n=e;for(let t=h.length-1;0<=t;t--){const ka=h[t];(m||=d)?n=f(n,ka,t):(n=ka,m=!0)}if(!d&&!m)throw Error("Sequence contains no elements");return n};Z.repeatValue=function(a,b=-1){return new ma(K(a),b)}; Z.sequenceEqual=function(a,b,c){({comparer:c=H}=c||{});a=a[Symbol.iterator]();b=b[Symbol.iterator]();let d,e;for(;!(d=a.next()).done;)if((e=b.next()).done||!c(d.value,e.value))return!1;return!!b.next().done};Z.single=function(a,b){const {thisArg:c,predicate:d=()=>!0}=b||{};let e;b=!1;let f=0;for(const h of a){if(b&&d.call(c,h,f++))throw Error("More than one element was found");d.call(c,h,f++)&&(e=h,b=!0)}return e}; Z.some=function(a,b){const {thisArg:c,predicate:d}=b;b=0;for(const e of a)if(d.call(c,e,b++))return!0;return!1};Z.sum=function(a,b){const {selector:c=g,thisArg:d}=b||{};b=0;for(const e of a)b+=c.call(d,e);return b};Z.throwError=function(a){return new na(a)};Z.toArray=L;Z.toDOMStream=X;Z.toMap=function(a,b){const {elementSelector:c=g,keySelector:d=g}=b||{};b=new Map;for(const e of a){a=c(e);const f=d(e);b.set(f,a)}return b};Z.toSet=function(a){const b=new Set;for(const c of a)b.add(c);return b}; Z.whileDo=function(a,b){return new Ja(b,a)};Z.zip=function(...a){return new Ka(a)};Object.assign(arguments[0],Z);}.bind(this)))); //# sourceMappingURL=iterable.esnext.min.js.map