@jrc03c/make-key 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1 @@
1
- (()=>{function f(e){return typeof e=="number"&&!isNaN(e)||typeof e=="bigint"}var gt=new Function(`
2
- try {
3
- return this === window
4
- } catch(e) {}
5
-
6
- try {
7
- return !!importScripts
8
- } catch(e){}
9
-
10
- return false
11
- `);var R=class extends Error{constructor(t){gt()?super(t):super(`
12
-
13
- \x1B[31m`+t+`
14
- \x1B[0m`)}};function s(e,t){if(!e)throw new R(t)}var yt=[Array,ArrayBuffer,BigInt64Array,BigUint64Array,Float32Array,Float64Array,Int16Array,Int32Array,Int8Array,Uint16Array,Uint32Array,Uint8Array,Uint8ClampedArray];function h(e){return e===null||typeof e>"u"}var Oe=yt.map(e=>e.name);function l(e){try{return e instanceof Array?!0:h(e.constructor)?!1:yt.indexOf(e.constructor)>-1||Oe.indexOf(e.constructor.name)>-1}catch{return!1}}function y(e){try{return!!e._symbol&&e._symbol===Symbol.for("@jrc03c/js-math-tools/dataframe")}catch{return!1}}function O(e){return typeof e=="function"}function C(e){return typeof e=="object"&&!h(e)&&!l(e)}function g(e){try{return!!e._symbol&&e._symbol===Symbol.for("@jrc03c/js-math-tools/series")}catch{return!1}}function V(e,t){if(y(e)){let i=V(e.values,t);return i.length>0&&f(i[0])&&i[0]>=0&&i[0]<e.index.length&&(i[0]=e.index[i[0]]),i.length>1&&f(i[1])&&i[1]>=0&&i[1]<e.columns.length&&(i[1]=e.columns[i[1]]),i}if(g(e)){let i=V(e.values,t);return i.length>0&&f(i[0])&&i[0]>=0&&i[0]<e.index.length&&(i[0]=e.index[i[0]]),i}if(s(C(e)||l(e),"You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `indexOf` function!"),!O(t)){let i=t;t=a=>a===i}function n(i,a,m){if(m=m||[],m.indexOf(i)>-1)return null;if(C(i)){m.push(i);let u=Object.keys(i).concat(Object.getOwnPropertySymbols(i));for(let p=0;p<u.length;p++){let c=u[p],d=i[c];if(a(d))return[c];let v=n(d,a,m);if(v&&v.length>0)return[c].concat(v)}}else if(l(i)){m.push(i);for(let u=0;u<i.length;u++){let p=i[u];if(a(p))return[u];let c=n(p,a,m);if(c&&c.length>0)return[u].concat(c)}}else if(a(i))return[];return null}function r(i){try{return t(i)}catch{return!1}}let o=n(e,r);return o&&o.length>0?o:null}function _(e){function t(n){if(typeof n=="object"){if(n===null)return null;if(l(n))return n instanceof Array?n.map(o=>_(o)):n.slice();if(g(n)){let o=n.copy();return o.values=_(o.values),o}if(y(n)){let o=n.copy();return o.values=_(n.values),o}if(n instanceof Date)return new Date(n.getTime());n=L(n);let r={};return Object.keys(n).concat(Object.getOwnPropertySymbols(n)).forEach(o=>{r[o]=_(n[o])}),r}else return n}return t(L(e))}function L(e){function t(o,i,a){if(i=i||[],a=a||"",i.indexOf(o)>-1){let m=a.split("/").slice(a.startsWith("/")?1:0);if(m.some((p,c)=>{let d=m.slice(0,m.length-c-1),v=n;return d.forEach(D=>{v=v[D]}),v===o}))return`<reference to "${n===o?"/":"/"+V(n,o).join("/")}">`}return typeof o=="object"?o===null?null:(i.push(o),l(o)?typeof o.constructor<"u"&&o.constructor.name!=="Array"?o.slice():o.map((m,u)=>t(m,i,a+"/"+u)):(Object.keys(o).concat(Object.getOwnPropertySymbols(o)).forEach(m=>{o[m]=t(o[m],i,a+"/"+m.toString())}),o)):o}let n=e,r=t(n);if(y(e)){let o=e.copy();o._values=r.values,o._columns=r.columns,o._index=r.index,r=o}if(g(e)){let o=e.copy();o.name=r.name,o._values=r.values,o._index=r.index,r=o}return r}function G(e){return e instanceof Date&&e.toString()!=="Invalid Date"}var _t=["number","int","float","bigint"];function P(e,t){function n(r,o){let i=typeof r,a=typeof o;if(i!==a&&!_t.includes(i)&&!_t.includes(a))return!1;if(i==="undefined"&&a==="undefined")return!0;if(i==="boolean"||i==="symbol")return r===o;if(i==="number"||i==="bigint")try{let m=r.toString(),u=o.toString();return m===u}catch{return!1}if(i==="string"||i==="function")return r===o;if(i==="object"){if(r===null||o===null)return r===null&&o===null;{if(G(r))return G(o)?r.getTime()===o.getTime():!1;if(G(o))return!1;if(r instanceof RegExp&&o instanceof RegExp)return r.toString()===o.toString();if(l(r)!==l(o))return!1;let m=Object.keys(r).concat(Object.getOwnPropertySymbols(r)),u=Object.keys(o).concat(Object.getOwnPropertySymbols(o));if(m.length!==u.length)return!1;for(let p=0;p<m.length;p++){let c=m[p];if(!n(r[c],o[c]))return!1}return!0}}}try{return n(e,t)}catch{return n(L(e),L(t))}}function rt(e){let t="abcdefg1234567890",n="";for(;n.length<e;)n+=t[Math.floor(Math.random()*t.length)];return n}var Te=rt(16),De=rt(16),_e=rt(16),Ie=rt(16),xe=rt(16),at=class{constructor(){this.clear()}get counts(){return this.values.map(t=>this.get(t))}get values(){return Object.values(this.valuesDict)}clear(){return this.countsDict={},this.valuesDict={},this}count(t){for(let n of t)l(n)?this.count(n):this.increment(n);return this}delete(t){let n=this.getStandardizedKey(t);return delete this.countsDict[n],delete this.valuesDict[n],this}get(t){return this.countsDict[this.getStandardizedKey(t)]||0}getStandardizedKey(t){return typeof t=="object"&&t===null?Te:h(t)?De:O(t)?t.toString():typeof t=="symbol"?t.toString()+" - "+xe:t===1/0?_e:t===-1/0?Ie:typeof t=="bigint"?t.toString():y(t)?t.toJSONString():g(t)?JSON.stringify(t.toObject()):JSON.stringify(t)}has(t){return!h(this.countsDict[this.getStandardizedKey(t)])}increment(t){return this.set(t,this.get(t)+1)}set(t,n){let r=this.getStandardizedKey(t);return this.countsDict[r]=n,this.valuesDict[r]=t,this}toArray(){return this.values.map(t=>({value:t,count:this.get(t)}))}toObject(){let t={};return this.values.forEach(n=>{t[n]=this.get(n)}),t}};function I(e){if(y(e)||g(e))return I(e.values);s(l(e),"The `flatten` function only works on arrays, Series, and DataFrames!");function t(n){let r=[];return n.forEach(o=>{l(o)?r=r.concat(t(o)):r.push(o)}),r}return t(e)}function j(e,t){t=t||{};let n=new at,r={},o=I(e),i=[],a=-1/0,m=1/0,u=!1,p=0;for(let d of o){if(typeof d=="bigint"&&(u=!0),!t.shouldDropNaNs||f(d))try{d>a&&(a=d),d<m&&(m=d),p+=Number(d),i.push(d)}catch{a=NaN,m=NaN,p=NaN}n.increment(d)}let c=p/i.length;if(r.counts=n,r.max=a,r.mean=c,r.min=m,r.n=o.length,r.sum=p,isNaN(r.mean)&&(r.max=NaN,r.min=NaN),t.shouldDropNaNs&&(r.nWithoutNaNs=i.length),t.mode){let d=Array.from(n.values.map(F=>[F,n.get(F)])).toSorted((F,st)=>st[1]-F[1]),v=d[0][1],D=[];for(let F of d)if(F[1]==v)D.push(F[0]);else break;r.mode=D.toSorted()}if(t.median)if(isNaN(c))r.median=NaN;else{let d=i.toSorted((D,F)=>Number(D)-Number(F)),v=Math.floor(d.length/2);if(d.length%2===0){let D=d[v-1],F=d[v];if(r.median=(Number(D)+Number(F))/2,u&&typeof D=="bigint"&&typeof F=="bigint")try{r.median=BigInt(r.median)}catch{}}else r.median=d[v]}if(t.stdev||t.variance){let d=0;for(let D of i)d+=Math.pow(Number(D)-c,2);d/=i.length;let v=Math.sqrt(d);r.stdev=v,r.variance=d}if(u){try{r.sum=BigInt(r.sum)}catch{}try{r.mean=BigInt(r.mean)}catch{}t.mode&&(r.mode=r.mode.map(d=>{try{return BigInt(d)}catch{return d}}))}return r}function nt(e,t){let{counts:n}=j(e);return h(t)||(O(t)?n.values.forEach(r=>{t(r)||n.delete(r)}):n.values.forEach(r=>{P(r,t)||n.delete(r)})),n}function bt(e){if(y(e)||g(e))return bt(e.values);if(l(e)){let t=!1,n=!1,r=null;for(let o of e){if(bt(o))return!0;if(l(o)){if(r===null)r=o.length;else if(o.length!==r)return!0;t=!0}else n=!0;if(t&&n)return!0}}return!1}function q(e){return bt(L(e))}function H(e){if(y(e)||g(e))return H(e.values);s(l(e),"The `isNested` function only works on arrays, Series, and DataFrames!");for(let t=0;t<e.length;t++)if(l(e[t]))return!0;return!1}var X="You must pass a natural number or a one-dimensional array of natural numbers into the `ndarray` function!";function A(e){s(!h(e),X),l(e)||(e=[e]),s(!H(e),X),s(e.length>0,X);let t=e[0];if(typeof t=="bigint"&&(t=Number(t)),s(f(t),X),s(t>=0,X),s(Math.floor(t)===t,X),s(t!==1/0,"We can't create an array containing an infinite number of values!"),e.length===1){let n=[];for(let r=0;r<t;r++)n.push(void 0);return n}else{let n=[];for(let r=0;r<t;r++)n.push(A(e.slice(1)));return n}}function B(e){if(y(e)||g(e)){let n=e.copy();return n.values=B(n.values),n.index=B(n.index),n}s(l(e),"The `reverse` function only works on arrays, Series, and DataFrames!");let t=[];for(let n=e.length-1;n>=0;n--)t.push(e[n]);return t}function S(e,t,n=1){s(!h(e)&&!h(t)&&!h(n),"You must pass two numbers and optionally a step value to the `range` function!"),s(f(e)&&f(t)&&f(n),"You must pass two numbers and optionally a step value to the `range` function!"),s(n>0,"The step value must be greater than 0! (NOTE: The step value is a magnitude; it does not indicate direction.)");let r=!1,o=typeof e=="bigint"||typeof t=="bigint"||typeof n=="bigint";if(e=Number(e),t=Number(t),n=Number(n),e>t){r=!0;let a=e;e=t+n,t=a+n}let i=[];for(let a=e;a<t;a+=n)if(o)try{i.push(BigInt(a))}catch{i.push(a)}else i.push(a);return r&&(i=B(i)),i}function ot(e){let t="abcdefg1234567890",n="";for(;n.length<e;)n+=t[Math.floor(Math.random()*t.length)];return n}var Fe=ot(256),Ae=ot(256),je=ot(256),Ee=ot(256),Me=ot(256);function U(e){if(y(e)||g(e))return U(e.values);s(l(e),"The `set` function only works on arrays, Series, and DataFrames!");let t=[],n={};return I(e).forEach(r=>{let o=typeof r=="object"&&r===null?Fe:h(r)?Ae:O(r)?r.toString():typeof r=="symbol"?r.toString()+" - "+Me:r===1/0?je:r===-1/0?Ee:typeof r=="bigint"?r.toString():y(r)?r.toJSONString():g(r)?JSON.stringify(r.toObject()):JSON.stringify(r);n[o]||t.push(r),n[o]=!0}),t}function It(e){if(l(e)){let t=It(e[0]);return[e.length].concat(t||[])}else return}function b(e){return y(e)||g(e)?b(e.values):(s(l(e),"The `shape` function only works on arrays, Series, and DataFrames!"),It(e))}function Nt(e,t,n){if(h(n)&&(n=0),s(n===0||n===1||n==="vertical"||n==="horizontal",'The only valid axis values for use when appending data to a DataFrame are 0, 1, "vertical", and "horizontal". Note that 0 == "horizontal" and 1 == "vertical".'),l(t)){s(!q(t),"The array of data you're trying to append to this DataFrame is jagged!");let r=b(t);if(r.length===1)if(n===0){let o=e.copy();o._values.push(t);let i=Math.max(e.shape[1],r[0]);for(o._values.forEach(a=>{for(;a.length<i;)a.push(void 0)});o._index.length<o._values.length;)o._index.push("row"+o._index.length);for(;o._columns.length<i;)o._columns.push("col"+o._columns.length);return o}else{let o=Math.max(e.shape[0],r[0]),i=e.copy();for(S(0,o).forEach(a=>{a>=i._values.length&&i._values.push(A(e.shape[1])),i._values[a].push(t[a])});i._index.length<i._values.length;)i._index.push("row"+i._index.length);for(;i._columns.length<i._values[0].length;)i._columns.push("col"+i._columns.length);return i}else if(r.length===2)if(n===0){let o=Math.max(...t.map(a=>a.length).concat([e.shape[1]])),i=e.copy();for(i._values=i._values.concat(t).map(a=>{for(;a.length<o;)a.push(void 0);return a});i._index.length<i._values.length;)i._index.push("row"+i._index.length);for(;i._columns.length<o;)i._columns.push("col"+i._columns.length);return i}else{let o=Math.max(...t.map(m=>m.length))+e.shape[1],i=Math.max(e.shape[0],r[0]),a=e.copy();for(S(0,i).forEach(m=>{for(m>=a._values.length&&a._values.push(A(e.shape[1])),a._values[m]=a._values[m].concat(t[m]);a._values[m].length<o;)a._values[m].push(void 0)});a._index.length<a._values.length;)a._index.push("row"+a._index.length);for(;a._columns.length<o;)a._columns.push("col"+a._columns.length);return a}else throw new R("Only 1- and 2-dimensional arrays can be appended to a DataFrame!")}else if(g(t)){let r=Nt(e,t.values,n);return n===0?r.index[r.index.length-1]=r.index.indexOf(t.name)>-1?t.name+" (2)":t.name:r.columns[r.columns.length-1]=r.columns.indexOf(t.name)>-1?t.name+" (2)":t.name,r}else if(y(t))if(n===0){let r=e.copy(),o=U(r._columns.concat(t._columns)).length;for(r._values.forEach(i=>{for(;i.length<o;)i.push(void 0)}),t.apply(i=>{let a=i.copy(),m=[];r._columns.forEach(u=>{let p=a._index.indexOf(u);p>-1?(m.push(a._values[p]),a._values.splice(p,1),a._index.splice(p,1)):m.push(void 0)}),r._values.push(m.concat(a._values))},1),r._columns=r._columns.concat(t._columns.filter(i=>r._columns.indexOf(i)<0));r._index.length<r._values.length;){let i="row"+r._index.length;r._index.push(i+(e._index.indexOf(i)>-1?" (2)":""))}return r}else{let r=e.copy();return r._index.forEach((o,i)=>{let a=t._index.indexOf(o);a>-1?r._values[i]=r._values[i].concat(t._values[a]):r._values[i]=r._values[i].concat(A(t.shape[1]))}),t._index.forEach((o,i)=>{r._index.indexOf(o)<0&&(r._index.push(o),r._values.push(A(r._columns.length).concat(t._values[i])))}),r._columns=r._columns.concat(t._columns.map(o=>o+(r._columns.indexOf(o)>-1?" (2)":""))),r}else throw new R("Only 1- or 2-dimensional arrays, Series, and DataFrames can be appended to a DataFrame!")}function xt(e,t,n,r,o){if(o=o||0,s(O(r),"The first parameter to the `apply` method must be a function."),s(o===0||o===1,"The second parameter to the `apply` method (the `axis`) must be 0 or 1."),o===0){let i={},a;if(n.columns.forEach((m,u)=>{let p=new t(n.values.map(d=>d[u]));p.name=m,p.index=n.index;let c=r(p,u,n);c instanceof t?i[m]=c.values:i[m]=c,h(a)&&(a=c instanceof t||l(c))}),a){let m=new e(i);return m.index=n.index,m}else{let m=new t(n.columns.map(u=>i[u]));return m.index=n.columns,m}}else if(o===1){let i,a=n.values.map((m,u)=>{let p=new t(m);p.name=n.index[u],p.index=n.columns;let c=r(p,u,n);return h(i)&&(i=c instanceof t||l(c)),c instanceof t?c.values:c});if(i){let m=new e(a);return m.index=n.index,m.columns=n.columns,m}else{let m=new t(a);return m.index=n.index,m}}}function w(e){return typeof e=="string"}function Ft(e,t,n,r,o){let i=m=>m instanceof e,a=m=>m instanceof t;if(h(o)){if(i(r))return n.append(r,1);if(a(r))return n.append(r,1);if(C(r)){let m=Math.max(...Object.keys(r).concat(Object.getOwnPropertySymbols(r)).map(u=>r[u].length));return Object.keys(r).concat(Object.getOwnPropertySymbols(r)).forEach(u=>{for(;r[u].length<m;)r[u].push(void 0)}),n.append(new e(r),1)}else throw new R("You must pass a DataFrame, Series, or object into the `assign` method!")}else{s(w(r),"If passing two arguments into the `assign` method, then the first argument must be a string name!"),s(l(o)&&!q(o)&&b(o).length===1,"If passing two arguments into the `assign` method, then the second argument must be a 1-dimensional array!");let m=n.append(o,1);return m.columns[m.columns.length-1]=r,m}}function At(e,t){if(t.isEmpty)return new e;let n=new e(_(t.values));return n.columns=t.columns.slice(),n.index=t.index.slice(),n}function jt(e,t,n,r,o){h(r)&&(r=[]),h(o)&&(o=[]),(w(r)||f(r))&&(r=[r]),(w(o)||f(o))&&(o=[o]),s(l(r),"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."),s(l(o),"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."),s(b(r).length===1,"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."),s(b(o).length===1,"The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings.");let i,a;n.index.forEach((u,p)=>{r.indexOf(u)<0&&r.indexOf(p)<0&&(i||(i=[]),i.push(u))}),n.columns.forEach((u,p)=>{o.indexOf(u)<0&&o.indexOf(p)<0&&(a||(a=[]),a.push(u))});let m=n.get(i,a);if(m instanceof t){let u=new e;u=u.assign(m),n.index.indexOf(m.name)>-1&&(u=u.transpose()),m=u}return m}function mt(e){return f(e)&&(e>=0?Math.floor(e)===e:Math.ceil(e)===e)}function k(e){return mt(e)&&e>=0}function Et(e,t,n,r,o,i){r=r||0,s(r===0||r===1,"The first parameter of the `dropMissing` method (the `axis`) must be 0 or 1."),i=i||0,s(k(i),"The third parameter of the `dropMissing` method (the `threshold`) should be a whole number (meaning that data should be dropped if it contains more than `threshold` null values)."),o=i>0?"none":o||"any",s(o==="any"||o==="all"||o==="none","The second parameter of the `dropMissing` method (the `condition` parameter, which indicates the condition under which data should be dropped) should be 'any' or 'all' (meaning that if 'any' of the data contains null values, then it should be dropped; or that if 'all' of the data contains null values, then it should be dropped).");function a(p){if(i>0){let c=0;for(let d=0;d<p.length;d++){let v=p[d];if(h(v)&&c++,c>=i)return[]}}else if(o==="any")for(let c=0;c<p.length;c++){let d=p[c];if(h(d))return[]}else if(o==="all"){for(let c=0;c<p.length;c++){let d=p[c];if(!h(d))return p}return[]}return p}let m=n.copy(),u=Math.random().toString();if(r===0){m=m.assign(u,m.index);let p=m.values.map(a).filter(d=>d.length>0);if(b(p).length<2)return new e;m.values=p;let c=m.get(null,u);if(h(c))return new e;w(c)&&(c=[c]),c instanceof t&&(c=c.values),m.index=c,m=m.drop(null,u)}else if(r===1){let p={};if(m.columns.forEach((d,v)=>{let D=m.values.map(st=>st[v]),F=a(D);F.length>0&&(p[d]=F)}),Object.keys(p).length+Object.getOwnPropertySymbols(p).length===0)return new e;let c=new e(p);return c.index=m.index,c}return m}function ut(e){if(y(e)||g(e))return e.dropNaN(...Object.values(arguments).slice(1));s(l(e),"The `dropNaN` function only works on arrays, Series, and DataFrames!");let t=[];return e.forEach(n=>{try{return t.push(ut(n))}catch{if(f(n))return t.push(n)}}),t}function Mt(e,t,n,r,o){n=n||0,s(n===0||n===1,"The first parameter of the `dropNaN` method (the `axis`) must be 0 or 1."),o=o||0,s(k(o),"The third parameter of the `dropNaN` method (the `threshold`) should be a whole number (meaning that data should be dropped if it contains more than `threshold` NaN values)."),r=o>0?"none":r||"any",s(r==="any"||r==="all"||r==="none","The second parameter of the `dropNaN` method (the `condition` parameter, which indicates the condition under which data should be dropped) should be 'any' or 'all' (meaning that if 'any' of the data contains NaN values, then it should be dropped; or that if 'all' of the data contains NaN values, then it should be dropped).");function i(m){let u=ut(m);return o>0?m.length-u.length<o:r==="any"?u.length===m.length:r==="all"?u.length>0:!0}let a=t.copy();if(n===0){let m=a.index.filter(u=>{let p=a.get(u,null).values;return i(p)});return m.length>0?a.get(m,null):new e}else if(n===1){let m=a.columns.filter(u=>{let p=a.get(null,u).values;return i(p)});return m.length>0?a.get(null,m):new e}return a}function Bt(e){let t={};return I(e).forEach((n,r)=>{t[n]=r}),t}function Q(e){return Object.keys(e).concat(Object.getOwnPropertySymbols(e)).sort((t,n)=>e[t]-e[n])}function Ut(e,t,n,r,o){s(O(r),"The `filter` method takes a single parameter: a function that is used to filter the values."),h(o)&&(o=0),s(o===0||o===1,"The `axis` parameter to the `filter` method must be 0 or 1.");let i=n.copy();if(i.isEmpty)return i;let a=Bt(i.index),m=Bt(i.columns);if(o===0){let u=0,p=i.values.filter((c,d)=>{let v=new t(c);v.name=n.index[d],v.index=n.columns;let D=r(v,d,n);return D?u++:delete a[i.index[d]],D});if(u===0)return new e;if(u===1){let c=new t(p[0]);return c.name=Q(a)[0],c.index=Q(m),c}i.values=p,i.index=Q(a)}else if(o===1){i=i.transpose();let u=0,p=i.values.filter((c,d)=>{let v=new t(c);v.name=n.columns[d],v.index=n.index;let D=r(v,d,n);return D?u++:delete m[i.index[d]],D});if(u===0)return new e;if(u===1){let c=new t(p[0]);return c.name=Q(m)[0],c.index=Q(a),c}i.values=p,i.index=Q(m),i=i.transpose()}return i}function Pt(e,t,n){(w(t)||f(t))&&(t=[t]),(w(n)||f(n))&&(n=[n]);for(let o in t)typeof t[o]=="bigint"&&(t[o]=Number(t[o]));for(let o in n)typeof n[o]=="bigint"&&(n[o]=Number(n[o]));let r=U((t||[]).concat(n||[]).map(o=>typeof o));return s(r.length<=2,"Only whole numbers and/or strings are allowed in `get` arrays!"),r.length===1&&s(r[0]==="string"||r[0]==="number","Only whole numbers and/or strings are allowed in `get` arrays!"),r.length===2&&(s(r.indexOf("string")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!"),s(r.indexOf("number")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!")),h(t)||(t=t.map(o=>{if(w(o))return s(e.index.indexOf(o)>-1,`Row "${o}" does not exist!`),o;if(f(o))return s(o>=0,`Index ${o} is out of bounds!`),s(Math.floor(o)===o,"Row numbers must be integers!"),s(o<e.index.length,`Index ${o} is out of bounds!`),e.index[o]})),h(n)||(n=n.map(o=>{if(w(o))return s(e.columns.indexOf(o)>-1,`Column "${o}" does not exist!`),o;if(f(o))return s(o>=0,`Column ${o} is out of bounds!`),s(Math.floor(o)===o,"Column numbers must be integers!"),s(o<e.columns.length,`Column ${o} is out of bounds!`),e.columns[o]})),e.getSubsetByNames(t,n)}function Be(e,t){try{return e<t?-1:e>t?1:0}catch{return e=typeof e=="object"&&e!==null?JSON.stringify(e):e.toString(),t=typeof t=="object"&&t!==null?JSON.stringify(t):t.toString(),e<t?-1:e>t?1:0}}function J(e,t){if(h(t)&&(t=Be),y(e)||g(e))return e.sort(...Object.values(arguments).slice(1));s(l(e),"The `sort` function only works on arrays, Series, and DataFrames!"),s(O(t),"The second parameter of the `sort` function must be a comparison function!");let n=e.slice();return n.sort(t),n}function Ue(e){let t=e.toLowerCase(),n="";for(let o=0;o<t.length;o++){let i=t[o];i.match(/[a-z0-9]/g)?n+=i:n+=" "}let r=n.split(" ").filter(o=>o.length>0);return r[0]+r.slice(1).map(o=>o[0].toUpperCase()+o.substring(1)).join("")}function vt(e,t,n){h(n)?n=t.columns:w(n)&&(n=[n]);let r={};n.forEach(i=>{s(w(i),"You must pass either a string or a one-dimensional array of strings into the `getDummies` (AKA `oneHotEncode`) method!");let a=t.columns.indexOf(i);s(a>-1,`The given DataFrame does not have a column called "${i}"!`);let m=t.values.map(p=>p[a]),u=J(U(m));m.forEach(p=>{u.forEach(c=>{let d=i+"_"+Ue(c.toString());r[d]||(r[d]=[]),p===c?r[d].push(1):r[d].push(0)})})});let o=new e(r);return o.index=t.index,o}function zt(e,t,n){let r=e.shape;h(t)&&(t=S(0,r[0])),h(n)&&(n=S(0,r[1])),f(t)&&(t=[t]),f(n)&&(n=[n]),s(l(t)&&l(n),"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),s(b(t).length===1&&b(n).length===1,"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),s(t.length>0,"The `rowIndices` array must contain at least one index."),s(n.length>0,"The `colIndices` array must contain at least one index."),t.forEach(a=>{s(k(a),"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),s(a<e.index.length,`The row index ${a} is out of bounds.`)}),n.forEach(a=>{s(k(a),"The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."),s(a<e.columns.length,`The column index ${a} is out of bounds.`)});let o=t.map(a=>e.index[a]),i=n.map(a=>e.columns[a]);return e.getSubsetByNames(o,i)}function Ct(e,t,n,r,o){h(r)&&(r=n.index),h(o)&&(o=n.columns),w(r)&&(r=[r]),w(o)&&(o=[o]),s(l(r)&&l(o),"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),s(b(r).length===1&&b(o).length===1,"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),s(r.length>0,"The `rows` array must contain at least one row name."),s(o.length>0,"The `cols` array must contain at least one column name."),r.forEach(m=>{s(w(m),"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),s(n.index.indexOf(m)>-1,`The row name "${m}" does not exist in the list of rows.`)}),o.forEach(m=>{s(w(m),"The `rows` and `cols` parameters must be 1-dimensional arrays of strings."),s(n.columns.indexOf(m)>-1,`The column name "${m}" does not exist in the list of columns.`)});let i=r.map(m=>o.map(u=>n.values[n.index.indexOf(m)][n.columns.indexOf(u)]));if(r.length===1&&o.length===1)return i[0][0];if(r.length===1){let m=new t(i[0]);return m.name=r[0],m.index=o,m}if(o.length===1){let m=new t(i.map(u=>u[0]));return m.name=o[0],m.index=r,m}let a=new e(i);return a.columns=o,a.index=r,a}function kt(e,t,n){function r(v,D){return w(v)&&v.length>D?v.substring(0,D-3)+"...":v}if(n.isEmpty)return console.table({}),console.log("Shape:",[0,0],`
15
- `),n;let o=typeof window>"u"?20:10,i=Math.floor(o/2),a=4,m=Math.floor(a/2),u=o>n.index.length?null:S(0,i).concat(S(n.index.length-i,n.index.length)),p=a>n.columns.length?null:S(0,m).concat(S(n.columns.length-m,n.columns.length)),c=n.get(u,p);c instanceof t&&(n.shape[0]===1?(c=new e([c.values]),c.index=n.index,c.columns=new t(n.columns).get(p).values):n.shape[1]===1&&(c=new e([c.values]).transpose(),c.index=new t(n.index).get(u).values,c.columns=n.columns)),o<=n.index.length&&(c._index.splice(i,0,"..."),c._values.splice(i,0,S(0,c.columns.length).map(()=>"..."))),a<=n.columns.length&&(c._columns.splice(m,0,"..."),c._values=c._values.map(v=>(v.splice(m,0,"..."),v)));let d=28;return c instanceof t?(c.values=c.values.map(v=>r(v,d)),c.name=r(c.name,d),c.index=c.index.map(v=>r(v,d))):(c.values=c.values.map(v=>v.map(D=>r(D,d))),c.columns=c.columns.map(v=>r(v,d)),c.index=c.index.map(v=>r(v,d))),console.table(c.toDetailedObject()),console.log("Shape:",n.shape,`
16
- `),n}function $(e,t){s(f(e),"The `leftPad` function only works on numbers!");let n=e.toString();for(;n.length<t;)n="0"+n;return n}function Jt(e,t){let n=t?e:e.copy();return n.index=S(0,e.shape[0]).map(r=>"row"+$(r,(n.index.length-1).toString().length)),n}function W(e,t){if(y(e)||g(e))return W(e.values,t);s(l(e),"The `product` function only works on arrays, Series, and DataFrames!");try{if(e.length===0)return NaN;let n=I(e),r=!1,o=1;for(let i of n){if(!f(i))if(t)i=1;else return NaN;typeof i=="bigint"&&(r=!0,i=Number(i)),o*=i}if(r)try{return BigInt(o)}catch{}return o}catch{return NaN}}function Rt(e){return mt(e)&&e>0}function Z(e,t){if(y(e)||g(e))return Z(e.values,t);if(s(l(e),"The first argument passed into the `reshape` function must be an array!"),f(t)&&(t=[t]),s(l(t),"The second argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"),s(b(t).length===1,"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"),t=t.map(i=>(typeof i=="bigint"&&(i=Number(i)),s(Rt(i),"The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"),Number(i))),t.length===0)return I(e);let n=I(e);if(t.length===1&&t[0]===n.length)return n;s(W(t)===n.length,"The new shape doesn't match the number of values available in `x` (the first argument passed into the `reshape` function)!");let r=[],o=Math.floor(n.length/t[0]);for(let i=0;i<t[0];i++){let a=n.slice(i*o,(i+1)*o);r.push(Z(a,t.slice(1)))}return r}var $t=Math.pow(2,64),T=[];ft(Math.floor(Math.random()*$t));function Pe(e,t){e=x(e);function n(){e+=x("0x9e3779b97f4a7c15");let o=_(e);return o=(o^o>>BigInt(30))*x("0xbf58476d1ce4e5b9"),o=(o^o>>BigInt(27))*x("0x94d049bb133111eb"),o^o>>BigInt(31)}let r=[];for(let o=0;o<t;o++)r.push(n());return r}function x(e){return BigInt.asUintN(64,BigInt(e))}function Yt(e,t){return e=x(e),t=BigInt(t),x(x(e<<t)|x(e>>x(BigInt(64)-t)))}function ft(e){if(typeof e=="bigint"&&(e=Number(e)),h(e))return _(T);{s(f(e),"If passing a value into the `seed` function, then that value must be an integer!");let t=Pe(Math.floor(e),4);T[0]=t[0],T[1]=t[1],T[2]=t[2],T[3]=t[3]}}function Kt(){let e=x(Yt(T[0]+T[3],23)+T[0]),t=x(T[1]<<BigInt(17));return T[2]=x(T[2]^T[0]),T[3]=x(T[3]^T[1]),T[1]=x(T[1]^T[2]),T[0]=x(T[0]^T[3]),T[2]=x(T[2]^t),T[3]=Yt(T[3],45),Math.floor(Number(e))/$t}function Y(e){return h(e)?Kt():(l(e)||(e=[e]),Z(A(W(e)).map(Kt),e))}function tt(e){if(y(e)||g(e))return e.shuffle(...Object.values(arguments).slice(1));s(l(e),"The `shuffle` function only works on arrays, Series, and DataFrames!");let t=[],n=e.slice();for(let r=0;r<e.length;r++){let o=Math.floor(Y()*n.length);t.push(n.splice(o,1)[0])}return t}function Lt(e,t){return h(t)&&(t=0),s(t===0||t===1,"The `axis` parameter to the `shuffle` must be 0, 1, or undefined."),e.get(t===0?tt(e.index):null,t===1?tt(e.columns):null)}function et(e){return typeof e=="boolean"}function qt(e,t,n){return O(t)?ze(e,t,n):Ce(e,t,n)}function ze(e,t,n){if(n=h(n)?0:n,s(O(t),"When sorting a DataFrame using a function, the first argument to the `sort` method must be a function!"),s(f(n),"When sorting a DataFrame using a function, the second argument to the `sort` method must be null, undefined, 0, or 1 to indicate the axis along which the data should be sorted! An axis of 0 means that the rows will be sorted relative to each other, whereas an axis of 1 means that the columns will be sorted relative to each other."),n===0){let r=J(e.index,(o,i)=>t(e.get(o,null),e.get(i,null)));return e.get(r,null)}else{let r=J(e.columns,(o,i)=>t(e.get(null,o),e.get(null,i)));return e.get(null,r)}}function Ce(e,t,n){let r=e.copy(),o=Y().toString();r=r.assign(o,r.index),h(t)&&(t=[o],n=[!0]),(f(t)||w(t))&&(t=[t],(et(n)||w(n))&&(n=[n])),s(l(t),"The first parameter of the `sort` method must be (1) a string or index representing a column name or index, respectively; (2) a 1-dimensional array of strings and/or indices; or (3) null."),s(b(t).length===1,"The first parameter of the `sort` method must be (1) a string or index representing a column name or index, respectively; (2) a 1-dimensional array of strings and/or indices; or (3) null."),h(n)&&(n=S(0,t.length).map(()=>!0)),s(l(n),"The second parameter of the `sort` method must be (1) a string or boolean representing the sort direction ('ascending' / 'descending', or true / false); (2) a 1-dimensional array of strings and/or booleans; or (3) null."),s(b(n).length===1,"The second parameter of the `sort` method must be (1) a string or boolean representing the sort direction ('ascending' / 'descending', or true / false); (2) a 1-dimensional array of strings and/or booleans; or (3) null."),s(t.length===n.length,"The arrays passed into the `sort` method must be equal in length."),t=t.map(a=>{if(s(w(a)||f(a),"Column references can either be column names (as strings) or column indices (as whole numbers)."),w(a)){let m=r.columns.indexOf(a);return s(m>-1,`The column "${a}" does not exist!`),m}if(f(a))return s(k(a),"Column indices must be whole numbers!"),s(a<r.columns.length,`The index ${a} is out of bounds!`),a}),n=n.map(a=>{if(s(w(a)||et(a),"Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."),w(a)){let m=a.trim().toLowerCase();return s(m==="ascending"||m==="descending","Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."),m==="ascending"}if(et(a))return a}),r.values=J(r.values,(a,m)=>{let u=0;for(;a[t[u]]===m[t[u]]&&u<t.length;)u++;let p=n[u];if(a[t[u]]===m[t[u]])return 0;if(a[t[u]]<m[t[u]])return p?-1:1;if(a[t[u]]>m[t[u]])return p?1:-1});let i=r.columns.indexOf(o);return r.index=r.values.map(a=>a[i]),r=r.dropColumns(o),r}function Vt(e,t){h(t)?t=0:s(t===0||t===1,"The axis parameter of the `toDetailedObject` method must be undefined, 0, or 1. An axis of 0 indicates that the returned object should be organized first by rows and then by columns. An axis of 1 indicates that the returned object should be organized first by columns and then by rows.");let n={};return t===0?e.index.forEach((r,o)=>{let i={};e.columns.forEach((a,m)=>{i[a]=e.values[o][m]}),n[r]=i}):e.columns.forEach((r,o)=>{let i={};e.index.forEach((a,m)=>{i[a]=e.values[m][o]}),n[r]=i}),n}function lt(e,t){return JSON.stringify(e.toObject(t))}async function Gt(e,t){return JSON.parse(lt(e,t))}function Wt(e){let t={};return e.columns.forEach(n=>{t[n]=e.get(n).values}),t}function z(e){if(y(e)||g(e))return e.transpose();s(l(e),"The `transpose` function only works on arrays, Series, and DataFrames!");let t=b(e);if(s(t.length<=2,"I'm not smart enough to know how to transpose arrays that have more than 2 dimensions. Sorry for the inconvenience! Please only pass 1- or 2-dimensional arrays into the `transpose` function!"),t.length===1)return B(e);if(t.length===2){let n=A(B(t));for(let r=0;r<t[0];r++)for(let o=0;o<t[1];o++)n[o][r]=e[r][o];return n}}function wt(e,t,n){if(g(n))return new e(t.values.concat(n.values));if(l(n)){let r=b(n);s(r.length===1&&!H(r),"Only vectors can be appended to Series!");let o=t.copy();return n.forEach((i,a)=>{o._values.push(i),o._index.push("item"+(t.values.length+a))}),o}return wt(t,[n])}function Ht(e,t){s(O(t),"The parameter to the `apply` method must be a function.");let n=e.copy();return n._values=n._values.map((r,o)=>t(r,o)),n}function Xt(e){let t=e.copy(),n=[];return t._values=t.values.filter((r,o)=>h(r)?!1:(n.push(t.index[o]),!0)),t._index=n,t}function Qt(e,t){let n=[],r=[];t.values.forEach((i,a)=>{f(i)&&(r.push(i),n.push(t.index[a]))});let o=new e(r);return o.name=t.name,o.index=n,o}function Zt(e,t,n){let r=t.copy(),o=_(r.index),i=[],a=r.values.filter((m,u)=>{let p=n(m,u,r.values);return p||i.push(r.index[u]),p});return i.forEach(m=>{o.splice(o.indexOf(m),1)}),a.length===0?(r=new e,r.name=t.name,r):(r.values=a,r.index=o,r)}function te(e,t){(w(t)||f(t))&&(t=[t]);for(let r in t)typeof t[r]=="bigint"&&(t[r]=Number(t[r]));let n=U((t||[]).map(r=>typeof r));return s(n.length<=2,"Only whole numbers and/or strings are allowed in `get` arrays!"),n.length===1&&s(n[0]==="string"||n[0]==="number","Only whole numbers and/or strings are allowed in `get` arrays!"),n.length===2&&(s(n.indexOf("string")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!"),s(n.indexOf("number")>-1,"Only whole numbers and/or strings are allowed in `get` arrays!")),h(t)||(t=t.map(r=>{if(typeof r=="string")return s(e.index.indexOf(r)>-1,`Index "${r}" does not exist!`),r;if(typeof r=="number")return s(r>=0,`Index ${r} is out of bounds!`),s(Math.floor(r)===r,"Indices must be integers!"),s(r<e.index.length,`Index ${r} is out of bounds!`),e.index[r]})),e.getSubsetByNames(t)}function ee(e,t){let n=e.shape;h(t)&&(t=S(0,n[0])),s(l(t),"The `indices` array must be 1-dimensional array of whole numbers."),s(b(t).length===1,"The `indices` array must be a 1-dimensional array of whole numbers."),s(t.length>0,"The `indices` array must contain at least one index."),t.forEach(o=>{s(k(o),"The `indices` array must be a 1-dimensional array of whole numbers."),s(o<e.index.length,`The row index ${o} is out of bounds.`)});let r=t.map(o=>e.index[o]);return e.getSubsetByNames(r)}function re(e,t,n){h(n)&&(n=t.index),s(l(n),"The `indices` array must be a 1-dimensional array of strings."),s(b(n).length===1,"The `indices` array must be a 1-dimensional array of strings."),s(n.length>0,"The `indices` array must contain at least one index name."),n.forEach(i=>{s(w(i),"The `indices` array must contain only strings."),s(t.index.indexOf(i)>-1,`The name "${i}" does not exist in the index.`)});let r=n.map(i=>t.values[t.index.indexOf(i)]);if(r.length===1)return r[0];let o=new e(r);return o.index=n,o.name=t.name,o}function ne(e){let t=e.copy(),n=typeof window>"u"?20:10;if(t.index.length>n){t=t.get(S(0,n/2).concat(S(t.index.length-n/2,t.index.length)));let o=_(t.index);o.splice(Math.floor(o.length/2),0,"..."),t.values.push("..."),t.index.push("..."),t=t.get(o)}let r={};return t.values.forEach((o,i)=>{let a={};a[t.name]=o,r[t.index[i]]=a}),console.table(r),console.log("Shape:",e.shape,`
17
- `),e}function oe(e){let t=e.copy();return t.get(tt(t.index))}function ie(e,t,n){n=n||((u,p)=>u<p?-1:1),s(h(n)||O(n),"You must pass undefined, null, or a comparison function as the second argument to the `sort` method!");let r=z([t.values,t.index]),o=J(r,(u,p)=>n(u[0],p[0])),i=[],a=[];o.forEach(u=>{i.push(u[0]),a.push(u[1])});let m=new e;return m._values=i,m._index=a,m.name=t.name,m}function se(e,t){let n=z([t.values,t.index]);n=z(J(n,(o,i)=>{if(o[1]===i[1])return 0;if(o[1]<i[1])return-1;if(o[1]>i[1])return 1}));let r=new e(n[0]);return r.index=n[1],r.name=t.name,r}function ae(e){let t={};return t[e.name]={},e.index.forEach((n,r)=>{t[e.name][n]=e.values[r]}),t}var me=Symbol.for("@jrc03c/js-math-tools/series");function ue(e){class t{static[Symbol.hasInstance](r){try{return!!r._symbol&&r._symbol===me}catch{return!1}}constructor(r){if(this.name="data",Object.defineProperty(this,"_symbol",{configurable:!1,enumerable:!1,writable:!1,value:me}),Object.defineProperty(this,"_values",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"values",{configurable:!0,enumerable:!0,get(){return this._values},set(o){s(l(o),"The new values must be a 1-dimensional array!");let i=b(o);s(i.length===1,"The new array of values must be 1-dimensional!"),i[0]<this._index.length?this._index=this._index.slice(0,i[0]):i[0]>this._index.length&&(this._index=this._index.concat(S(this._index.length,i[0]).map(a=>"item"+$(a,(o.length-1).toString().length)))),this._values=o}}),Object.defineProperty(this,"_index",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"index",{configurable:!0,enumerable:!0,get(){return this._index},set(o){s(l(o),"The new index must be a 1-dimensional array of strings!"),s(o.length===this.shape[0],"The new index must be the same length as the old index!"),s(b(o).length===1,"The new index must be a 1-dimensional array of strings!"),o.forEach(i=>{s(w(i),"All of the row names must be strings!")}),this._index=o}}),r){if(r instanceof t)this.name=r.name,this.values=_(r.values),this.index=_(r.index);else if(l(r)){let o=b(r);s(o.length===1,"When passing an array into the constructor of a Series, the array must be 1-dimensional!"),this.values=r}else if(r instanceof Object){let o=Object.keys(r).concat(Object.getOwnPropertySymbols(r)).map(m=>m.toString());s(o.length===1,"When passing an object into the constructor of a Series, the object must have only 1 key-value pair, where the key is the name of the data and the value is the 1-dimensional array of values!");let i=o[0],a=r[i];s(b(a).length===1,"When passing an object into the constructor of a Series, the object must have only 1 key-value pair, where the key is the name of the data and the value is the 1-dimensional array of values!"),this.name=i,this.values=a.slice()}}}get shape(){return b(this.values)}get length(){return this.shape[0]}get isEmpty(){return this.values.filter(r=>!h(r)).length===0}clear(){let r=this.copy();return r.values.forEach((o,i)=>{r.values[i]=void 0}),r}get(r){return te(this,r)}getSubsetByNames(r){return re(t,this,r)}getSubsetByIndices(r){return ee(this,r)}loc(r){return this.getSubsetByNames(r)}iloc(r){return this.getSubsetByIndices(r)}reverse(){let r=new t(B(this.values));return r.index=B(this.index),r.name=this.name,r}resetIndex(){let r=this.copy();return r.index=S(0,this.shape[0]).map(o=>"item"+$(o,(r.index.length-1).toString().length)),r}copy(){let r=new t;return r._values=_(this.values),r._index=_(this.index),r.name=this.name,r}append(r){return wt(t,this,r)}apply(r){return Ht(this,r)}concat(r){return this.append(r)}dropMissing(r,o){return Xt(this,r,o)}dropNaN(){return Qt(t,this)}toObject(){return ae(this)}print(){return ne(this)}shuffle(){return oe(this)}sort(r){return ie(t,this,r)}sortByIndex(){return se(t,this)}filter(r){return Zt(t,this,r)}toDataFrame(){let r=new e(z([this.values]));return r.columns=[this.name],r.index=this.index,r}transpose(){let r=this.copy();return r.values=B(r.values),r.index=B(r.index),r}getDummies(){return this.toDataFrame().getDummies()}oneHotEncode(){return this.getDummies()}}return t}var fe=Symbol.for("@jrc03c/js-math-tools/dataframe");function pt(e){let t="abcdefghijklmnopqrstuvwxyz1234567890",n="";for(let r=0;r<e;r++)n+=t[Math.floor(Y()*t.length)];return n}var K=class e{static[Symbol.hasInstance](t){try{return!!t._symbol&&t._symbol===fe}catch{return!1}}constructor(t){if(Object.defineProperty(this,"_symbol",{configurable:!1,enumerable:!1,writable:!1,value:fe}),Object.defineProperty(this,"_values",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"values",{configurable:!0,enumerable:!0,get(){return this._values.length===0||!h(this._values[0])&&this._values[0].length===0?[[]]:this._values},set(n){s(l(n),"The new values must be a 2-dimensional array!");let r=b(n);s(r.length===2,"The new array of values must be 2-dimensional!"),r[0]<this._index.length?this._index=this._index.slice(0,r[0]):r[0]>this._index.length&&(this._index=this._index.concat(S(this._index.length,r[0]).map(o=>"row"+$(o,(r[0]-1).toString().length)))),r[1]<this._columns.length?this._columns=this._columns.slice(0,r[1]):r[1]>this._columns.length&&(this._columns=this._columns.concat(S(this._columns.length,r[1]).map(o=>"col"+$(o,(r[1]-1).toString().length)))),this._values=n}}),Object.defineProperty(this,"_columns",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"columns",{configurable:!0,enumerable:!0,get(){return this._columns},set(n){s(l(n),"The new columns list must be a 1-dimensional array of strings!"),s(this.isEmpty||n.length===this.shape[1],"The new columns list must be the same length as the old columns list!"),s(b(n).length===1,"The new columns list must be a 1-dimensional array of strings!"),n=n.map(o=>(typeof o!="string"&&(o=JSON.stringify(o)||o.toString()),o.trim().length===0?"untitled_"+pt(8):o.trim()));let r=(()=>{let o=nt(n),i={};return o.values.forEach(a=>{i[a]=o.get(a)}),i})();n=n.map(o=>r[o]>1?o+"_"+pt(8):o),this._columns=n}}),Object.defineProperty(this,"_index",{value:[],configurable:!0,enumerable:!1,writable:!0}),Object.defineProperty(this,"index",{configurable:!0,enumerable:!0,get(){return this._index},set(n){s(l(n),"The new index must be a 1-dimensional array of strings!"),s(this.isEmpty||n.length===this.shape[0],"The new index must be the same length as the old index!"),s(b(n).length===1,"The new index must be a 1-dimensional array of strings!"),n=n.map(o=>(typeof o!="string"&&(o=JSON.stringify(o)||o.toString()),o.trim().length===0?"untitled_"+pt(8):o.trim()));let r=(()=>{let o=nt(n),i={};return o.values.forEach(a=>{i[a]=o.get(a)}),i})();n=n.map(o=>r[o]>1?o+"_"+pt(8):o),this._index=n}}),s(h(t)||C(t)||l(t),"The `data` passed into the constructor of a DataFrame must be either (1) an object where the key-value pairs are (respectively) column names and 1-dimensional arrays of values, or (2) a 2-dimensional array of values."),t)if(t instanceof e)this.values=_(t.values),this.columns=_(t.columns),this.index=_(t.index);else if(l(t)){let n=b(t);s(n.length===2,"The `data` array passed into the constructor of a DataFrame must be 2-dimensional!"),s(!q(t),"The 2-dimensional array passed into the constructor of a DataFrame must not contain sub-arrays (i.e., rows) of different lengths!"),this.values=t}else{this._columns=Object.keys(t).concat(Object.getOwnPropertySymbols(t)).map(a=>a.toString());let n=[],r=null,o=null;this._columns.forEach(a=>{h(o)&&(r=a,o=t[a].length),s(t[a].length===o,`The object passed into the DataFrame constructor contains arrays of different lengths! The key "${r}" points to an array containing ${o} items, and the key "${a}" points to an array containing ${t[a].length} items.`),o=t[a].length;let m=t[a];n.push(m)}),this._values=z(n);let i=b(this.values);this._index=S(0,i[0]).map(a=>"row"+$(a,(i[0]-1).toString().length))}}get shape(){return b(this.values)}get length(){return this.shape[0]}get width(){return this.shape[1]}get rows(){return this.index}set rows(t){this.index=t}get isEmpty(){return this.values.length===0||this.values.every(t=>t.length===0)}clear(){let t=new e(A(this.shape));return t.columns=this.columns.slice(),t.index=this.index.slice(),t}get(t,n){if(arguments.length===0)return this;if(arguments.length===1)try{return this.get(null,t)}catch{return this.get(t,null)}return Pt(this,t,n)}getSubsetByNames(t,n){return Ct(e,E,this,t,n)}getSubsetByIndices(t,n){return zt(this,t,n)}getDummies(t){return vt(e,this,t)}oneHotEncode(t){return vt(e,this,t)}transpose(){let t=new e(z(this.values));return t.columns=this.index.slice(),t.index=this.columns.slice(),t}get T(){return this.transpose()}resetIndex(t){return Jt(this,t)}copy(){return At(e,this)}assign(t,n){return Ft(e,E,this,t,n)}apply(t,n){return xt(e,E,this,t,n)}dropMissing(t,n,r){return Et(e,E,this,t,n,r)}dropNaN(t,n,r){return Mt(e,this,t,n,r)}drop(t,n){return jt(e,E,this,t,n)}dropColumns(t){return this.drop(null,t)}dropRows(t){return this.drop(t,null)}toDetailedObject(t){return Vt(this,t)}toObject(){return Wt(this)}toJSONString(t){return lt(this,t)}saveAsJSON(t,n){return Gt(this,t,n)}print(){return kt(e,E,this)}sort(t,n){return qt(this,t,n)}sortByIndex(){return this.sort()}filter(t,n){return Ut(e,E,this,t,n)}shuffle(t){return Lt(this,t)}append(t,n){return Nt(this,t,n)}concat(t,n){return this.append(t,n)}join(t,n){return this.append(t,n)}toString(){return JSON.stringify(this)}},E=ue(K);function it(e,t){return j(e,{shouldDropNaNs:t}).max}function N(e){return s(O(e),"You must pass a function into the `vectorize` function!"),function t(){let n,r,o=[],i=[],a=Object.keys(arguments).filter(m=>{let u=arguments[m];return l(u)?!0:g(u)?(n=!0,o.push(u),!0):y(u)?(r=!0,i.push(u),!0):!1}).map(m=>arguments[m]);if(a.slice(0,-1).forEach((m,u)=>{s(P(l(m)?b(m):m.shape,l(a[u+1])?b(a[u+1]):a[u+1].shape),`When passing multiple arrays into the \`${e.name}\` function, all of the arrays must have the same shape!`)}),a.length>0){let m=it(a.map(p=>p.length?p.length:p.values.length)),u=S(0,m).map(p=>{let c=Object.keys(arguments).map(d=>l(arguments[d])?arguments[d][p]:g(arguments[d])||y(arguments[d])?arguments[d].values[p]:arguments[d]);return t(...c)});if(r)try{if(i.length===1&&P(b(i[0]),b(u))){let p=new K(u);return p.index=i[0].index.slice(),p.columns=i[0].columns.slice(),p}else return new K(u)}catch{return u}if(n)try{if(o.length===1&&o[0].length===u.length){let p=new E(u);return p.name=o[0].name,p.index=o[0].index.slice(),p}else return new E(u)}catch{return u}return u}else return e(...arguments)}}function ke(e){try{return f(e)?typeof e=="bigint"?e<0?-e:e:Math.abs(e):NaN}catch{return NaN}}var ct=N(ke);function Je(){try{let e=0,t=!1,n=Object.values(arguments);for(let r of n){if(!f(r))return NaN;typeof r=="bigint"&&(t=!0,r=Number(r)),e+=r}if(t)try{return BigInt(e)}catch{}return e}catch{return NaN}}var St=N(Je);function Re(e,t){try{return t(e)}catch{return NaN}}var ht=N(Re);function Ye(e){try{return f(e)?(typeof e=="bigint"&&(e=Number(e)),Math.acos(e)):NaN}catch{return NaN}}var Ke=N(Ye);function $e(e){try{return f(e)?(typeof e=="bigint"&&(e=Number(e)),Math.asin(e)):NaN}catch{return NaN}}var Le=N($e);function qe(e){try{return f(e)?(typeof e=="bigint"&&(e=Number(e)),Math.atan(e)):NaN}catch{return NaN}}var Ve=N(qe);function We(e){try{return f(e)?typeof e=="bigint"?e:Math.ceil(e):NaN}catch{return NaN}}var He=N(We);function Xe(e,t){try{if(!f(e))return NaN;if(typeof e=="bigint")return e;if(h(t))t=1e-10;else if(!f(t))return NaN;return ct(e)<t?0:e}catch{return NaN}}var Qe=N(Xe);function Ot(e){if(y(e)||g(e)){let t=e.copy();return t.values=Ot(t.values),t}if(l(e))return e.map(t=>Ot(t));try{let t=JSON.parse(e);return f(t)?typeof t=="bigint"?Number(t):t>=0?Math.floor(t):Math.ceil(t):NaN}catch{return NaN}}var M=N(Ot);function le(e,t,n){try{return f(e)?f(t)?f(n)?typeof e=="bigint"?BigInt(le(M(e),t,n)):e<t?t:e>n?n:e:NaN:NaN:NaN}catch{return NaN}}var Ze=N(le);function nr(e){try{return f(e)?(typeof e=="bigint"&&(e=Number(e)),Math.cos(e)):NaN}catch{return NaN}}var or=N(nr);var ir=Object.freeze({boolean:"boolean",date:"date",null:"null",number:"number",object:"object",string:"string"});function pe(e,t){try{if(!f(e))return NaN;if(!f(t))return NaN;if(typeof e=="bigint"||typeof t=="bigint"){let n=pe(Number(e),Number(t));try{return BigInt(n)}catch{return n}}return Math.pow(e,t)}catch{return NaN}}var Tt=N(pe);function ce(e){try{if(!f(e))return NaN;if(typeof e=="bigint"){let t=ce(Number(e));try{return BigInt(t)}catch{return t}}return Math.sqrt(e)}catch{return NaN}}var he=N(ce);function sr(){try{let e=Object.values(arguments);if(e.length===0)return NaN;let t=!1,n=1;for(let r of e){if(!f(r))return NaN;typeof r=="bigint"&&(t=!0,r=Number(r)),n*=r}if(t)try{return BigInt(n)}catch{}return n}catch{return NaN}}var de=N(sr);function ur(e){try{if(!f(e))return NaN;if(typeof e=="bigint"){if(e===0n)return 1n;e=Number(e)}return Math.exp(e)}catch{return NaN}}var fr=N(ur);function Dt(e){try{return typeof e=="bigint"?BigInt(Dt(M(e))):e!==M(e)?NaN:e<=1?1:e*Dt(e-1)}catch{return NaN}}var lr=N(Dt);function pr(e){try{if(e==="Infinity")return 1/0;if(e==="-Infinity")return-1/0;let t=JSON.parse(e);return f(t)?t:NaN}catch{return NaN}}var cr=N(pr);function hr(e){try{return f(e)?typeof e=="bigint"?e:Math.floor(e):NaN}catch{return NaN}}var dr=N(hr);function be(e,t,n){try{if(!f(e))return NaN;if(!f(t))return NaN;if(!f(n))return NaN;if(typeof e=="bigint"||typeof t=="bigint"){let r=be(Number(e),Number(t),n);try{return BigInt(r)}catch{return r}}return n*(t-e)+e}catch{return NaN}}var Nr=N(be);function Ne(e,t){try{if(t=h(t)?Math.E:t,!f(e))return NaN;if(!f(t))return NaN;if(typeof e=="bigint"||typeof t=="bigint"){let n=Ne(Number(e),Number(t));try{return BigInt(n)}catch{return n}}return Math.log(e)/Math.log(t)}catch{return NaN}}var vr=N(Ne);function ve(e,t){try{if(!f(e))return NaN;if(!f(t))return NaN;if(typeof e=="bigint"||typeof t=="bigint"){let n=ve(Number(e),Number(t));try{return BigInt(n)}catch{return n}}return e%t}catch{return NaN}}var wr=N(ve);var ld=N((e,t,n,r,o)=>{try{let i=!1;for(let p of[e,t,n,r,o]){if(!f(p))return NaN;typeof p=="bigint"&&(i=!0)}i&&(e=Number(e),t=Number(t),n=Number(n),r=Number(r),o=Number(o));let a=(o-r)*(e-t),m=n-t;if(m===0)return NaN;let u=a/m+r;if(i)try{return BigInt(u)}catch{}return u}catch{return NaN}});function Or(e){try{return f(e)?typeof e=="bigint"?e:Math.round(e):NaN}catch{return NaN}}var Tr=N(Or);function we(e){try{return f(e)?typeof e=="bigint"?BigInt(we(Number(e))):e<0?-1:e>0?1:0:NaN}catch{return NaN}}var Dr=N(we);function _r(e){try{return f(e)?(typeof e=="bigint"&&(e=Number(e)),Math.sin(e)):NaN}catch{return NaN}}var Ir=N(_r);function Fr(e){try{return f(e)?(typeof e=="bigint"&&(e=Number(e)),Math.tan(e)):NaN}catch{return NaN}}var Ar=N(Fr);function Se(e,t,n){arguments.length===2&&(f(arguments[1])?n=null:(n=t,t=null)),s(f(e)&&M(e)===e,"`keyLength` must be an integer!"),t&&(s(f(t)&&M(t)===t,"`keySeed` must be an integer!"),ft(t)),n&&s(w(n),"`charset` must be a string!");let r="";n=n||"abcdefg1234567890";for(let o=0;o<e;o++)r+=n[M(Y()*n.length)];return r}typeof globalThis<"u"&&(globalThis.makeKey=Se);})();
1
+ (()=>{function f(t,e,o){if(typeof t!="number"||isNaN(t))throw new Error("The first value passed into the `makeKey` function must be a number!");if(e&&(e instanceof Array&&(e=e.join("")),typeof e!="string"))throw new Error("The second argument passed into the `makeKey` function must be a string or array of strings!");if(o=o||Math.random,typeof o!="function")throw new Error("The third argument passed into the `makeKey` function must be a function!");let i="";e=e||"abcdef1234567890";for(let n=0;n<t;n++)i+=e[Math.floor(o()*e.length)];return i}typeof globalThis<"u"&&(globalThis.makeKey=f);})();
package/package.json CHANGED
@@ -1,22 +1,21 @@
1
1
  {
2
- "author": "",
3
2
  "bin": {
4
- "key": "./bin.mjs"
3
+ "key": "./src/bin.mjs"
5
4
  },
6
- "dependencies": {
7
- "@jrc03c/js-math-tools": "^0.0.92"
8
- },
9
- "description": "",
10
5
  "devDependencies": {
11
- "@jrc03c/fake-jest": "^0.0.16",
12
- "esbuild": "^0.25.0",
13
- "eslint": "^8.36.0"
6
+ "@jrc03c/fake-jest": "^0.0.17",
7
+ "@jrc03c/js-math-tools": "^0.0.94",
8
+ "esbuild": "^0.25.4",
9
+ "eslint": "^8.36.0",
10
+ "prettier": "^3.5.3"
14
11
  },
15
- "keywords": [],
16
12
  "license": "ISC",
17
13
  "main": "./src/index.mjs",
18
14
  "module": "./src/index.mjs",
19
15
  "name": "@jrc03c/make-key",
20
16
  "type": "module",
21
- "version": "0.0.36"
17
+ "version": "0.0.38",
18
+ "dependencies": {
19
+ "@jrc03c/js-math-tools": "file:../js-math-tools"
20
+ }
22
21
  }
package/readme.md CHANGED
@@ -15,40 +15,30 @@ npm install --save https://github.com/jrc03c/make-key
15
15
  Node / bundlers:
16
16
 
17
17
  ```js
18
- const makeKey = require("@jrc03c/make-key")
19
- const keyLength = 32
20
- const keySeed = 1234
21
-
22
- console.log(makeKey(keyLength))
23
- // "8v1101x1whevcm1cgdhuq90e12549xri"
24
-
25
- console.log(makeKey(keyLength, keySeed))
26
- // "dcb09fuuv3smirvqaetiyggvhap90e88"
18
+ import { makeKey } from "@jrc03c/make-key"
19
+ console.log(makeKey(32))
20
+ // "33189046179171bfb492577f0fdca4ca"
27
21
  ```
28
22
 
29
23
  Browser:
30
24
 
31
25
  ```html
32
- <script src="path/to/@jrc03c/make-key/dist/make-key.js"></script>
26
+ <script src="path/to/@jrc03c/make-key/dist/make-key.min.js"></script>
33
27
  <script>
34
- // (makeKey is now in the global scope)
35
-
36
- const keyLength = 32
37
- const keySeed = 1234
38
-
39
- console.log(makeKey(keyLength))
28
+ // (`makeKey` is available in the global scope)
29
+ console.log(makeKey(32))
40
30
  // "8v1101x1whevcm1cgdhuq90e12549xri"
41
-
42
- console.log(makeKey(keyLength, keySeed))
43
- // "dcb09fuuv3smirvqaetiyggvhap90e88"
44
31
  </script>
45
32
  ```
46
33
 
47
34
  ## API
48
35
 
49
- ### `makeKey(length, seed, charset)`
36
+ ### `makeKey(length, charset, randomFn)`
37
+
38
+ Returns a random string of length `length`. Can optionally accept:
50
39
 
51
- Returns a random string of length `length`. Can optionally be given a random `seed` value as a number and/or a `charset` as a string of characters from which to generate the new string.
40
+ - `charset` = a string (or an array of strings) defining the characters from which to generate the new string; uses `abcdef1234567890` by default
41
+ - `randomFn` = a random number generation function; uses `Math.random` by default
52
42
 
53
43
  # CLI
54
44
 
@@ -60,7 +50,7 @@ cd make-key
60
50
  npm link
61
51
  ```
62
52
 
63
- Optionally, you can install `xsel` to automatically have the key copied to the clipboard:
53
+ Optionally, you can install `xsel` to have the key be copied automatically to the clipboard:
64
54
 
65
55
  ```bash
66
56
  sudo apt-get install -y xsel
@@ -69,12 +59,15 @@ sudo apt-get install -y xsel
69
59
  ## Usage
70
60
 
71
61
  ```bash
72
- # key <length> <seed>
73
- key 32 12345
62
+ key 32
63
+ # e1123ab8eff4082147cef3adc030769d
64
+
65
+ key 32 foobar
66
+ # aaoobrrforfbbfoofffooffroaoofaba
74
67
  ```
75
68
 
76
69
  ## API
77
70
 
78
- ### `key <length> <seed> <charset>`
71
+ ### `key <length> <charset>`
79
72
 
80
73
  These arguments mean the same thing as in the Node / browser API.
package/src/bin.mjs ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import { exec } from "node:child_process"
3
+ import { makeKey } from "./index.mjs"
4
+
5
+ const args = process.argv.slice(2)
6
+
7
+ if (args.length === 0) {
8
+ console.log("SYNTAX: key <length> <charset>")
9
+ process.exit(0)
10
+ }
11
+
12
+ const keyLength = parseInt(args[0])
13
+ const charset = args[1]
14
+ const key = makeKey(keyLength, charset)
15
+ console.log(key)
16
+
17
+ try {
18
+ exec(`echo -n "${key}" | xsel -b`, () => {})
19
+ } catch (e) {}
package/src/index.mjs CHANGED
@@ -1,45 +1,35 @@
1
- import {
2
- assert,
3
- int,
4
- isNumber,
5
- isString,
6
- random,
7
- seed,
8
- } from "@jrc03c/js-math-tools"
9
-
10
- function makeKey(keyLength, keySeed, charset) {
11
- if (arguments.length === 2) {
12
- if (isNumber(arguments[1])) {
13
- charset = null
14
- } else {
15
- charset = keySeed
16
- keySeed = null
17
- }
1
+ function makeKey(keyLength, charset, randomFn) {
2
+ if (typeof keyLength !== "number" || isNaN(keyLength)) {
3
+ throw new Error(
4
+ "The first value passed into the `makeKey` function must be a number!",
5
+ )
18
6
  }
19
7
 
20
- assert(
21
- isNumber(keyLength) && int(keyLength) === keyLength,
22
- "`keyLength` must be an integer!",
23
- )
24
-
25
- if (keySeed) {
26
- assert(
27
- isNumber(keySeed) && int(keySeed) === keySeed,
28
- "`keySeed` must be an integer!",
29
- )
8
+ if (charset) {
9
+ if (charset instanceof Array) {
10
+ charset = charset.join("")
11
+ }
30
12
 
31
- seed(keySeed)
13
+ if (typeof charset !== "string") {
14
+ throw new Error(
15
+ "The second argument passed into the `makeKey` function must be a string or array of strings!",
16
+ )
17
+ }
32
18
  }
33
19
 
34
- if (charset) {
35
- assert(isString(charset), "`charset` must be a string!")
20
+ randomFn = randomFn || Math.random
21
+
22
+ if (typeof randomFn !== "function") {
23
+ throw new Error(
24
+ "The third argument passed into the `makeKey` function must be a function!",
25
+ )
36
26
  }
37
27
 
38
28
  let out = ""
39
- charset = charset || "abcdefg1234567890"
29
+ charset = charset || "abcdef1234567890"
40
30
 
41
31
  for (let i = 0; i < keyLength; i++) {
42
- out += charset[int(random() * charset.length)]
32
+ out += charset[Math.floor(randomFn() * charset.length)]
43
33
  }
44
34
 
45
35
  return out
@@ -1,5 +1,6 @@
1
- import { makeKey } from "./index.mjs"
2
1
  import { expect, test } from "@jrc03c/fake-jest"
2
+ import { makeKey } from "./index.mjs"
3
+ import { random, seed } from "@jrc03c/js-math-tools"
3
4
 
4
5
  test("tests that random strings can be generated correctly", () => {
5
6
  const a = makeKey(123)
@@ -9,12 +10,16 @@ test("tests that random strings can be generated correctly", () => {
9
10
  const c = makeKey(123)
10
11
  expect(b).not.toBe(c)
11
12
 
12
- const d = makeKey(123, 12345)
13
- const e = makeKey(123, 12345)
13
+ seed(12345)
14
+ const d = makeKey(123, null, random)
15
+ seed(12345)
16
+ const e = makeKey(123, null, random)
14
17
  expect(d).toBe(e)
15
18
 
16
- const f = makeKey(64, 12345)
17
- const g = makeKey(32, 12345)
19
+ seed(12345)
20
+ const f = makeKey(64, null, random)
21
+ seed(12345)
22
+ const g = makeKey(32, null, random)
18
23
  expect(f.includes(g)).toBe(true)
19
24
  expect(g.includes(f)).toBe(false)
20
25
 
@@ -28,13 +33,18 @@ test("tests that random strings can be generated correctly", () => {
28
33
  const i = makeKey(123, charset)
29
34
  expect(h).not.toBe(i)
30
35
 
31
- const j = makeKey(123, 12345, charset)
32
- const k = makeKey(123, 12345, charset)
36
+ seed(12345)
37
+ const j = makeKey(123, charset, random)
38
+ seed(12345)
39
+ const k = makeKey(123, charset, random)
33
40
  expect(j).toBe(k)
34
- expect(makeKey(123, 12345, "foobar")).not.toBe(k)
41
+ seed(12345)
42
+ expect(makeKey(123, "foobar", random)).not.toBe(k)
35
43
 
36
- const l = makeKey(64, 12345, charset)
37
- const m = makeKey(32, 12345, charset)
44
+ seed(12345)
45
+ const l = makeKey(64, charset, random)
46
+ seed(12345)
47
+ const m = makeKey(32, charset, random)
38
48
  expect(l.includes(m)).toBe(true)
39
49
  expect(m.includes(l)).toBe(false)
40
50
  })
package/bin.mjs DELETED
@@ -1,31 +0,0 @@
1
- #!/usr/bin/env node
2
- import { exec } from "node:child_process"
3
- import { makeKey } from "./src/index.mjs"
4
-
5
- const args = process.argv.slice(2)
6
-
7
- if (args.length === 0) {
8
- console.log("You must specify a key length.")
9
- process.exit(0)
10
- }
11
-
12
- const keyLength = parseInt(args[0])
13
- let keySeed, charset
14
-
15
- if (args.length === 2) {
16
- if (!isNaN(parseInt(args[1]))) {
17
- keySeed = parseInt(args[1])
18
- } else {
19
- charset = args[1]
20
- }
21
- } else if (args.length > 2) {
22
- keySeed = parseInt(args[1])
23
- charset = args[2]
24
- }
25
-
26
- const key = makeKey(keyLength, keySeed, charset)
27
- console.log(key)
28
-
29
- try {
30
- exec(`echo -n "${key}" | xsel -b`, () => {})
31
- } catch (e) {}