UNPKG

ixfx

Version:

Bundle of ixfx libraries

1 lines 12.5 kB
import{n as e}from"./chunk-BKBlUVio.js";import{C as t,M as n,R as r,d as i,p as a,s as o,v as s}from"./src-CrVWx2VD.js";const c=(e,r)=>{if(n(t(r,``,`index`)),!Array.isArray(e))throw Error(`Param 'array' is not an array`);return r%=e.length,e.at(r)};function l(e,t){r(s(t,`aboveZero`,`size`),a(e,`array`));let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function*u(e,t,n){if(t===0)throw TypeError(`Offset cannot be 0.`);if(t<0){t=Math.abs(t);for(let r=t;r<e.length;r++)yield n(e[r],e[r-t])}else for(let r=0;r<e.length-t;r++)yield n(e[r],e[r+t])}const d=e=>typeof e==`string`?e:JSON.stringify(e),f=(e,t)=>e===t,ee=(e,t)=>e===t?!0:d(e)===d(t),p=(e,t,r=f)=>{n(a(e,`haystack`),a(t,`needles`),o(r,`eq`));for(let n of t){let t=!1;for(let i of e)if(r(n,i)){t=!0;break}if(!t)return!1}return!0},m=(e,t=d)=>{if(typeof e!=`object`)throw Error(`Param 'data' is expected to be an Iterable. Got type: ${typeof e}`);let n=new Set;for(let r of e){let e=t(r);if(n.has(e))return!0;n.add(e)}return!1},h=e=>{n(a(e,`array`));for(let t=0;t<e.length;t++)for(let n=0;n<e.length;n++)if(t!==n&&e[t]===e[n])return!0;return!1},g=e=>{r(a(e,`options`));let t=[...e],n=0,i=()=>(n++,n===t.length&&(n=0),s()),o=()=>(n--,n===-1&&(n=t.length-1),s()),s=()=>t.at(n);return{toArray:()=>[...t],next:i,prev:o,get current(){return s()},select:e=>{if(typeof e==`number`)n=e;else{let r=t.indexOf(e);if(r===-1)throw Error(`Could not find value`);n=r}}}};function _(e,t,n=`undefined`,r=`from-end`){if(e===void 0)throw Error(`Data undefined`);if(!Array.isArray(e))throw Error(`data is not an array`);if(e.length===t)return[...e];if(e.length>t)return r===`from-end`?e.slice(0,t):e.slice(e.length-t);let i=[...e],a=t-i.length;for(let t=0;t<a;t++)switch(n){case`undefined`:i.push(void 0);break;case`repeat`:i.push(e[t%e.length]);break;case`first`:i.push(e[0]);break;case`last`:i.push(e.at(-1));break}return i}function v(e,t,n){return e.length===0?t:t.length===0?e:(n??=d,typeof n(e[0],t[0])==`string`?ne(e,t,n):te(e,t,n))}const te=(e,t,n)=>e.filter(e=>t.some(t=>n(e,t))),ne=(e,t,n)=>{let r=new Set,i=[];for(let t of e)r.add(n(t));let a=new Set;for(let e of t){let t=n(e);a.has(t)||r.has(t)&&(i.push(e),a.add(t))}return i};function y(e,t,r=f){if(n(a(e,`arrayA`),a(t,`arrayB`),o(r)),e.length!==t.length)return!1;if(typeof r(e[0],t[0])==`string`){let n=r;for(let r=0;r<e.length;r++)if(n(e[r])!==n(t[r]))return!1}else{let n=r;for(let r=0;r<e.length;r++)if(!n(e[r],t[r]))return!1}return!0}function b(e,t,r=f){return n(a(e,`arrayA`),a(t,`arrayB`),o(r)),e.length===t.length?v(e,t,r).length===e.length:!1}const x=(e,t)=>{if(!Array.isArray(e))throw TypeError(`Param 'array' is not an array.`);if(e.length===0)return!0;let n=t??ee,r=e[0];return!e.some(e=>!n(r,e))};function S(e,t,n,r){let i=n??0,a=r??e.length;if(i>=e.length)throw RangeError(`Start ${i} is out of bounds for array of length ${e.length}`);if(a>e.length)throw RangeError(`End ${a} is out of bounds for array of length ${e.length}`);if(i>a)throw RangeError(`Start ${i} is greater than end ${a}`);for(let n=i;n<a;n++)if(t(e[n],n,e))return n;return-1}function C(e,t,n,r){let i=n??e.length-1,a=r??0;if(i>=e.length)throw RangeError(`Start ${i} is out of bounds for array of length ${e.length}`);if(a<0)throw RangeError(`End ${a} is out of bounds`);if(i<a)throw RangeError(`Start ${i} is less than end ${a}`);for(let n=i;n>=a;n--)if(t(e[n],n,e))return n;return-1}function*w(e,t){for(let n=0;n<e.length;n++)t(e[n],n,e)&&(yield n)}function T(e,t){let n=[],r=[];for(let i of e)t(i)?n.push(i):r.push(i);return[n,r]}function*E(e,t,r,o){n(a(e,`array`)),r===void 0&&(r=0),o===void 0&&(o=e.length),n(i(e,r,`startIndex`)),n(i(e,o-1,`endIndex`));for(let n=r;n<o;n++)t(e[n],n,e)&&(yield e[n])}const D=e=>[...e].flat(),O=(e,t,n)=>typeof e!=`object`||!Array.isArray(e)||e.length===0?Array.isArray(n)?n:[n]:e.map(t);var k=class e{#e=new Map;#t;#n=0;constructor(e=e=>e.toString()){this.#t=e}add(e){if(!Array.isArray(e))throw TypeError(`Param 'array' is expected to be an array. Got type: '${typeof e}'`);for(let t of e){let e=this.#t(t);if(typeof e!=`string`&&typeof e!=`number`)throw TypeError(`groupBy function is expected to return type string or number. Got type: '${typeof e}' for value: '${t}'`);let n=(this.#e.get(e)??0)+1;this.#n++,this.#e.set(e,n)}}static fromArray(t,n){let r=new e(n);return r.add(t),r}static*entriesFromArray(t,n){return yield*e.fromArray(t,n).entries()}getRelative(e){let t=this.#e.get(e);if(t!==void 0)return t/this.#n}has(e){return this.#e.has(e)}get(e){return this.#e.get(e)}entries(){return this.#e.entries()}*entriesRelative(){for(let[e,t]of this.#e.entries())yield[e,t/this.#n]}keys(){return this.#e.keys()}values(){return this.#e.values()}averageFrequency(){let e=0;for(let t of this.#e.values())e+=t;return e/this.#e.size}};const A=(e,t)=>{let n=new Map;for(let r of e){let e=t(r),i=n.get(e);i||(i=[],n.set(e,i)),i.push(r)}return n},j=(e,t,...n)=>(r(a(e,`data`),i(e,t,`index`)),t===e.length-1?[...e,...n]:t===0?[...n,...e]:[...e.slice(0,t),...n,...e.slice(t)]),M=(...e)=>{if(e.some(e=>!Array.isArray(e)))throw Error(`All parameters must be an array`);let t=e.map(e=>e.length);if(!x(t))throw Error(`Arrays must be of same length`);let n=[],r=t[0];for(let t=0;t<r;t++)for(let r of e)n.push(r[t]);return n},N=(e,t,...n)=>{let r=new Map;for(let i of n)for(let n of i){if(n===void 0)continue;let i=e(n),a=r.get(i);a=a?t(a,n):n,r.set(i,a)}return[...r.values()]},P=e=>F(e).seen,F=e=>{let t=[],n=typeof e==`object`?e.reject:void 0,r=typeof e==`object`?e.allow:void 0,i=typeof e==`number`?e:e.samples;return{seen:e=>{if(n&&n(e)||r&&!r(e))return t;for(t.push(e);t.length>i;)t.shift();return t},get data(){return[...t]}}};function*re(e){if(n(a(e,`values`)),e.length<2)throw Error(`Array needs to have at least two entries. Length: ${e.length}`);for(let t=1;t<e.length;t++)yield[e[t-1],e[t]]}const I=(e,t,r)=>{if(n(a(e,`arr`)),e.length<2)return r;for(let n=0;n<e.length-1;n++)r=t(r,e[n],e[n+1]);return r},L=(e,t=Math.random)=>{n(a(e,`dataToShuffle`),o(t,`rand`));let r=[...e];for(let e=r.length-1;e>0;e--){let n=Math.floor(t()*(e+1));[r[e],r[n]]=[r[n],r[e]]}return r},R=(e,t=Math.random)=>(n(a(e,`array`),o(t,`rand`)),e[Math.floor(t()*e.length)]),z=(e,t=Math.random)=>(n(a(e,`array`),o(t,`rand`)),Math.floor(t()*e.length));function B(e,t){if(!Array.isArray(e))throw TypeError(`Parameter 'data' should be an array`);return n(i(e,t,`index`)),[...e.slice(0,t),...e.slice(t+1)]}function V(e,t){if(!Array.isArray(e))throw TypeError(`Parameter 'input' should be an array`);if(typeof t!=`function`)throw TypeError(`Parameter 'prediate' should be a function. Got type: ${typeof t}`);let n=e.length,r=e.filter(e=>!t(e));return[r,n-r.length]}const H=(e,t)=>{if(!Array.isArray(e))throw TypeError(`Param 'array' is not actually an array. Got type: ${typeof e}`);let r=1;if(t<=1){let n=e.length*t;r=Math.round(e.length/n)}else r=t;if(n(s(r,`positive`,`amount`)),r>e.length-1)throw Error(`Subsample steps exceeds array length`);let i=[];for(let t=r-1;t<e.length;t+=r)i.push(e[t]);return i},U=(e,t)=>[...e].sort((r,i)=>{n(a(e,`data`));let o=r[t],s=i[t];return o<s?-1:o>s?1:0}),W=(e,t,r)=>[...e].sort((i,o)=>{n(a(e,`data`));let s=i[t],c=o[t];return r===void 0?s<c?-1:s>c?1:0:r(s,c)});function G(e,t){if(!Number.isInteger(e))throw TypeError(`v parameter must be an integer (${e})`);let n=Array.isArray(t)?t.length:t;if(!Number.isInteger(n))throw TypeError(`length parameter must be an integer (${n}, ${typeof n})`);return e=Math.round(e),e<0?0:e>=n?n-1:e}function K(e,t,n,r,i=0){if(r===void 0)throw TypeError(`Param 'wrapLogic' is required.`);if(t>n)throw TypeError(`startIndex must be less than or equal to endIndex.`);if(e>=t&&e<=n)return{index:e,iterations:i};if(r===`brickwall`)return e<t?{index:t,iterations:i}:{index:n,iterations:i};if(r===`bounce`)return K(e<t?t-e+t:n-(e-n),t,n,`bounce`,i+1);if(r===`cycle`)return K(e<t?n-(t-e):t+(e-n),t,n,`cycle`,i+1);throw TypeError(`Invalid wrapLogic: ${r}`)}function ie(e,t,n=0,r=Math.random){if(n>t)throw Error(`minInclusive (${n}) cannot be greater than maxInclusive (${t})`);if(n===t)throw Error(`minInclusive (${n}) cannot be equal to maxInclusive (${t})`);return e<=0?n:e>1?t:r()<=e?ae(t,n,r):n}function ae(e,t=0,n=Math.random){return Math.floor(n()*(e-t+1))+t}function q(e,t,n){if(n.startIndex>n.endIndex)throw TypeError(`startIndex must be less than or equal to endIndex. startIndex: ${n.startIndex} endIndex: ${n.endIndex}`);if(n.startIndex===n.endIndex)throw TypeError(`startIndex cannot be the same as endIndex (${n.startIndex}).`);let r=e.incrementing,i=r?t.steps:-t.steps,a=e.index+i,o=!1,s=t.loop===`none`?`brickwall`:`bounce`;(t.debug??!1)&&console.log(`Step: index: ${e.index} incrementing: ${e.incrementing} delta: ${i} index after step: ${a} start: ${n.startIndex} end: ${n.endIndex} loop: ${t.loop}`);let c=K(a,n.startIndex,n.endIndex,s);return a=c.index,c.iterations>0&&c.iterations%2==1&&(r=!e.incrementing),t.loop===`none`&&(a===n.endIndex||a===n.startIndex)&&(o=!0),{index:a,incrementing:r,done:o}}function J(e,t){let n={steps:1,loop:`none`,repeatLoopedIndex:!1,debug:!1,forward:!0,randomDirectionFlip:0,randomChanceSteps:0,randomStepsMax:2,...e},r={startIndex:0,endIndex:t.data.length-1,randomSource:Math.random,...t};return function*(e={},i={}){let a={...n,...e},o=i.data??t.data;if(!Array.isArray(o))throw TypeError(`Param 'data' must be an array. Got: ${typeof o}`);if(o.length===0)return;if(o.length===1){yield 0;return}let s=G(i.startIndex??r.startIndex,o),c=G(i.endIndex??r.endIndex,o);if(s===c)throw Error(`startIndex and endIndex cannot be the same. startIndex: ${s} endIndex: ${c}. Data length: ${o.length} Override: ${JSON.stringify(i)}`);let l={startIndex:s,endIndex:c},u={index:a.forward?s:c,incrementing:a.forward,done:!1},d=NaN,f=a.debug??!1;for(;!u.done;){if(yield u.index,a.randomDirectionFlip>0&&r.randomSource()<a.randomDirectionFlip&&(u.incrementing=!u.incrementing),a.randomChanceSteps>0){let e=ie(a.randomChanceSteps,a.randomStepsMax,a.steps,r.randomSource);u=q(u,{...a,steps:e},l)}else u=q(u,a,l);f&&console.log(`index: ${u.index} state: ${JSON.stringify(u)}`),u.done&&u.index!==d&&(yield u.index),a.repeatLoopedIndex&&a.loop!==`none`&&(u.index===s||u.index===c)&&(yield u.index),d=u.index}}}function Y(e,t){let n=e.flat(10);return n.length<=1?n:(t??=d,typeof t(n[0],n[1])==`string`?oe(n,t):se(n,t))}const oe=(e,t)=>{let n=new Set,r=[];for(let i of e){let e=t(i);n.has(e)||(n.add(e),r.push(i))}return r},se=(e,t)=>{let n=[],r=e=>{for(let r of n)if(t(r,e))return!0;return!1};for(let t of e)r(t)||n.push(t);return n};function*X(e,t,n){let r=n;for(let n of e){let e=t(n,r);if(typeof e==`boolean`){if(e)break}else{let[t,n]=e;if(t)break;r=n}yield n}}function Z(e,t){let n=[];for(let r=0;r<t;r++){let{value:t,done:r}=e.next();if(r)break;n.push(t)}if(n.length>t)throw Error(`Bug: takeFromGenerator returned more items than requested.`);return n}const Q=e=>(n(a(e,`sourceArray`)),e.filter(e=>e!==void 0)),ce=(e,t,r=f)=>{if(n(a(e,`sourceArray`),o(r,`comparer`)),Array.isArray(t)){let n=[];for(let i of e)t.some(e=>r(i,e))||n.push(i);return n}else return e.filter(e=>!r(e,t))},$=(...e)=>{if(e.some(e=>!Array.isArray(e)))throw TypeError(`All parameters must be an array`);let t=e.map(e=>e.length);if(!x(t))throw Error(`Arrays must be of same length`);let n=[],r=t[0];for(let t=0;t<r;t++)n.push(e.map(e=>e[t]));return n};var le=e({FrequencyByGroup:()=>k,arrayIndexStepper:()=>J,atWrap:()=>c,chunks:()=>l,compareTo:()=>u,contains:()=>p,containsDuplicateInstances:()=>h,containsDuplicateValues:()=>m,containsIdenticalValues:()=>x,cycle:()=>g,ensureLength:()=>_,filterAB:()=>T,filterBetween:()=>E,filterWithIndex:()=>w,findIndex:()=>S,findIndexReverse:()=>C,flatten:()=>D,groupBy:()=>A,insertAt:()=>j,interleave:()=>M,intersection:()=>v,isEqual:()=>y,isEqualIgnoreOrder:()=>b,mapWithEmptyFallback:()=>O,mergeByKey:()=>N,movingWindow:()=>P,movingWindowWithContext:()=>F,pairwise:()=>re,pairwiseReduce:()=>I,randomElement:()=>R,randomIndex:()=>z,remove:()=>B,removeByFilter:()=>V,sample:()=>H,shuffle:()=>L,sortByNumericProperty:()=>U,sortByProperty:()=>W,step:()=>q,takeFromGenerator:()=>Z,unique:()=>Y,until:()=>X,without:()=>ce,withoutUndefined:()=>Q,zip:()=>$});export{E as A,p as B,M as C,O as D,k as E,y as F,c as G,m as H,b as I,v as L,S as M,C as N,D as O,x as P,_ as R,N as S,A as T,u as U,h as V,l as W,L as _,Z as a,P as b,J as c,W as d,H as f,z as g,R as h,Q as i,w as j,T as k,q as l,V as m,$ as n,X as o,B as p,ce as r,Y as s,le as t,U as u,re as v,j as w,F as x,I as y,g as z};