@jrc03c/make-key 0.0.37 → 0.0.39

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.
package/dist/make-key.js CHANGED
@@ -1,3501 +1,37 @@
1
1
  (() => {
2
- // node_modules/@jrc03c/js-math-tools/src/is-number.mjs
3
- function isNumber(x) {
4
- return typeof x === "number" && !isNaN(x) || typeof x === "bigint";
5
- }
6
-
7
- // node_modules/@jrc03c/js-math-tools/src/is-browser.mjs
8
- var isBrowser = new Function(
9
- `
10
- try {
11
- return this === window
12
- } catch(e) {}
13
-
14
- try {
15
- return !!importScripts
16
- } catch(e){}
17
-
18
- return false
19
- `
20
- );
21
-
22
- // node_modules/@jrc03c/js-math-tools/src/math-error.mjs
23
- var MathError = class extends Error {
24
- constructor(message) {
25
- if (isBrowser()) {
26
- super(message);
27
- } else {
28
- super("\n\n\x1B[31m" + message + "\n\x1B[0m");
29
- }
30
- }
31
- };
32
-
33
- // node_modules/@jrc03c/js-math-tools/src/assert.mjs
34
- function assert(isTrue, message) {
35
- if (!isTrue) throw new MathError(message);
36
- }
37
-
38
- // node_modules/@jrc03c/js-math-tools/src/helpers/array-types.mjs
39
- var arrayTypes = [
40
- Array,
41
- ArrayBuffer,
42
- BigInt64Array,
43
- BigUint64Array,
44
- Float32Array,
45
- Float64Array,
46
- Int16Array,
47
- Int32Array,
48
- Int8Array,
49
- Uint16Array,
50
- Uint32Array,
51
- Uint8Array,
52
- Uint8ClampedArray
53
- ];
54
-
55
- // node_modules/@jrc03c/js-math-tools/src/is-undefined.mjs
56
- function isUndefined(x) {
57
- return x === null || typeof x === "undefined";
58
- }
59
-
60
- // node_modules/@jrc03c/js-math-tools/src/is-array.mjs
61
- var typeStrings = arrayTypes.map((s2) => s2.name);
62
- function isArray(obj) {
63
- try {
64
- if (obj instanceof Array) {
65
- return true;
66
- }
67
- if (!isUndefined(obj.constructor)) {
68
- return arrayTypes.indexOf(obj.constructor) > -1 || typeStrings.indexOf(obj.constructor.name) > -1;
69
- }
70
- return false;
71
- } catch (e) {
72
- return false;
73
- }
74
- }
75
-
76
- // node_modules/@jrc03c/js-math-tools/src/is-dataframe.mjs
77
- function isDataFrame(x) {
78
- try {
79
- return !!x._symbol && x._symbol === Symbol.for("@jrc03c/js-math-tools/dataframe");
80
- } catch (e) {
81
- return false;
82
- }
83
- }
84
-
85
- // node_modules/@jrc03c/js-math-tools/src/is-function.mjs
86
- function isFunction(fn) {
87
- return typeof fn === "function";
88
- }
89
-
90
- // node_modules/@jrc03c/js-math-tools/src/is-object.mjs
91
- function isObject(x) {
92
- return typeof x === "object" && !isUndefined(x) && !isArray(x);
93
- }
94
-
95
- // node_modules/@jrc03c/js-math-tools/src/is-series.mjs
96
- function isSeries(x) {
97
- try {
98
- return !!x._symbol && x._symbol === Symbol.for("@jrc03c/js-math-tools/series");
99
- } catch (e) {
100
- return false;
101
- }
102
- }
103
-
104
- // node_modules/@jrc03c/js-math-tools/src/index-of.mjs
105
- function indexOf(x, fn) {
106
- if (isDataFrame(x)) {
107
- const index = indexOf(x.values, fn);
108
- if (index.length > 0 && isNumber(index[0]) && index[0] >= 0 && index[0] < x.index.length) {
109
- index[0] = x.index[index[0]];
110
- }
111
- if (index.length > 1 && isNumber(index[1]) && index[1] >= 0 && index[1] < x.columns.length) {
112
- index[1] = x.columns[index[1]];
113
- }
114
- return index;
115
- }
116
- if (isSeries(x)) {
117
- const index = indexOf(x.values, fn);
118
- if (index.length > 0 && isNumber(index[0]) && index[0] >= 0 && index[0] < x.index.length) {
119
- index[0] = x.index[index[0]];
120
- }
121
- return index;
122
- }
123
- assert(
124
- isObject(x) || isArray(x),
125
- "You must pass (1) an object, array, Series, or DataFrame and (2) a function or value into the `indexOf` function!"
126
- );
127
- if (!isFunction(fn)) {
128
- const value = fn;
129
- fn = (v) => v === value;
130
- }
131
- function helper4(x2, fn2, checked) {
132
- checked = checked || [];
133
- if (checked.indexOf(x2) > -1) {
134
- return null;
135
- }
136
- if (isObject(x2)) {
137
- checked.push(x2);
138
- const keys = Object.keys(x2).concat(Object.getOwnPropertySymbols(x2));
139
- for (let i = 0; i < keys.length; i++) {
140
- const key = keys[i];
141
- const value = x2[key];
142
- if (fn2(value)) {
143
- return [key];
144
- }
145
- const results = helper4(value, fn2, checked);
146
- if (results && results.length > 0) {
147
- return [key].concat(results);
148
- }
149
- }
150
- } else if (isArray(x2)) {
151
- checked.push(x2);
152
- for (let i = 0; i < x2.length; i++) {
153
- const value = x2[i];
154
- if (fn2(value)) {
155
- return [i];
156
- }
157
- const results = helper4(value, fn2, checked);
158
- if (results && results.length > 0) {
159
- return [i].concat(results);
160
- }
161
- }
162
- } else {
163
- if (fn2(x2)) {
164
- return [];
165
- }
166
- }
167
- return null;
168
- }
169
- function safeFn(v) {
170
- try {
171
- return fn(v);
172
- } catch (e) {
173
- return false;
174
- }
175
- }
176
- const paths = helper4(x, safeFn);
177
- if (paths && paths.length > 0) {
178
- return paths;
179
- } else {
180
- return null;
181
- }
182
- }
183
-
184
- // node_modules/@jrc03c/js-math-tools/src/copy.mjs
185
- function copy(x) {
186
- function helper4(x2) {
187
- if (typeof x2 === "object") {
188
- if (x2 === null) {
189
- return null;
190
- }
191
- if (isArray(x2)) {
192
- if (!(x2 instanceof Array)) {
193
- return x2.slice();
194
- }
195
- return x2.map((v) => copy(v));
196
- }
197
- if (isSeries(x2)) {
198
- const out2 = x2.copy();
199
- out2.values = copy(out2.values);
200
- return out2;
201
- }
202
- if (isDataFrame(x2)) {
203
- const out2 = x2.copy();
204
- out2.values = copy(x2.values);
205
- return out2;
206
- }
207
- if (x2 instanceof Date) {
208
- return new Date(x2.getTime());
209
- }
210
- x2 = decycle(x2);
211
- const out = {};
212
- Object.keys(x2).concat(Object.getOwnPropertySymbols(x2)).forEach((key) => {
213
- out[key] = copy(x2[key]);
214
- });
215
- return out;
216
- } else {
217
- return x2;
218
- }
219
- }
220
- return helper4(decycle(x));
221
- }
222
- function decycle(x) {
223
- function helper4(x2, checked, currentPath) {
224
- checked = checked || [];
225
- currentPath = currentPath || "";
226
- if (checked.indexOf(x2) > -1) {
227
- const parts = currentPath.split("/").slice(currentPath.startsWith("/") ? 1 : 0);
228
- const isANestedCopy = parts.some((v, i) => {
229
- const subParts = parts.slice(0, parts.length - i - 1);
230
- let temp = orig;
231
- subParts.forEach((part) => {
232
- temp = temp[part];
233
- });
234
- return temp === x2;
235
- });
236
- if (isANestedCopy) {
237
- const pathToCopy = orig === x2 ? "/" : "/" + indexOf(orig, x2).join("/");
238
- return `<reference to "${pathToCopy}">`;
239
- }
240
- }
241
- if (typeof x2 === "object") {
242
- if (x2 === null) return null;
243
- checked.push(x2);
244
- if (isArray(x2)) {
245
- if (typeof x2.constructor !== "undefined" && x2.constructor.name !== "Array") {
246
- return x2.slice();
247
- }
248
- return x2.map((v, i) => helper4(v, checked, currentPath + "/" + i));
249
- } else {
250
- Object.keys(x2).concat(Object.getOwnPropertySymbols(x2)).forEach((key) => {
251
- x2[key] = helper4(x2[key], checked, currentPath + "/" + key.toString());
252
- });
253
- return x2;
254
- }
255
- } else {
256
- return x2;
257
- }
258
- }
259
- const orig = x;
260
- let out = helper4(orig);
261
- if (isDataFrame(x)) {
262
- const temp = x.copy();
263
- temp._values = out.values;
264
- temp._columns = out.columns;
265
- temp._index = out.index;
266
- out = temp;
267
- }
268
- if (isSeries(x)) {
269
- const temp = x.copy();
270
- temp.name = out.name;
271
- temp._values = out.values;
272
- temp._index = out.index;
273
- out = temp;
274
- }
275
- return out;
276
- }
277
-
278
- // node_modules/@jrc03c/js-math-tools/src/is-date.mjs
279
- function isDate(x) {
280
- return x instanceof Date && x.toString() !== "Invalid Date";
281
- }
282
-
283
- // node_modules/@jrc03c/js-math-tools/src/is-equal.mjs
284
- var numberTypes = ["number", "int", "float", "bigint"];
285
- function isEqual(a, b) {
286
- function helper4(a2, b2) {
287
- const aType = typeof a2;
288
- const bType = typeof b2;
289
- if (aType !== bType && !numberTypes.includes(aType) && !numberTypes.includes(bType))
290
- return false;
291
- if (aType === "undefined" && bType === "undefined") return true;
292
- if (aType === "boolean") return a2 === b2;
293
- if (aType === "symbol") return a2 === b2;
294
- if (aType === "number" || aType === "bigint") {
295
- try {
296
- const aString = a2.toString();
297
- const bString = b2.toString();
298
- return aString === bString;
299
- } catch (e) {
300
- return false;
301
- }
302
- }
303
- if (aType === "string") return a2 === b2;
304
- if (aType === "function") return a2 === b2;
305
- if (aType === "object") {
306
- if (a2 === null || b2 === null) {
307
- return a2 === null && b2 === null;
308
- } else {
309
- if (isDate(a2)) {
310
- if (isDate(b2)) {
311
- return a2.getTime() === b2.getTime();
312
- } else {
313
- return false;
314
- }
315
- } else if (isDate(b2)) {
316
- return false;
317
- }
318
- if (a2 instanceof RegExp && b2 instanceof RegExp) {
319
- return a2.toString() === b2.toString();
320
- }
321
- if (isArray(a2) !== isArray(b2)) {
322
- return false;
323
- }
324
- const aKeys = Object.keys(a2).concat(Object.getOwnPropertySymbols(a2));
325
- const bKeys = Object.keys(b2).concat(Object.getOwnPropertySymbols(b2));
326
- if (aKeys.length !== bKeys.length) return false;
327
- for (let i = 0; i < aKeys.length; i++) {
328
- const key = aKeys[i];
329
- if (!helper4(a2[key], b2[key])) return false;
330
- }
331
- return true;
332
- }
333
- }
334
- }
335
- try {
336
- return helper4(a, b);
337
- } catch (e) {
338
- return helper4(decycle(a), decycle(b));
339
- }
340
- }
341
-
342
- // node_modules/@jrc03c/js-math-tools/src/helpers/counter.mjs
343
- function makeKey(n) {
344
- const alpha = "abcdefg1234567890";
345
- let out = "";
346
- while (out.length < n) out += alpha[Math.floor(Math.random() * alpha.length)];
347
- return out;
348
- }
349
- var NULL_KEY = makeKey(16);
350
- var UNDEFINED_KEY = makeKey(16);
351
- var INFINITY_KEY = makeKey(16);
352
- var MINUS_INFINITY_KEY = makeKey(16);
353
- var SYMBOL_KEY = makeKey(16);
354
- var Counter = class {
355
- constructor() {
356
- this.clear();
357
- }
358
- get counts() {
359
- return this.values.map((v) => this.get(v));
360
- }
361
- get values() {
362
- return Object.values(this.valuesDict);
363
- }
364
- clear() {
365
- this.countsDict = {};
366
- this.valuesDict = {};
367
- return this;
368
- }
369
- count(x) {
370
- for (const v of x) {
371
- if (isArray(v)) {
372
- this.count(v);
373
- } else {
374
- this.increment(v);
375
- }
376
- }
377
- return this;
378
- }
379
- delete(value) {
380
- const key = this.getStandardizedKey(value);
381
- delete this.countsDict[key];
382
- delete this.valuesDict[key];
383
- return this;
384
- }
385
- get(value) {
386
- return this.countsDict[this.getStandardizedKey(value)] || 0;
387
- }
388
- getStandardizedKey(value) {
389
- return typeof value === "object" && value === null ? NULL_KEY : isUndefined(value) ? UNDEFINED_KEY : isFunction(value) ? value.toString() : typeof value === "symbol" ? value.toString() + " - " + SYMBOL_KEY : value === Infinity ? INFINITY_KEY : value === -Infinity ? MINUS_INFINITY_KEY : typeof value === "bigint" ? value.toString() : isDataFrame(value) ? value.toJSONString() : isSeries(value) ? JSON.stringify(value.toObject()) : JSON.stringify(value);
390
- }
391
- has(value) {
392
- return !isUndefined(this.countsDict[this.getStandardizedKey(value)]);
393
- }
394
- increment(value) {
395
- return this.set(value, this.get(value) + 1);
396
- }
397
- set(value, count2) {
398
- const key = this.getStandardizedKey(value);
399
- this.countsDict[key] = count2;
400
- this.valuesDict[key] = value;
401
- return this;
402
- }
403
- toArray() {
404
- return this.values.map((v) => ({ value: v, count: this.get(v) }));
405
- }
406
- toObject() {
407
- const out = {};
408
- this.values.forEach((value) => {
409
- out[value] = this.get(value);
410
- });
411
- return out;
412
- }
413
- };
414
-
415
- // node_modules/@jrc03c/js-math-tools/src/flatten.mjs
416
- function flatten(arr) {
417
- if (isDataFrame(arr) || isSeries(arr)) {
418
- return flatten(arr.values);
419
- }
420
- assert(
421
- isArray(arr),
422
- "The `flatten` function only works on arrays, Series, and DataFrames!"
423
- );
424
- function helper4(arr2) {
425
- let out = [];
426
- arr2.forEach((child) => {
427
- if (isArray(child)) {
428
- out = out.concat(helper4(child));
429
- } else {
430
- out.push(child);
431
- }
432
- });
433
- return out;
434
- }
435
- return helper4(arr);
436
- }
437
-
438
- // node_modules/@jrc03c/js-math-tools/src/stats.mjs
439
- function stats(x, options) {
440
- options = options || {};
441
- const counts = new Counter();
442
- const out = {};
443
- const xflat = flatten(x);
444
- const xnums = [];
445
- let max2 = -Infinity;
446
- let min2 = Infinity;
447
- let resultsShouldIncludeBigInts = false;
448
- let sum2 = 0;
449
- for (const v of xflat) {
450
- if (typeof v === "bigint") {
451
- resultsShouldIncludeBigInts = true;
452
- }
453
- if (!options.shouldDropNaNs || isNumber(v)) {
454
- try {
455
- if (v > max2) {
456
- max2 = v;
457
- }
458
- if (v < min2) {
459
- min2 = v;
460
- }
461
- sum2 += Number(v);
462
- xnums.push(v);
463
- } catch (e) {
464
- max2 = NaN;
465
- min2 = NaN;
466
- sum2 = NaN;
467
- }
468
- }
469
- counts.increment(v);
470
- }
471
- const mean2 = sum2 / xnums.length;
472
- out.counts = counts;
473
- out.max = max2;
474
- out.mean = mean2;
475
- out.min = min2;
476
- out.n = xflat.length;
477
- out.sum = sum2;
478
- if (isNaN(out.mean)) {
479
- out.max = NaN;
480
- out.min = NaN;
481
- }
482
- if (options.shouldDropNaNs) {
483
- out.nWithoutNaNs = xnums.length;
484
- }
485
- if (options.mode) {
486
- const sortedCountPairs = Array.from(
487
- counts.values.map((v) => [v, counts.get(v)])
488
- ).toSorted((a, b) => b[1] - a[1]);
489
- const highestCount = sortedCountPairs[0][1];
490
- const mode2 = [];
491
- for (const pair of sortedCountPairs) {
492
- if (pair[1] == highestCount) {
493
- mode2.push(pair[0]);
494
- } else {
495
- break;
496
- }
497
- }
498
- out.mode = mode2.toSorted();
499
- }
500
- if (options.median) {
501
- if (isNaN(mean2)) {
502
- out.median = NaN;
503
- } else {
504
- const xnumsSorted = xnums.toSorted((a, b) => Number(a) - Number(b));
505
- const middle = Math.floor(xnumsSorted.length / 2);
506
- if (xnumsSorted.length % 2 === 0) {
507
- const left = xnumsSorted[middle - 1];
508
- const right = xnumsSorted[middle];
509
- out.median = (Number(left) + Number(right)) / 2;
510
- if (resultsShouldIncludeBigInts && typeof left === "bigint" && typeof right === "bigint") {
511
- try {
512
- out.median = BigInt(out.median);
513
- } catch (e) {
514
- }
515
- }
516
- } else {
517
- out.median = xnumsSorted[middle];
518
- }
519
- }
520
- }
521
- if (options.stdev || options.variance) {
522
- let variance2 = 0;
523
- for (const v of xnums) {
524
- variance2 += Math.pow(Number(v) - mean2, 2);
525
- }
526
- variance2 /= xnums.length;
527
- const stdev2 = Math.sqrt(variance2);
528
- out.stdev = stdev2;
529
- out.variance = variance2;
530
- }
531
- if (resultsShouldIncludeBigInts) {
532
- try {
533
- out.sum = BigInt(out.sum);
534
- } catch (e) {
535
- }
536
- try {
537
- out.mean = BigInt(out.mean);
538
- } catch (e) {
539
- }
540
- if (options.mode) {
541
- out.mode = out.mode.map((v) => {
542
- try {
543
- return BigInt(v);
544
- } catch (e) {
545
- return v;
546
- }
547
- });
548
- }
549
- }
550
- return out;
551
- }
552
-
553
- // node_modules/@jrc03c/js-math-tools/src/count.mjs
554
- function count(arr, matcher) {
555
- const { counts } = stats(arr);
556
- if (!isUndefined(matcher)) {
557
- if (isFunction(matcher)) {
558
- counts.values.forEach((v) => {
559
- if (!matcher(v)) {
560
- counts.delete(v);
561
- }
562
- });
563
- } else {
564
- counts.values.forEach((v) => {
565
- if (!isEqual(v, matcher)) {
566
- counts.delete(v);
567
- }
568
- });
569
- }
570
- }
571
- return counts;
572
- }
573
-
574
- // node_modules/@jrc03c/js-math-tools/src/is-jagged.mjs
575
- function helper(x) {
576
- if (isDataFrame(x) || isSeries(x)) {
577
- return helper(x.values);
578
- }
579
- if (isArray(x)) {
580
- let hasArrayValues = false;
581
- let hasNonArrayValues = false;
582
- let arrayLength = null;
583
- for (const v of x) {
584
- if (helper(v)) {
585
- return true;
586
- }
587
- if (isArray(v)) {
588
- if (arrayLength === null) {
589
- arrayLength = v.length;
590
- } else if (v.length !== arrayLength) {
591
- return true;
592
- }
593
- hasArrayValues = true;
594
- } else {
595
- hasNonArrayValues = true;
596
- }
597
- if (hasArrayValues && hasNonArrayValues) {
598
- return true;
599
- }
600
- }
601
- }
602
- return false;
603
- }
604
- function isJagged(x) {
605
- return helper(decycle(x));
606
- }
607
-
608
- // node_modules/@jrc03c/js-math-tools/src/is-nested.mjs
609
- function isNested(x) {
610
- if (isDataFrame(x) || isSeries(x)) {
611
- return isNested(x.values);
612
- }
613
- assert(
614
- isArray(x),
615
- "The `isNested` function only works on arrays, Series, and DataFrames!"
616
- );
617
- for (let i = 0; i < x.length; i++) {
618
- if (isArray(x[i])) {
619
- return true;
620
- }
621
- }
622
- return false;
623
- }
624
-
625
- // node_modules/@jrc03c/js-math-tools/src/ndarray.mjs
626
- var error = "You must pass a natural number or a one-dimensional array of natural numbers into the `ndarray` function!";
627
- function ndarray(shape2) {
628
- assert(!isUndefined(shape2), error);
629
- if (!isArray(shape2)) shape2 = [shape2];
630
- assert(!isNested(shape2), error);
631
- assert(shape2.length > 0, error);
632
- let s2 = shape2[0];
633
- if (typeof s2 === "bigint") s2 = Number(s2);
634
- assert(isNumber(s2), error);
635
- assert(s2 >= 0, error);
636
- assert(Math.floor(s2) === s2, error);
637
- assert(
638
- s2 !== Infinity,
639
- "We can't create an array containing an infinite number of values!"
640
- );
641
- if (shape2.length === 1) {
642
- const out = [];
643
- for (let i = 0; i < s2; i++) out.push(void 0);
644
- return out;
645
- } else {
646
- const out = [];
647
- for (let i = 0; i < s2; i++) {
648
- out.push(ndarray(shape2.slice(1)));
649
- }
650
- return out;
651
- }
652
- }
653
-
654
- // node_modules/@jrc03c/js-math-tools/src/reverse.mjs
655
- function reverse(arr) {
656
- if (isDataFrame(arr) || isSeries(arr)) {
657
- const out2 = arr.copy();
658
- out2.values = reverse(out2.values);
659
- out2.index = reverse(out2.index);
660
- return out2;
661
- }
662
- assert(
663
- isArray(arr),
664
- "The `reverse` function only works on arrays, Series, and DataFrames!"
665
- );
666
- const out = [];
667
- for (let i = arr.length - 1; i >= 0; i--) out.push(arr[i]);
668
- return out;
669
- }
670
-
671
- // node_modules/@jrc03c/js-math-tools/src/range.mjs
672
- function range(a, b, step = 1) {
673
- assert(
674
- !isUndefined(a) && !isUndefined(b) && !isUndefined(step),
675
- "You must pass two numbers and optionally a step value to the `range` function!"
676
- );
677
- assert(
678
- isNumber(a) && isNumber(b) && isNumber(step),
679
- "You must pass two numbers and optionally a step value to the `range` function!"
680
- );
681
- assert(
682
- step > 0,
683
- "The step value must be greater than 0! (NOTE: The step value is a magnitude; it does not indicate direction.)"
684
- );
685
- let shouldReverse = false;
686
- const shouldIncludeBigInts = typeof a === "bigint" || typeof b === "bigint" || typeof step === "bigint";
687
- a = Number(a);
688
- b = Number(b);
689
- step = Number(step);
690
- if (a > b) {
691
- shouldReverse = true;
692
- const buffer = a;
693
- a = b + step;
694
- b = buffer + step;
695
- }
696
- let out = [];
697
- for (let i = a; i < b; i += step) {
698
- if (shouldIncludeBigInts) {
699
- try {
700
- out.push(BigInt(i));
701
- } catch (e) {
702
- out.push(i);
703
- }
704
- } else {
705
- out.push(i);
706
- }
707
- }
708
- if (shouldReverse) out = reverse(out);
709
- return out;
710
- }
711
-
712
- // node_modules/@jrc03c/js-math-tools/src/set.mjs
713
- function makeKey2(n) {
714
- const alpha = "abcdefg1234567890";
715
- let out = "";
716
- while (out.length < n) out += alpha[Math.floor(Math.random() * alpha.length)];
717
- return out;
718
- }
719
- var NULL_KEY2 = makeKey2(256);
720
- var UNDEFINED_KEY2 = makeKey2(256);
721
- var INFINITY_KEY2 = makeKey2(256);
722
- var MINUS_INFINITY_KEY2 = makeKey2(256);
723
- var SYMBOL_KEY2 = makeKey2(256);
724
- function set(arr) {
725
- if (isDataFrame(arr) || isSeries(arr)) {
726
- return set(arr.values);
727
- }
728
- assert(
729
- isArray(arr),
730
- "The `set` function only works on arrays, Series, and DataFrames!"
731
- );
732
- const out = [];
733
- const temp = {};
734
- flatten(arr).forEach((item) => {
735
- const key = typeof item === "object" && item === null ? NULL_KEY2 : isUndefined(item) ? UNDEFINED_KEY2 : isFunction(item) ? item.toString() : typeof item === "symbol" ? item.toString() + " - " + SYMBOL_KEY2 : item === Infinity ? INFINITY_KEY2 : item === -Infinity ? MINUS_INFINITY_KEY2 : typeof item === "bigint" ? item.toString() : isDataFrame(item) ? item.toJSONString() : isSeries(item) ? JSON.stringify(item.toObject()) : JSON.stringify(item);
736
- if (!temp[key]) out.push(item);
737
- temp[key] = true;
738
- });
739
- return out;
740
- }
741
-
742
- // node_modules/@jrc03c/js-math-tools/src/shape.mjs
743
- function helper2(x) {
744
- if (isArray(x)) {
745
- const childShapes = helper2(x[0]);
746
- return [x.length].concat(childShapes || []);
747
- } else {
748
- return void 0;
749
- }
750
- }
751
- function shape(x) {
752
- if (isDataFrame(x) || isSeries(x)) {
753
- return shape(x.values);
754
- }
755
- assert(
756
- isArray(x),
757
- "The `shape` function only works on arrays, Series, and DataFrames!"
758
- );
759
- return helper2(x);
760
- }
761
-
762
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-append.mjs
763
- function dfAppend(df, x, axis) {
764
- if (isUndefined(axis)) {
765
- axis = 0;
766
- }
767
- assert(
768
- axis === 0 || axis === 1 || axis === "vertical" || axis === "horizontal",
769
- '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".'
770
- );
771
- if (isArray(x)) {
772
- assert(
773
- !isJagged(x),
774
- "The array of data you're trying to append to this DataFrame is jagged!"
775
- );
776
- const xShape = shape(x);
777
- if (xShape.length === 1) {
778
- if (axis === 0) {
779
- const out = df.copy();
780
- out._values.push(x);
781
- const maxRowLength = Math.max(df.shape[1], xShape[0]);
782
- out._values.forEach((row) => {
783
- while (row.length < maxRowLength) {
784
- row.push(void 0);
785
- }
786
- });
787
- while (out._index.length < out._values.length) {
788
- out._index.push("row" + out._index.length);
789
- }
790
- while (out._columns.length < maxRowLength) {
791
- out._columns.push("col" + out._columns.length);
792
- }
793
- return out;
794
- } else {
795
- const maxColLength = Math.max(df.shape[0], xShape[0]);
796
- const out = df.copy();
797
- range(0, maxColLength).forEach((i) => {
798
- if (i >= out._values.length) {
799
- out._values.push(ndarray(df.shape[1]));
800
- }
801
- out._values[i].push(x[i]);
802
- });
803
- while (out._index.length < out._values.length) {
804
- out._index.push("row" + out._index.length);
805
- }
806
- while (out._columns.length < out._values[0].length) {
807
- out._columns.push("col" + out._columns.length);
808
- }
809
- return out;
810
- }
811
- } else if (xShape.length === 2) {
812
- if (axis === 0) {
813
- const maxRowLength = Math.max(
814
- ...x.map((row) => row.length).concat([df.shape[1]])
815
- );
816
- const out = df.copy();
817
- out._values = out._values.concat(x).map((row) => {
818
- while (row.length < maxRowLength) {
819
- row.push(void 0);
820
- }
821
- return row;
822
- });
823
- while (out._index.length < out._values.length) {
824
- out._index.push("row" + out._index.length);
825
- }
826
- while (out._columns.length < maxRowLength) {
827
- out._columns.push("col" + out._columns.length);
828
- }
829
- return out;
830
- } else {
831
- const maxRowLength = Math.max(...x.map((row) => row.length)) + df.shape[1];
832
- const maxColLength = Math.max(df.shape[0], xShape[0]);
833
- const out = df.copy();
834
- range(0, maxColLength).forEach((i) => {
835
- if (i >= out._values.length) {
836
- out._values.push(ndarray(df.shape[1]));
837
- }
838
- out._values[i] = out._values[i].concat(x[i]);
839
- while (out._values[i].length < maxRowLength) {
840
- out._values[i].push(void 0);
841
- }
842
- });
843
- while (out._index.length < out._values.length) {
844
- out._index.push("row" + out._index.length);
845
- }
846
- while (out._columns.length < maxRowLength) {
847
- out._columns.push("col" + out._columns.length);
848
- }
849
- return out;
850
- }
851
- } else {
852
- throw new MathError(
853
- "Only 1- and 2-dimensional arrays can be appended to a DataFrame!"
854
- );
855
- }
856
- } else if (isSeries(x)) {
857
- const out = dfAppend(df, x.values, axis);
858
- if (axis === 0) {
859
- out.index[out.index.length - 1] = out.index.indexOf(x.name) > -1 ? x.name + " (2)" : x.name;
860
- } else {
861
- out.columns[out.columns.length - 1] = out.columns.indexOf(x.name) > -1 ? x.name + " (2)" : x.name;
862
- }
863
- return out;
864
- } else if (isDataFrame(x)) {
865
- if (axis === 0) {
866
- const out = df.copy();
867
- const maxRowLength = set(out._columns.concat(x._columns)).length;
868
- out._values.forEach((row) => {
869
- while (row.length < maxRowLength) {
870
- row.push(void 0);
871
- }
872
- });
873
- x.apply((row) => {
874
- const rowCopy = row.copy();
875
- const temp = [];
876
- out._columns.forEach((col) => {
877
- const index = rowCopy._index.indexOf(col);
878
- if (index > -1) {
879
- temp.push(rowCopy._values[index]);
880
- rowCopy._values.splice(index, 1);
881
- rowCopy._index.splice(index, 1);
882
- } else {
883
- temp.push(void 0);
884
- }
885
- });
886
- out._values.push(temp.concat(rowCopy._values));
887
- }, 1);
888
- out._columns = out._columns.concat(
889
- x._columns.filter((c) => out._columns.indexOf(c) < 0)
890
- );
891
- while (out._index.length < out._values.length) {
892
- const newRowName = "row" + out._index.length;
893
- out._index.push(
894
- newRowName + (df._index.indexOf(newRowName) > -1 ? " (2)" : "")
895
- );
896
- }
897
- return out;
898
- } else {
899
- const out = df.copy();
900
- out._index.forEach((rowName, i) => {
901
- const xIndex = x._index.indexOf(rowName);
902
- if (xIndex > -1) {
903
- out._values[i] = out._values[i].concat(x._values[xIndex]);
904
- } else {
905
- out._values[i] = out._values[i].concat(ndarray(x.shape[1]));
906
- }
907
- });
908
- x._index.forEach((rowName, i) => {
909
- const outIndex = out._index.indexOf(rowName);
910
- if (outIndex < 0) {
911
- out._index.push(rowName);
912
- out._values.push(ndarray(out._columns.length).concat(x._values[i]));
913
- }
914
- });
915
- out._columns = out._columns.concat(
916
- x._columns.map((c) => c + (out._columns.indexOf(c) > -1 ? " (2)" : ""))
917
- );
918
- return out;
919
- }
920
- } else {
921
- throw new MathError(
922
- "Only 1- or 2-dimensional arrays, Series, and DataFrames can be appended to a DataFrame!"
923
- );
924
- }
925
- }
926
-
927
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-apply.mjs
928
- function dfApply(DataFrame2, Series2, df, fn, axis) {
929
- axis = axis || 0;
930
- assert(
931
- isFunction(fn),
932
- "The first parameter to the `apply` method must be a function."
933
- );
934
- assert(
935
- axis === 0 || axis === 1,
936
- "The second parameter to the `apply` method (the `axis`) must be 0 or 1."
937
- );
938
- if (axis === 0) {
939
- const temp = {};
940
- let shouldReturnADataFrame;
941
- df.columns.forEach((colName, i) => {
942
- const series = new Series2(df.values.map((row) => row[i]));
943
- series.name = colName;
944
- series.index = df.index;
945
- const value = fn(series, i, df);
946
- if (value instanceof Series2) {
947
- temp[colName] = value.values;
948
- } else {
949
- temp[colName] = value;
950
- }
951
- if (isUndefined(shouldReturnADataFrame)) {
952
- shouldReturnADataFrame = value instanceof Series2 || isArray(value);
953
- }
954
- });
955
- if (shouldReturnADataFrame) {
956
- const out = new DataFrame2(temp);
957
- out.index = df.index;
958
- return out;
959
- } else {
960
- const out = new Series2(df.columns.map((colName) => temp[colName]));
961
- out.index = df.columns;
962
- return out;
963
- }
964
- } else if (axis === 1) {
965
- let shouldReturnADataFrame;
966
- const temp = df.values.map((row, i) => {
967
- const series = new Series2(row);
968
- series.name = df.index[i];
969
- series.index = df.columns;
970
- const value = fn(series, i, df);
971
- if (isUndefined(shouldReturnADataFrame)) {
972
- shouldReturnADataFrame = value instanceof Series2 || isArray(value);
973
- }
974
- if (value instanceof Series2) {
975
- return value.values;
976
- } else {
977
- return value;
978
- }
979
- });
980
- if (shouldReturnADataFrame) {
981
- const out = new DataFrame2(temp);
982
- out.index = df.index;
983
- out.columns = df.columns;
984
- return out;
985
- } else {
986
- const out = new Series2(temp);
987
- out.index = df.index;
988
- return out;
989
- }
990
- }
991
- }
992
-
993
- // node_modules/@jrc03c/js-math-tools/src/is-string.mjs
994
- function isString(s2) {
995
- return typeof s2 === "string";
996
- }
997
-
998
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-assign.mjs
999
- function dfAssign(DataFrame2, Series2, df, p1, p2) {
1000
- const isDataFrame2 = (x) => x instanceof DataFrame2;
1001
- const isSeries2 = (x) => x instanceof Series2;
1002
- if (!isUndefined(p2)) {
1003
- assert(
1004
- isString(p1),
1005
- "If passing two arguments into the `assign` method, then the first argument must be a string name!"
1006
- );
1007
- assert(
1008
- isArray(p2) && !isJagged(p2) && shape(p2).length === 1,
1009
- "If passing two arguments into the `assign` method, then the second argument must be a 1-dimensional array!"
1010
- );
1011
- const out = df.copy();
1012
- if (out.columns.includes(p1)) {
1013
- const index = out.columns.indexOf(p1);
1014
- out.columns[index] = p1;
1015
- out.values.forEach((v, i) => v[index] = p2[i]);
1016
- return out;
1017
- } else {
1018
- out._columns.push(p1);
1019
- out._values.forEach((v, i) => v.push(p2[i]));
1020
- return out;
1021
- }
1022
- } else {
1023
- if (isDataFrame2(p1)) {
1024
- const out = df.copy();
1025
- const outShape = out.shape;
1026
- const p1Shape = p1.shape;
1027
- for (let j = 0; j < p1Shape[1]; j++) {
1028
- const col = p1.columns[j];
1029
- const colNewIndex = out.columns.includes(col) ? out.columns.indexOf(col) : out.columns.length;
1030
- if (!out.columns.includes(col)) {
1031
- out._columns.push(col);
1032
- }
1033
- for (let i = 0; i < outShape[0]; i++) {
1034
- out._values[i][colNewIndex] = p1._values[i][j];
1035
- }
1036
- }
1037
- return out;
1038
- } else if (isSeries2(p1)) {
1039
- return df.assign(p1.name, p1.values);
1040
- } else if (isObject(p1)) {
1041
- return df.assign(new DataFrame2(p1));
1042
- } else {
1043
- throw new MathError(
1044
- "You must pass a DataFrame, Series, or object into the `assign` method!"
1045
- );
1046
- }
1047
- }
1048
- }
1049
-
1050
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-copy.mjs
1051
- function dfCopy(DataFrame2, df) {
1052
- if (df.isEmpty) return new DataFrame2();
1053
- const out = new DataFrame2(copy(df.values));
1054
- out.columns = df.columns.slice();
1055
- out.index = df.index.slice();
1056
- return out;
1057
- }
1058
-
1059
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop.mjs
1060
- function dfDrop(DataFrame2, Series2, df, rows, cols) {
1061
- if (isUndefined(rows)) rows = [];
1062
- if (isUndefined(cols)) cols = [];
1063
- if (isString(rows) || isNumber(rows)) rows = [rows];
1064
- if (isString(cols) || isNumber(cols)) cols = [cols];
1065
- assert(
1066
- isArray(rows),
1067
- "The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
1068
- );
1069
- assert(
1070
- isArray(cols),
1071
- "The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
1072
- );
1073
- assert(
1074
- shape(rows).length === 1,
1075
- "The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
1076
- );
1077
- assert(
1078
- shape(cols).length === 1,
1079
- "The `drop` method only works on 1-dimensional arrays of numerical indices and/or strings."
1080
- );
1081
- let outIndex, outColumns;
1082
- df.index.forEach((row, i) => {
1083
- if (rows.indexOf(row) < 0 && rows.indexOf(i) < 0) {
1084
- if (!outIndex) outIndex = [];
1085
- outIndex.push(row);
1086
- }
1087
- });
1088
- df.columns.forEach((col, i) => {
1089
- if (cols.indexOf(col) < 0 && cols.indexOf(i) < 0) {
1090
- if (!outColumns) outColumns = [];
1091
- outColumns.push(col);
1092
- }
1093
- });
1094
- let out = df.get(outIndex, outColumns);
1095
- if (out instanceof Series2) {
1096
- let temp = new DataFrame2();
1097
- temp = temp.assign(out);
1098
- if (df.index.indexOf(out.name) > -1) temp = temp.transpose();
1099
- out = temp;
1100
- }
1101
- return out;
1102
- }
1103
-
1104
- // node_modules/@jrc03c/js-math-tools/src/helpers/is-integer.mjs
1105
- function isInteger(x) {
1106
- return isNumber(x) && (x >= 0 ? Math.floor(x) === x : Math.ceil(x) === x);
1107
- }
1108
-
1109
- // node_modules/@jrc03c/js-math-tools/src/helpers/is-whole-number.mjs
1110
- function isWholeNumber(x) {
1111
- return isInteger(x) && x >= 0;
1112
- }
1113
-
1114
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop-missing.mjs
1115
- function dfDropMissing(DataFrame2, Series2, df, axis, condition, threshold) {
1116
- axis = axis || 0;
1117
- assert(
1118
- axis === 0 || axis === 1,
1119
- "The first parameter of the `dropMissing` method (the `axis`) must be 0 or 1."
1120
- );
1121
- threshold = threshold || 0;
1122
- assert(
1123
- isWholeNumber(threshold),
1124
- "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)."
1125
- );
1126
- condition = threshold > 0 ? "none" : condition || "any";
1127
- assert(
1128
- condition === "any" || condition === "all" || condition === "none",
1129
- "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)."
1130
- );
1131
- function helper4(values) {
1132
- if (threshold > 0) {
1133
- let count2 = 0;
1134
- for (let i = 0; i < values.length; i++) {
1135
- const value = values[i];
1136
- if (isUndefined(value)) count2++;
1137
- if (count2 >= threshold) return [];
1138
- }
1139
- } else if (condition === "any") {
1140
- for (let i = 0; i < values.length; i++) {
1141
- const value = values[i];
1142
- if (isUndefined(value)) return [];
1143
- }
1144
- } else if (condition === "all") {
1145
- for (let i = 0; i < values.length; i++) {
1146
- const value = values[i];
1147
- if (!isUndefined(value)) return values;
1148
- }
1149
- return [];
1150
- }
1151
- return values;
1152
- }
1153
- let out = df.copy();
1154
- const tempID = Math.random().toString();
1155
- if (axis === 0) {
1156
- out = out.assign(tempID, out.index);
1157
- const newValues = out.values.map(helper4).filter((row) => row.length > 0);
1158
- if (shape(newValues).length < 2) return new DataFrame2();
1159
- out.values = newValues;
1160
- let newIndex = out.get(null, tempID);
1161
- if (isUndefined(newIndex)) return new DataFrame2();
1162
- if (isString(newIndex)) newIndex = [newIndex];
1163
- if (newIndex instanceof Series2) newIndex = newIndex.values;
1164
- out.index = newIndex;
1165
- out = out.drop(null, tempID);
1166
- } else if (axis === 1) {
1167
- const temp = {};
1168
- out.columns.forEach((colName, i) => {
1169
- const values = out.values.map((row) => row[i]);
1170
- const newValues = helper4(values);
1171
- if (newValues.length > 0) {
1172
- temp[colName] = newValues;
1173
- }
1174
- });
1175
- if (Object.keys(temp).length + Object.getOwnPropertySymbols(temp).length === 0) {
1176
- return new DataFrame2();
1177
- }
1178
- const newOut = new DataFrame2(temp);
1179
- newOut.index = out.index;
1180
- return newOut;
1181
- }
1182
- return out;
1183
- }
1184
-
1185
- // node_modules/@jrc03c/js-math-tools/src/drop-nan.mjs
1186
- function dropNaN(x) {
1187
- if (isDataFrame(x) || isSeries(x)) {
1188
- return x.dropNaN(...Object.values(arguments).slice(1));
1189
- }
1190
- assert(
1191
- isArray(x),
1192
- "The `dropNaN` function only works on arrays, Series, and DataFrames!"
1193
- );
1194
- const out = [];
1195
- x.forEach((v) => {
1196
- try {
1197
- return out.push(dropNaN(v));
1198
- } catch (e) {
1199
- if (isNumber(v)) {
1200
- return out.push(v);
1201
- }
1202
- }
1203
- });
1204
- return out;
1205
- }
1206
-
1207
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-drop-nan.mjs
1208
- function dfDropNaN(DataFrame2, df, axis, condition, threshold) {
1209
- axis = axis || 0;
1210
- assert(
1211
- axis === 0 || axis === 1,
1212
- "The first parameter of the `dropNaN` method (the `axis`) must be 0 or 1."
1213
- );
1214
- threshold = threshold || 0;
1215
- assert(
1216
- isWholeNumber(threshold),
1217
- "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)."
1218
- );
1219
- condition = threshold > 0 ? "none" : condition || "any";
1220
- assert(
1221
- condition === "any" || condition === "all" || condition === "none",
1222
- "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)."
1223
- );
1224
- function helper4(values) {
1225
- const numericalValues = dropNaN(values);
1226
- if (threshold > 0) return values.length - numericalValues.length < threshold;
1227
- if (condition === "any") return numericalValues.length === values.length;
1228
- if (condition === "all") return numericalValues.length > 0;
1229
- return true;
1230
- }
1231
- const out = df.copy();
1232
- if (axis === 0) {
1233
- const rowsToKeep = out.index.filter((row) => {
1234
- const values = out.get(row, null).values;
1235
- return helper4(values);
1236
- });
1237
- if (rowsToKeep.length > 0) return out.get(rowsToKeep, null);
1238
- else return new DataFrame2();
1239
- } else if (axis === 1) {
1240
- const colsToKeep = out.columns.filter((col) => {
1241
- const values = out.get(null, col).values;
1242
- return helper4(values);
1243
- });
1244
- if (colsToKeep.length > 0) return out.get(null, colsToKeep);
1245
- else return new DataFrame2();
1246
- }
1247
- return out;
1248
- }
1249
-
1250
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-filter.mjs
1251
- function arrayToObject(x) {
1252
- const out = {};
1253
- flatten(x).forEach((value, i) => {
1254
- out[value] = i;
1255
- });
1256
- return out;
1257
- }
1258
- function undoArrayToObject(obj) {
1259
- return Object.keys(obj).concat(Object.getOwnPropertySymbols(obj)).sort((a, b) => obj[a] - obj[b]);
1260
- }
1261
- function dfFilter(DataFrame2, Series2, df, fn, axis) {
1262
- assert(
1263
- isFunction(fn),
1264
- "The `filter` method takes a single parameter: a function that is used to filter the values."
1265
- );
1266
- if (isUndefined(axis)) axis = 0;
1267
- assert(
1268
- axis === 0 || axis === 1,
1269
- "The `axis` parameter to the `filter` method must be 0 or 1."
1270
- );
1271
- let out = df.copy();
1272
- if (out.isEmpty) return out;
1273
- const index = arrayToObject(out.index);
1274
- const columns = arrayToObject(out.columns);
1275
- if (axis === 0) {
1276
- let count2 = 0;
1277
- const newValues = out.values.filter((row, i) => {
1278
- const series = new Series2(row);
1279
- series.name = df.index[i];
1280
- series.index = df.columns;
1281
- const shouldKeep = fn(series, i, df);
1282
- if (shouldKeep) {
1283
- count2++;
1284
- } else {
1285
- delete index[out.index[i]];
1286
- }
1287
- return shouldKeep;
1288
- });
1289
- if (count2 === 0) {
1290
- return new DataFrame2();
1291
- }
1292
- if (count2 === 1) {
1293
- const temp = new Series2(newValues[0]);
1294
- temp.name = undoArrayToObject(index)[0];
1295
- temp.index = undoArrayToObject(columns);
1296
- return temp;
1297
- }
1298
- out.values = newValues;
1299
- out.index = undoArrayToObject(index);
1300
- } else if (axis === 1) {
1301
- out = out.transpose();
1302
- let count2 = 0;
1303
- const newValues = out.values.filter((row, i) => {
1304
- const series = new Series2(row);
1305
- series.name = df.columns[i];
1306
- series.index = df.index;
1307
- const shouldKeep = fn(series, i, df);
1308
- if (shouldKeep) {
1309
- count2++;
1310
- } else {
1311
- delete columns[out.index[i]];
1312
- }
1313
- return shouldKeep;
1314
- });
1315
- if (count2 === 0) {
1316
- return new DataFrame2();
1317
- }
1318
- if (count2 === 1) {
1319
- const temp = new Series2(newValues[0]);
1320
- temp.name = undoArrayToObject(columns)[0];
1321
- temp.index = undoArrayToObject(index);
1322
- return temp;
1323
- }
1324
- out.values = newValues;
1325
- out.index = undoArrayToObject(columns);
1326
- out = out.transpose();
1327
- }
1328
- return out;
1329
- }
1330
-
1331
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-get.mjs
1332
- function dfGet(df, rows, cols) {
1333
- if (isString(rows) || isNumber(rows)) rows = [rows];
1334
- if (isString(cols) || isNumber(cols)) cols = [cols];
1335
- for (const i in rows) {
1336
- if (typeof rows[i] === "bigint") {
1337
- rows[i] = Number(rows[i]);
1338
- }
1339
- }
1340
- for (const i in cols) {
1341
- if (typeof cols[i] === "bigint") {
1342
- cols[i] = Number(cols[i]);
1343
- }
1344
- }
1345
- const types = set((rows || []).concat(cols || []).map((v) => typeof v));
1346
- assert(
1347
- types.length <= 2,
1348
- "Only whole numbers and/or strings are allowed in `get` arrays!"
1349
- );
1350
- if (types.length === 1) {
1351
- assert(
1352
- types[0] === "string" || types[0] === "number",
1353
- "Only whole numbers and/or strings are allowed in `get` arrays!"
1354
- );
1355
- }
1356
- if (types.length === 2) {
1357
- assert(
1358
- types.indexOf("string") > -1,
1359
- "Only whole numbers and/or strings are allowed in `get` arrays!"
1360
- );
1361
- assert(
1362
- types.indexOf("number") > -1,
1363
- "Only whole numbers and/or strings are allowed in `get` arrays!"
1364
- );
1365
- }
1366
- if (!isUndefined(rows)) {
1367
- rows = rows.map((r) => {
1368
- if (isString(r)) {
1369
- assert(df.index.indexOf(r) > -1, `Row "${r}" does not exist!`);
1370
- return r;
1371
- }
1372
- if (isNumber(r)) {
1373
- assert(r >= 0, `Index ${r} is out of bounds!`);
1374
- assert(Math.floor(r) === r, `Row numbers must be integers!`);
1375
- assert(r < df.index.length, `Index ${r} is out of bounds!`);
1376
- return df.index[r];
1377
- }
1378
- });
1379
- }
1380
- if (!isUndefined(cols)) {
1381
- cols = cols.map((c) => {
1382
- if (isString(c)) {
1383
- assert(df.columns.indexOf(c) > -1, `Column "${c}" does not exist!`);
1384
- return c;
1385
- }
1386
- if (isNumber(c)) {
1387
- assert(c >= 0, `Column ${c} is out of bounds!`);
1388
- assert(Math.floor(c) === c, `Column numbers must be integers!`);
1389
- assert(c < df.columns.length, `Column ${c} is out of bounds!`);
1390
- return df.columns[c];
1391
- }
1392
- });
1393
- }
1394
- return df.getSubsetByNames(rows, cols);
1395
- }
1396
-
1397
- // node_modules/@jrc03c/js-math-tools/src/sort.mjs
1398
- function alphaSort(a, b) {
1399
- try {
1400
- if (a < b) return -1;
1401
- if (a > b) return 1;
1402
- return 0;
1403
- } catch (e) {
1404
- a = typeof a === "object" && a !== null ? JSON.stringify(a) : a.toString();
1405
- b = typeof b === "object" && b !== null ? JSON.stringify(b) : b.toString();
1406
- if (a < b) return -1;
1407
- if (a > b) return 1;
1408
- return 0;
1409
- }
1410
- }
1411
- function sort(arr, fn) {
1412
- if (isUndefined(fn)) fn = alphaSort;
1413
- if (isDataFrame(arr) || isSeries(arr)) {
1414
- return arr.sort(...Object.values(arguments).slice(1));
1415
- }
1416
- assert(
1417
- isArray(arr),
1418
- "The `sort` function only works on arrays, Series, and DataFrames!"
1419
- );
1420
- assert(
1421
- isFunction(fn),
1422
- "The second parameter of the `sort` function must be a comparison function!"
1423
- );
1424
- const out = arr.slice();
1425
- out.sort(fn);
1426
- return out;
1427
- }
1428
-
1429
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-dummies.mjs
1430
- function camelify(text) {
1431
- const temp = text.toLowerCase();
1432
- let out = "";
1433
- for (let i = 0; i < temp.length; i++) {
1434
- const char = temp[i];
1435
- if (char.match(/[a-z0-9]/g)) {
1436
- out += char;
1437
- } else {
1438
- out += " ";
1439
- }
1440
- }
1441
- const words = out.split(" ").filter((word) => word.length > 0);
1442
- return words[0] + words.slice(1).map((word) => word[0].toUpperCase() + word.substring(1)).join("");
1443
- }
1444
- function dfGetDummies(DataFrame2, df, columns) {
1445
- if (isUndefined(columns)) {
1446
- columns = df.columns;
1447
- } else if (isString(columns)) {
1448
- columns = [columns];
1449
- }
1450
- const temp = {};
1451
- columns.forEach((col) => {
1452
- assert(
1453
- isString(col),
1454
- "You must pass either a string or a one-dimensional array of strings into the `getDummies` (AKA `oneHotEncode`) method!"
1455
- );
1456
- const colIndex = df.columns.indexOf(col);
1457
- assert(
1458
- colIndex > -1,
1459
- `The given DataFrame does not have a column called "${col}"!`
1460
- );
1461
- const values = df.values.map((row) => row[colIndex]);
1462
- const valuesSet = sort(set(values));
1463
- values.forEach((value) => {
1464
- valuesSet.forEach((orig) => {
1465
- const colName = col + "_" + camelify(orig.toString());
1466
- if (!temp[colName]) {
1467
- temp[colName] = [];
1468
- }
1469
- if (value === orig) {
1470
- temp[colName].push(1);
1471
- } else {
1472
- temp[colName].push(0);
1473
- }
1474
- });
1475
- });
1476
- });
1477
- const out = new DataFrame2(temp);
1478
- out.index = df.index;
1479
- return out;
1480
- }
1481
-
1482
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-subset-by-indices.mjs
1483
- function dfGetSubsetByIndices(df, rowIndices, colIndices) {
1484
- const dataShape = df.shape;
1485
- if (isUndefined(rowIndices)) rowIndices = range(0, dataShape[0]);
1486
- if (isUndefined(colIndices)) colIndices = range(0, dataShape[1]);
1487
- if (isNumber(rowIndices)) rowIndices = [rowIndices];
1488
- if (isNumber(colIndices)) colIndices = [colIndices];
1489
- assert(
1490
- isArray(rowIndices) && isArray(colIndices),
1491
- "The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
1492
- );
1493
- assert(
1494
- shape(rowIndices).length === 1 && shape(colIndices).length === 1,
1495
- "The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
1496
- );
1497
- assert(
1498
- rowIndices.length > 0,
1499
- "The `rowIndices` array must contain at least one index."
1500
- );
1501
- assert(
1502
- colIndices.length > 0,
1503
- "The `colIndices` array must contain at least one index."
1504
- );
1505
- rowIndices.forEach((rowIndex) => {
1506
- assert(
1507
- isWholeNumber(rowIndex),
1508
- "The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
1509
- );
1510
- assert(
1511
- rowIndex < df.index.length,
1512
- `The row index ${rowIndex} is out of bounds.`
1513
- );
1514
- });
1515
- colIndices.forEach((colIndex) => {
1516
- assert(
1517
- isWholeNumber(colIndex),
1518
- "The `rowIndices` and `colIndices` parameters must be 1-dimensional arrays of whole numbers."
1519
- );
1520
- assert(
1521
- colIndex < df.columns.length,
1522
- `The column index ${colIndex} is out of bounds.`
1523
- );
1524
- });
1525
- const rows = rowIndices.map((i) => df.index[i]);
1526
- const cols = colIndices.map((i) => df.columns[i]);
1527
- return df.getSubsetByNames(rows, cols);
1528
- }
1529
-
1530
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-get-subset-by-names.mjs
1531
- function dfGetSubsetByNames(DataFrame2, Series2, df, rows, cols) {
1532
- if (isUndefined(rows)) rows = df.index;
1533
- if (isUndefined(cols)) cols = df.columns;
1534
- if (isString(rows)) rows = [rows];
1535
- if (isString(cols)) cols = [cols];
1536
- assert(
1537
- isArray(rows) && isArray(cols),
1538
- "The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
1539
- );
1540
- assert(
1541
- shape(rows).length === 1 && shape(cols).length === 1,
1542
- "The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
1543
- );
1544
- assert(
1545
- rows.length > 0,
1546
- "The `rows` array must contain at least one row name."
1547
- );
1548
- assert(
1549
- cols.length > 0,
1550
- "The `cols` array must contain at least one column name."
1551
- );
1552
- rows.forEach((row) => {
1553
- assert(
1554
- isString(row),
1555
- "The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
1556
- );
1557
- assert(
1558
- df.index.indexOf(row) > -1,
1559
- `The row name "${row}" does not exist in the list of rows.`
1560
- );
1561
- });
1562
- cols.forEach((col) => {
1563
- assert(
1564
- isString(col),
1565
- "The `rows` and `cols` parameters must be 1-dimensional arrays of strings."
1566
- );
1567
- assert(
1568
- df.columns.indexOf(col) > -1,
1569
- `The column name "${col}" does not exist in the list of columns.`
1570
- );
1571
- });
1572
- const values = rows.map((row) => {
1573
- return cols.map((col) => {
1574
- return df.values[df.index.indexOf(row)][df.columns.indexOf(col)];
1575
- });
1576
- });
1577
- if (rows.length === 1 && cols.length === 1) {
1578
- return values[0][0];
1579
- }
1580
- if (rows.length === 1) {
1581
- const out2 = new Series2(values[0]);
1582
- out2.name = rows[0];
1583
- out2.index = cols;
1584
- return out2;
1585
- }
1586
- if (cols.length === 1) {
1587
- const out2 = new Series2(values.map((v) => v[0]));
1588
- out2.name = cols[0];
1589
- out2.index = rows;
1590
- return out2;
1591
- }
1592
- const out = new DataFrame2(values);
1593
- out.columns = cols;
1594
- out.index = rows;
1595
- return out;
1596
- }
1597
-
1598
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-print.mjs
1599
- function dfPrint(DataFrame2, Series2, df) {
1600
- function truncate(s2, maxLength2) {
1601
- if (isString(s2)) {
1602
- if (s2.length > maxLength2) {
1603
- return s2.substring(0, maxLength2 - 3) + "...";
1604
- } else {
1605
- return s2;
1606
- }
1607
- } else {
1608
- return s2;
1609
- }
1610
- }
1611
- if (df.isEmpty) {
1612
- console.table({});
1613
- console.log("Shape:", [0, 0], "\n");
1614
- return df;
1615
- }
1616
- const maxRows = typeof window === "undefined" ? 20 : 10;
1617
- const halfMaxRows = Math.floor(maxRows / 2);
1618
- const maxColumns = 4;
1619
- const halfMaxColumns = Math.floor(maxColumns / 2);
1620
- const tempRows = maxRows > df.index.length ? null : range(0, halfMaxRows).concat(
1621
- range(df.index.length - halfMaxRows, df.index.length)
1622
- );
1623
- const tempColumns = maxColumns > df.columns.length ? null : range(0, halfMaxColumns).concat(
1624
- range(df.columns.length - halfMaxColumns, df.columns.length)
1625
- );
1626
- let temp = df.get(tempRows, tempColumns);
1627
- if (temp instanceof Series2) {
1628
- if (df.shape[0] === 1) {
1629
- temp = new DataFrame2([temp.values]);
1630
- temp.index = df.index;
1631
- temp.columns = new Series2(df.columns).get(tempColumns).values;
1632
- } else if (df.shape[1] === 1) {
1633
- temp = new DataFrame2([temp.values]).transpose();
1634
- temp.index = new Series2(df.index).get(tempRows).values;
1635
- temp.columns = df.columns;
1636
- }
1637
- }
1638
- if (maxRows <= df.index.length) {
1639
- temp._index.splice(halfMaxRows, 0, "...");
1640
- temp._values.splice(
1641
- halfMaxRows,
1642
- 0,
1643
- range(0, temp.columns.length).map(() => "...")
1644
- );
1645
- }
1646
- if (maxColumns <= df.columns.length) {
1647
- temp._columns.splice(halfMaxColumns, 0, "...");
1648
- temp._values = temp._values.map((row) => {
1649
- row.splice(halfMaxColumns, 0, "...");
1650
- return row;
1651
- });
1652
- }
1653
- const maxLength = 28;
1654
- if (temp instanceof Series2) {
1655
- temp.values = temp.values.map((value) => truncate(value, maxLength));
1656
- temp.name = truncate(temp.name, maxLength);
1657
- temp.index = temp.index.map((row) => truncate(row, maxLength));
1658
- } else {
1659
- temp.values = temp.values.map((row) => {
1660
- return row.map((value) => truncate(value, maxLength));
1661
- });
1662
- temp.columns = temp.columns.map((col) => truncate(col, maxLength));
1663
- temp.index = temp.index.map((row) => truncate(row, maxLength));
1664
- }
1665
- console.table(temp.toDetailedObject());
1666
- console.log("Shape:", df.shape, "\n");
1667
- return df;
1668
- }
1669
-
1670
- // node_modules/@jrc03c/js-math-tools/src/helpers/left-pad.mjs
1671
- function leftPad(x, maxLength) {
1672
- assert(isNumber(x), "The `leftPad` function only works on numbers!");
1673
- let out = x.toString();
1674
- while (out.length < maxLength) out = "0" + out;
1675
- return out;
1676
- }
1677
-
1678
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-reset-index.mjs
1679
- function dfResetIndex(df, shouldSkipCopying) {
1680
- const out = shouldSkipCopying ? df : df.copy();
1681
- out.index = range(0, df.shape[0]).map((i) => {
1682
- return "row" + leftPad(i, (out.index.length - 1).toString().length);
1683
- });
1684
- return out;
1685
- }
1686
-
1687
- // node_modules/@jrc03c/js-math-tools/src/product.mjs
1688
- function product(arr, shouldDropNaNs) {
1689
- if (isDataFrame(arr) || isSeries(arr)) {
1690
- return product(arr.values, shouldDropNaNs);
1691
- }
1692
- assert(
1693
- isArray(arr),
1694
- "The `product` function only works on arrays, Series, and DataFrames!"
1695
- );
1696
- try {
1697
- if (arr.length === 0) return NaN;
1698
- const temp = flatten(arr);
1699
- let resultShouldBeABigInt = false;
1700
- let out = 1;
1701
- for (let v of temp) {
1702
- if (!isNumber(v)) {
1703
- if (shouldDropNaNs) {
1704
- v = 1;
1705
- } else {
1706
- return NaN;
1707
- }
1708
- }
1709
- if (typeof v === "bigint") {
1710
- resultShouldBeABigInt = true;
1711
- v = Number(v);
1712
- }
1713
- out *= v;
1714
- }
1715
- if (resultShouldBeABigInt) {
1716
- try {
1717
- return BigInt(out);
1718
- } catch (e) {
1719
- }
1720
- }
1721
- return out;
1722
- } catch (e) {
1723
- return NaN;
1724
- }
1725
- }
1726
-
1727
- // node_modules/@jrc03c/js-math-tools/src/helpers/is-natural-number.mjs
1728
- function isNaturalNumber(x) {
1729
- return isInteger(x) && x > 0;
1730
- }
1731
-
1732
- // node_modules/@jrc03c/js-math-tools/src/reshape.mjs
1733
- function reshape(x, newShape) {
1734
- if (isDataFrame(x) || isSeries(x)) {
1735
- return reshape(x.values, newShape);
1736
- }
1737
- assert(
1738
- isArray(x),
1739
- "The first argument passed into the `reshape` function must be an array!"
1740
- );
1741
- if (isNumber(newShape)) newShape = [newShape];
1742
- assert(
1743
- isArray(newShape),
1744
- "The second argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
1745
- );
1746
- assert(
1747
- shape(newShape).length === 1,
1748
- "The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
1749
- );
1750
- newShape = newShape.map((v) => {
1751
- if (typeof v === "bigint") {
1752
- v = Number(v);
1753
- }
1754
- assert(
1755
- isNaturalNumber(v),
1756
- "The first argument passed into the `reshape` function must be a whole number or a one-dimensional array of whole numbers!"
1757
- );
1758
- return Number(v);
1759
- });
1760
- if (newShape.length === 0) {
1761
- return flatten(x);
1762
- }
1763
- const temp = flatten(x);
1764
- if (newShape.length === 1 && newShape[0] === temp.length) {
1765
- return temp;
1766
- }
1767
- assert(
1768
- product(newShape) === temp.length,
1769
- "The new shape doesn't match the number of values available in `x` (the first argument passed into the `reshape` function)!"
1770
- );
1771
- const out = [];
1772
- const step = Math.floor(temp.length / newShape[0]);
1773
- for (let i = 0; i < newShape[0]; i++) {
1774
- const row = temp.slice(i * step, (i + 1) * step);
1775
- out.push(reshape(row, newShape.slice(1)));
1776
- }
1777
- return out;
1778
- }
1779
-
1780
- // node_modules/@jrc03c/js-math-tools/src/random.mjs
1781
- var MAX = Math.pow(2, 64);
1782
- var s = [];
1783
- seed(Math.floor(Math.random() * MAX));
1784
- function splitmix64(state, n) {
1785
- state = uint(state);
1786
- function helper4() {
1787
- state += uint("0x9e3779b97f4a7c15");
1788
- let z = copy(state);
1789
- z = (z ^ z >> BigInt(30)) * uint("0xbf58476d1ce4e5b9");
1790
- z = (z ^ z >> BigInt(27)) * uint("0x94d049bb133111eb");
1791
- return z ^ z >> BigInt(31);
1792
- }
1793
- const out = [];
1794
- for (let i = 0; i < n; i++) out.push(helper4());
1795
- return out;
1796
- }
1797
- function uint(x) {
1798
- return BigInt.asUintN(64, BigInt(x));
1799
- }
1800
- function rotl(x, k) {
1801
- x = uint(x);
1802
- k = BigInt(k);
1803
- return uint(uint(x << k) | uint(x >> uint(BigInt(64) - k)));
1804
- }
1805
- function seed(val) {
1806
- if (typeof val === "bigint") {
1807
- val = Number(val);
1808
- }
1809
- if (!isUndefined(val)) {
1810
- assert(
1811
- isNumber(val),
1812
- "If passing a value into the `seed` function, then that value must be an integer!"
1813
- );
1814
- const temp = splitmix64(Math.floor(val), 4);
1815
- s[0] = temp[0];
1816
- s[1] = temp[1];
1817
- s[2] = temp[2];
1818
- s[3] = temp[3];
1819
- } else {
1820
- return copy(s);
1821
- }
1822
- }
1823
- function next() {
1824
- const result = uint(rotl(s[0] + s[3], 23) + s[0]);
1825
- const t = uint(s[1] << BigInt(17));
1826
- s[2] = uint(s[2] ^ s[0]);
1827
- s[3] = uint(s[3] ^ s[1]);
1828
- s[1] = uint(s[1] ^ s[2]);
1829
- s[0] = uint(s[0] ^ s[3]);
1830
- s[2] = uint(s[2] ^ t);
1831
- s[3] = rotl(s[3], 45);
1832
- return Math.floor(Number(result)) / MAX;
1833
- }
1834
- function random(shape2) {
1835
- if (isUndefined(shape2)) return next();
1836
- if (!isArray(shape2)) shape2 = [shape2];
1837
- return reshape(ndarray(product(shape2)).map(next), shape2);
1838
- }
1839
-
1840
- // node_modules/@jrc03c/js-math-tools/src/shuffle.mjs
1841
- function shuffle(arr) {
1842
- if (isDataFrame(arr) || isSeries(arr)) {
1843
- return arr.shuffle(...Object.values(arguments).slice(1));
1844
- }
1845
- assert(
1846
- isArray(arr),
1847
- "The `shuffle` function only works on arrays, Series, and DataFrames!"
1848
- );
1849
- const out = [];
1850
- const temp = arr.slice();
1851
- for (let i = 0; i < arr.length; i++) {
1852
- const index = Math.floor(random() * temp.length);
1853
- out.push(temp.splice(index, 1)[0]);
1854
- }
1855
- return out;
1856
- }
1857
-
1858
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-shuffle.mjs
1859
- function dfShuffle(df, axis) {
1860
- if (isUndefined(axis)) axis = 0;
1861
- assert(
1862
- axis === 0 || axis === 1,
1863
- "The `axis` parameter to the `shuffle` must be 0, 1, or undefined."
1864
- );
1865
- return df.get(
1866
- axis === 0 ? shuffle(df.index) : null,
1867
- axis === 1 ? shuffle(df.columns) : null
1868
- );
1869
- }
1870
-
1871
- // node_modules/@jrc03c/js-math-tools/src/is-boolean.mjs
1872
- function isBoolean(x) {
1873
- return typeof x === "boolean";
1874
- }
1875
-
1876
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-sort.mjs
1877
- function dfSort(df, a, b) {
1878
- if (isFunction(a)) {
1879
- return dfSortByFunction(df, a, b);
1880
- } else {
1881
- return dfSortByColumns(df, a, b);
1882
- }
1883
- }
1884
- function dfSortByFunction(df, fn, axis) {
1885
- axis = isUndefined(axis) ? 0 : axis;
1886
- assert(
1887
- isFunction(fn),
1888
- "When sorting a DataFrame using a function, the first argument to the `sort` method must be a function!"
1889
- );
1890
- assert(
1891
- isNumber(axis),
1892
- "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."
1893
- );
1894
- if (axis === 0) {
1895
- const index = sort(df.index, (a, b) => {
1896
- return fn(df.get(a, null), df.get(b, null));
1897
- });
1898
- return df.get(index, null);
1899
- } else {
1900
- const columns = sort(df.columns, (a, b) => {
1901
- return fn(df.get(null, a), df.get(null, b));
1902
- });
1903
- return df.get(null, columns);
1904
- }
1905
- }
1906
- function dfSortByColumns(df, cols, directions) {
1907
- let out = df.copy();
1908
- const indexID = random().toString();
1909
- out = out.assign(indexID, out.index);
1910
- if (isUndefined(cols)) {
1911
- cols = [indexID];
1912
- directions = [true];
1913
- }
1914
- if (isNumber(cols) || isString(cols)) {
1915
- cols = [cols];
1916
- if (isBoolean(directions) || isString(directions)) directions = [directions];
1917
- }
1918
- assert(
1919
- isArray(cols),
1920
- "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."
1921
- );
1922
- assert(
1923
- shape(cols).length === 1,
1924
- "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."
1925
- );
1926
- if (isUndefined(directions))
1927
- directions = range(0, cols.length).map(() => true);
1928
- assert(
1929
- isArray(directions),
1930
- "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."
1931
- );
1932
- assert(
1933
- shape(directions).length === 1,
1934
- "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."
1935
- );
1936
- assert(
1937
- cols.length === directions.length,
1938
- "The arrays passed into the `sort` method must be equal in length."
1939
- );
1940
- cols = cols.map((col) => {
1941
- assert(
1942
- isString(col) || isNumber(col),
1943
- "Column references can either be column names (as strings) or column indices (as whole numbers)."
1944
- );
1945
- if (isString(col)) {
1946
- const index = out.columns.indexOf(col);
1947
- assert(index > -1, `The column "${col}" does not exist!`);
1948
- return index;
1949
- }
1950
- if (isNumber(col)) {
1951
- assert(isWholeNumber(col), "Column indices must be whole numbers!");
1952
- assert(col < out.columns.length, `The index ${col} is out of bounds!`);
1953
- return col;
1954
- }
1955
- });
1956
- directions = directions.map((dir) => {
1957
- assert(
1958
- isString(dir) || isBoolean(dir),
1959
- "Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."
1960
- );
1961
- if (isString(dir)) {
1962
- const value = dir.trim().toLowerCase();
1963
- assert(
1964
- value === "ascending" || value === "descending",
1965
- "Direction references can either be strings ('ascending' or 'descending') or booleans (true or false)."
1966
- );
1967
- return value === "ascending";
1968
- }
1969
- if (isBoolean(dir)) {
1970
- return dir;
1971
- }
1972
- });
1973
- out.values = sort(out.values, (a, b) => {
1974
- let counter = 0;
1975
- while (a[cols[counter]] === b[cols[counter]] && counter < cols.length) {
1976
- counter++;
1977
- }
1978
- const isAscending = directions[counter];
1979
- if (a[cols[counter]] === b[cols[counter]]) return 0;
1980
- if (a[cols[counter]] < b[cols[counter]]) return isAscending ? -1 : 1;
1981
- if (a[cols[counter]] > b[cols[counter]]) return isAscending ? 1 : -1;
1982
- });
1983
- const indexNumber = out.columns.indexOf(indexID);
1984
- out.index = out.values.map((row) => row[indexNumber]);
1985
- out = out.dropColumns(indexID);
1986
- return out;
1987
- }
1988
-
1989
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-detailed-object.mjs
1990
- function dfToDetailedObject(df, axis) {
1991
- if (isUndefined(axis)) {
1992
- axis = 0;
1993
- } else {
1994
- assert(
1995
- axis === 0 || axis === 1,
1996
- "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."
1997
- );
1998
- }
1999
- const out = {};
2000
- if (axis === 0) {
2001
- df.index.forEach((rowName, i) => {
2002
- const temp = {};
2003
- df.columns.forEach((colName, j) => {
2004
- temp[colName] = df.values[i][j];
2005
- });
2006
- out[rowName] = temp;
2007
- });
2008
- } else {
2009
- df.columns.forEach((colName, j) => {
2010
- const temp = {};
2011
- df.index.forEach((rowName, i) => {
2012
- temp[rowName] = df.values[i][j];
2013
- });
2014
- out[colName] = temp;
2015
- });
2016
- }
2017
- return out;
2018
- }
2019
-
2020
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-json-string.mjs
2021
- function dfToJSONString(df, axis) {
2022
- return JSON.stringify(df.toObject(axis));
2023
- }
2024
-
2025
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-json.mjs
2026
- async function dfToJSON(df, axis) {
2027
- return JSON.parse(dfToJSONString(df, axis));
2028
- }
2029
-
2030
- // node_modules/@jrc03c/js-math-tools/src/dataframe/df-to-object.mjs
2031
- function dfToObject(df) {
2032
- const out = {};
2033
- df.columns.forEach((col) => {
2034
- out[col] = df.get(col).values;
2035
- });
2036
- return out;
2037
- }
2038
-
2039
- // node_modules/@jrc03c/js-math-tools/src/transpose.mjs
2040
- function transpose(arr) {
2041
- if (isDataFrame(arr) || isSeries(arr)) {
2042
- return arr.transpose();
2043
- }
2044
- assert(
2045
- isArray(arr),
2046
- "The `transpose` function only works on arrays, Series, and DataFrames!"
2047
- );
2048
- const theShape = shape(arr);
2049
- assert(
2050
- theShape.length <= 2,
2051
- "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!"
2052
- );
2053
- if (theShape.length === 1) {
2054
- return reverse(arr);
2055
- } else if (theShape.length === 2) {
2056
- const out = ndarray(reverse(theShape));
2057
- for (let row = 0; row < theShape[0]; row++) {
2058
- for (let col = 0; col < theShape[1]; col++) {
2059
- out[col][row] = arr[row][col];
2060
- }
2061
- }
2062
- return out;
2063
- }
2064
- }
2065
-
2066
- // node_modules/@jrc03c/js-math-tools/src/series/series-append.mjs
2067
- function seriesAppend(Series2, series, x) {
2068
- if (isSeries(x)) {
2069
- return new Series2(series.values.concat(x.values));
2070
- }
2071
- if (isArray(x)) {
2072
- const xShape = shape(x);
2073
- assert(
2074
- xShape.length === 1 && !isNested(xShape),
2075
- "Only vectors can be appended to Series!"
2076
- );
2077
- const out = series.copy();
2078
- x.forEach((v, i) => {
2079
- out._values.push(v);
2080
- out._index.push("item" + (series.values.length + i));
2081
- });
2082
- return out;
2083
- }
2084
- return seriesAppend(series, [x]);
2085
- }
2086
-
2087
- // node_modules/@jrc03c/js-math-tools/src/series/series-apply.mjs
2088
- function seriesApply(series, fn) {
2089
- assert(
2090
- isFunction(fn),
2091
- "The parameter to the `apply` method must be a function."
2092
- );
2093
- const out = series.copy();
2094
- out._values = out._values.map((v, i) => fn(v, i));
2095
- return out;
2096
- }
2097
-
2098
- // node_modules/@jrc03c/js-math-tools/src/series/series-drop-missing.mjs
2099
- function seriesDropMissing(series) {
2100
- const out = series.copy();
2101
- const outIndex = [];
2102
- out._values = out.values.filter((v, i) => {
2103
- if (isUndefined(v)) {
2104
- return false;
2105
- } else {
2106
- outIndex.push(out.index[i]);
2107
- return true;
2108
- }
2109
- });
2110
- out._index = outIndex;
2111
- return out;
2112
- }
2113
-
2114
- // node_modules/@jrc03c/js-math-tools/src/series/series-drop-nan.mjs
2115
- function seriesDropNaN(Series2, series) {
2116
- const index = [];
2117
- const values = [];
2118
- series.values.forEach((value, i) => {
2119
- if (isNumber(value)) {
2120
- values.push(value);
2121
- index.push(series.index[i]);
2122
- }
2123
- });
2124
- const out = new Series2(values);
2125
- out.name = series.name;
2126
- out.index = index;
2127
- return out;
2128
- }
2129
-
2130
- // node_modules/@jrc03c/js-math-tools/src/series/series-filter.mjs
2131
- function seriesFilter(Series2, series, fn) {
2132
- let out = series.copy();
2133
- const index = copy(out.index);
2134
- const indicesToRemove = [];
2135
- const newValues = out.values.filter((value, i) => {
2136
- const shouldKeep = fn(value, i, out.values);
2137
- if (!shouldKeep) indicesToRemove.push(out.index[i]);
2138
- return shouldKeep;
2139
- });
2140
- indicesToRemove.forEach((i) => {
2141
- index.splice(index.indexOf(i), 1);
2142
- });
2143
- if (newValues.length === 0) {
2144
- out = new Series2();
2145
- out.name = series.name;
2146
- return out;
2147
- }
2148
- out.values = newValues;
2149
- out.index = index;
2150
- return out;
2151
- }
2152
-
2153
- // node_modules/@jrc03c/js-math-tools/src/series/series-get.mjs
2154
- function seriesGet(series, indices) {
2155
- if (isString(indices) || isNumber(indices)) indices = [indices];
2156
- for (const i in indices) {
2157
- if (typeof indices[i] === "bigint") {
2158
- indices[i] = Number(indices[i]);
2159
- }
2160
- }
2161
- const types = set((indices || []).map((v) => typeof v));
2162
- assert(
2163
- types.length <= 2,
2164
- "Only whole numbers and/or strings are allowed in `get` arrays!"
2165
- );
2166
- if (types.length === 1) {
2167
- assert(
2168
- types[0] === "string" || types[0] === "number",
2169
- "Only whole numbers and/or strings are allowed in `get` arrays!"
2170
- );
2171
- }
2172
- if (types.length === 2) {
2173
- assert(
2174
- types.indexOf("string") > -1,
2175
- "Only whole numbers and/or strings are allowed in `get` arrays!"
2176
- );
2177
- assert(
2178
- types.indexOf("number") > -1,
2179
- "Only whole numbers and/or strings are allowed in `get` arrays!"
2180
- );
2181
- }
2182
- if (!isUndefined(indices)) {
2183
- indices = indices.map((i) => {
2184
- if (typeof i === "string") {
2185
- assert(series.index.indexOf(i) > -1, `Index "${i}" does not exist!`);
2186
- return i;
2187
- }
2188
- if (typeof i === "number") {
2189
- assert(i >= 0, `Index ${i} is out of bounds!`);
2190
- assert(Math.floor(i) === i, `Indices must be integers!`);
2191
- assert(i < series.index.length, `Index ${i} is out of bounds!`);
2192
- return series.index[i];
2193
- }
2194
- });
2195
- }
2196
- return series.getSubsetByNames(indices);
2197
- }
2198
-
2199
- // node_modules/@jrc03c/js-math-tools/src/series/series-get-subset-by-indices.mjs
2200
- function seriesGetSubsetByIndices(series, indices) {
2201
- const dataShape = series.shape;
2202
- if (isUndefined(indices)) indices = range(0, dataShape[0]);
2203
- assert(
2204
- isArray(indices),
2205
- "The `indices` array must be 1-dimensional array of whole numbers."
2206
- );
2207
- assert(
2208
- shape(indices).length === 1,
2209
- "The `indices` array must be a 1-dimensional array of whole numbers."
2210
- );
2211
- assert(
2212
- indices.length > 0,
2213
- "The `indices` array must contain at least one index."
2214
- );
2215
- indices.forEach((index) => {
2216
- assert(
2217
- isWholeNumber(index),
2218
- "The `indices` array must be a 1-dimensional array of whole numbers."
2219
- );
2220
- assert(
2221
- index < series.index.length,
2222
- `The row index ${index} is out of bounds.`
2223
- );
2224
- });
2225
- const rows = indices.map((i) => series.index[i]);
2226
- return series.getSubsetByNames(rows);
2227
- }
2228
-
2229
- // node_modules/@jrc03c/js-math-tools/src/series/series-get-subset-by-names.mjs
2230
- function seriesGetSubsetByNames(Series2, series, indices) {
2231
- if (isUndefined(indices)) indices = series.index;
2232
- assert(
2233
- isArray(indices),
2234
- "The `indices` array must be a 1-dimensional array of strings."
2235
- );
2236
- assert(
2237
- shape(indices).length === 1,
2238
- "The `indices` array must be a 1-dimensional array of strings."
2239
- );
2240
- assert(
2241
- indices.length > 0,
2242
- "The `indices` array must contain at least one index name."
2243
- );
2244
- indices.forEach((name) => {
2245
- assert(isString(name), "The `indices` array must contain only strings.");
2246
- assert(
2247
- series.index.indexOf(name) > -1,
2248
- `The name "${name}" does not exist in the index.`
2249
- );
2250
- });
2251
- const values = indices.map((name) => {
2252
- return series.values[series.index.indexOf(name)];
2253
- });
2254
- if (values.length === 1) return values[0];
2255
- const out = new Series2(values);
2256
- out.index = indices;
2257
- out.name = series.name;
2258
- return out;
2259
- }
2260
-
2261
- // node_modules/@jrc03c/js-math-tools/src/series/series-print.mjs
2262
- function seriesPrint(series) {
2263
- let temp = series.copy();
2264
- const maxRows = typeof window === "undefined" ? 20 : 10;
2265
- if (temp.index.length > maxRows) {
2266
- temp = temp.get(
2267
- range(0, maxRows / 2).concat(
2268
- range(temp.index.length - maxRows / 2, temp.index.length)
2269
- )
2270
- );
2271
- const tempIndex = copy(temp.index);
2272
- tempIndex.splice(Math.floor(tempIndex.length / 2), 0, "...");
2273
- temp.values.push("...");
2274
- temp.index.push("...");
2275
- temp = temp.get(tempIndex);
2276
- }
2277
- const out = {};
2278
- temp.values.forEach((value, i) => {
2279
- const obj = {};
2280
- obj[temp.name] = value;
2281
- out[temp.index[i]] = obj;
2282
- });
2283
- console.table(out);
2284
- console.log("Shape:", series.shape, "\n");
2285
- return series;
2286
- }
2287
-
2288
- // node_modules/@jrc03c/js-math-tools/src/series/series-shuffle.mjs
2289
- function seriesShuffle(series) {
2290
- const out = series.copy();
2291
- return out.get(shuffle(out.index));
2292
- }
2293
-
2294
- // node_modules/@jrc03c/js-math-tools/src/series/series-sort.mjs
2295
- function seriesSort(Series2, series, fn) {
2296
- fn = fn || ((a, b) => a < b ? -1 : 1);
2297
- assert(
2298
- isUndefined(fn) || isFunction(fn),
2299
- "You must pass undefined, null, or a comparison function as the second argument to the `sort` method!"
2300
- );
2301
- const pairs = transpose([series.values, series.index]);
2302
- const temp = sort(pairs, (aPair, bPair) => {
2303
- return fn(aPair[0], bPair[0]);
2304
- });
2305
- const newValues = [];
2306
- const newIndex = [];
2307
- temp.forEach((pair) => {
2308
- newValues.push(pair[0]);
2309
- newIndex.push(pair[1]);
2310
- });
2311
- const out = new Series2();
2312
- out._values = newValues;
2313
- out._index = newIndex;
2314
- out.name = series.name;
2315
- return out;
2316
- }
2317
-
2318
- // node_modules/@jrc03c/js-math-tools/src/series/series-sort-by-index.mjs
2319
- function seriesSortByIndex(Series2, series) {
2320
- let temp = transpose([series.values, series.index]);
2321
- temp = transpose(
2322
- sort(temp, (a, b) => {
2323
- if (a[1] === b[1]) return 0;
2324
- if (a[1] < b[1]) return -1;
2325
- if (a[1] > b[1]) return 1;
2326
- })
2327
- );
2328
- const out = new Series2(temp[0]);
2329
- out.index = temp[1];
2330
- out.name = series.name;
2331
- return out;
2332
- }
2333
-
2334
- // node_modules/@jrc03c/js-math-tools/src/series/series-to-object.mjs
2335
- function seriesToObject(series) {
2336
- const out = {};
2337
- out[series.name] = {};
2338
- series.index.forEach((index, i) => {
2339
- out[series.name][index] = series.values[i];
2340
- });
2341
- return out;
2342
- }
2343
-
2344
- // node_modules/@jrc03c/js-math-tools/src/series/index.mjs
2345
- var SERIES_SYMBOL = Symbol.for("@jrc03c/js-math-tools/series");
2346
- function createSeriesClass(DataFrame2) {
2347
- class Series2 {
2348
- static [Symbol.hasInstance](x) {
2349
- try {
2350
- return !!x._symbol && x._symbol === SERIES_SYMBOL;
2351
- } catch (e) {
2352
- return false;
2353
- }
2354
- }
2355
- constructor(data) {
2356
- this.name = "data";
2357
- Object.defineProperty(this, "_symbol", {
2358
- configurable: false,
2359
- enumerable: false,
2360
- writable: false,
2361
- value: SERIES_SYMBOL
2362
- });
2363
- Object.defineProperty(this, "_values", {
2364
- value: [],
2365
- configurable: true,
2366
- enumerable: false,
2367
- writable: true
2368
- });
2369
- Object.defineProperty(this, "values", {
2370
- configurable: true,
2371
- enumerable: true,
2372
- get() {
2373
- return this._values;
2374
- },
2375
- set(x) {
2376
- assert(isArray(x), "The new values must be a 1-dimensional array!");
2377
- const dataShape = shape(x);
2378
- assert(
2379
- dataShape.length === 1,
2380
- "The new array of values must be 1-dimensional!"
2381
- );
2382
- if (dataShape[0] < this._index.length) {
2383
- this._index = this._index.slice(0, dataShape[0]);
2384
- } else if (dataShape[0] > this._index.length) {
2385
- this._index = this._index.concat(
2386
- range(this._index.length, dataShape[0]).map((i) => {
2387
- return "item" + leftPad(i, (x.length - 1).toString().length);
2388
- })
2389
- );
2390
- }
2391
- this._values = x;
2392
- }
2393
- });
2394
- Object.defineProperty(this, "_index", {
2395
- value: [],
2396
- configurable: true,
2397
- enumerable: false,
2398
- writable: true
2399
- });
2400
- Object.defineProperty(this, "index", {
2401
- configurable: true,
2402
- enumerable: true,
2403
- get() {
2404
- return this._index;
2405
- },
2406
- set(x) {
2407
- assert(
2408
- isArray(x),
2409
- "The new index must be a 1-dimensional array of strings!"
2410
- );
2411
- assert(
2412
- x.length === this.shape[0],
2413
- "The new index must be the same length as the old index!"
2414
- );
2415
- assert(
2416
- shape(x).length === 1,
2417
- "The new index must be a 1-dimensional array of strings!"
2418
- );
2419
- x.forEach((value) => {
2420
- assert(isString(value), "All of the row names must be strings!");
2421
- });
2422
- this._index = x;
2423
- }
2424
- });
2425
- if (data) {
2426
- if (data instanceof Series2) {
2427
- this.name = data.name;
2428
- this.values = copy(data.values);
2429
- this.index = copy(data.index);
2430
- } else if (isArray(data)) {
2431
- const dataShape = shape(data);
2432
- assert(
2433
- dataShape.length === 1,
2434
- "When passing an array into the constructor of a Series, the array must be 1-dimensional!"
2435
- );
2436
- this.values = data;
2437
- } else if (data instanceof Object) {
2438
- const keys = Object.keys(data).concat(Object.getOwnPropertySymbols(data)).map((v) => v.toString());
2439
- assert(
2440
- keys.length === 1,
2441
- "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!"
2442
- );
2443
- const name = keys[0];
2444
- const values = data[name];
2445
- assert(
2446
- shape(values).length === 1,
2447
- "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!"
2448
- );
2449
- this.name = name;
2450
- this.values = values.slice();
2451
- }
2452
- }
2453
- }
2454
- get shape() {
2455
- return shape(this.values);
2456
- }
2457
- get length() {
2458
- return this.shape[0];
2459
- }
2460
- get isEmpty() {
2461
- return this.values.filter((v) => !isUndefined(v)).length === 0;
2462
- }
2463
- clear() {
2464
- const out = this.copy();
2465
- out.values.forEach((v, i) => {
2466
- out.values[i] = void 0;
2467
- });
2468
- return out;
2469
- }
2470
- get(indices) {
2471
- return seriesGet(this, indices);
2472
- }
2473
- getSubsetByNames(indices) {
2474
- return seriesGetSubsetByNames(Series2, this, indices);
2475
- }
2476
- getSubsetByIndices(indices) {
2477
- return seriesGetSubsetByIndices(this, indices);
2478
- }
2479
- loc(indices) {
2480
- return this.getSubsetByNames(indices);
2481
- }
2482
- iloc(indices) {
2483
- return this.getSubsetByIndices(indices);
2484
- }
2485
- reverse() {
2486
- const out = new Series2(reverse(this.values));
2487
- out.index = reverse(this.index);
2488
- out.name = this.name;
2489
- return out;
2490
- }
2491
- resetIndex() {
2492
- const out = this.copy();
2493
- out.index = range(0, this.shape[0]).map((i) => {
2494
- return "item" + leftPad(i, (out.index.length - 1).toString().length);
2495
- });
2496
- return out;
2497
- }
2498
- copy() {
2499
- const out = new Series2();
2500
- out._values = copy(this.values);
2501
- out._index = copy(this.index);
2502
- out.name = this.name;
2503
- return out;
2504
- }
2505
- append(x) {
2506
- return seriesAppend(Series2, this, x);
2507
- }
2508
- apply(fn) {
2509
- return seriesApply(this, fn);
2510
- }
2511
- concat(x) {
2512
- return this.append(x);
2513
- }
2514
- dropMissing(condition, threshold) {
2515
- return seriesDropMissing(this, condition, threshold);
2516
- }
2517
- dropNaN() {
2518
- return seriesDropNaN(Series2, this);
2519
- }
2520
- toObject() {
2521
- return seriesToObject(this);
2522
- }
2523
- print() {
2524
- return seriesPrint(this);
2525
- }
2526
- shuffle() {
2527
- return seriesShuffle(this);
2528
- }
2529
- sort(direction) {
2530
- return seriesSort(Series2, this, direction);
2531
- }
2532
- sortByIndex() {
2533
- return seriesSortByIndex(Series2, this);
2534
- }
2535
- filter(fn) {
2536
- return seriesFilter(Series2, this, fn);
2537
- }
2538
- toDataFrame() {
2539
- const out = new DataFrame2(transpose([this.values]));
2540
- out.columns = [this.name];
2541
- out.index = this.index;
2542
- return out;
2543
- }
2544
- transpose() {
2545
- const out = this.copy();
2546
- out.values = reverse(out.values);
2547
- out.index = reverse(out.index);
2548
- return out;
2549
- }
2550
- getDummies() {
2551
- return this.toDataFrame().getDummies();
2552
- }
2553
- oneHotEncode() {
2554
- return this.getDummies();
2555
- }
2556
- }
2557
- return Series2;
2558
- }
2559
-
2560
- // node_modules/@jrc03c/js-math-tools/src/dataframe/index.mjs
2561
- var DATAFRAME_SYMBOL = Symbol.for("@jrc03c/js-math-tools/dataframe");
2562
- function makeKey3(n) {
2563
- const alpha = "abcdefghijklmnopqrstuvwxyz1234567890";
2564
- let out = "";
2565
- for (let i = 0; i < n; i++) out += alpha[Math.floor(random() * alpha.length)];
2566
- return out;
2567
- }
2568
- var DataFrame = class _DataFrame {
2569
- static [Symbol.hasInstance](x) {
2570
- try {
2571
- return !!x._symbol && x._symbol === DATAFRAME_SYMBOL;
2572
- } catch (e) {
2573
- return false;
2574
- }
2575
- }
2576
- constructor(data) {
2577
- Object.defineProperty(this, "_symbol", {
2578
- configurable: false,
2579
- enumerable: false,
2580
- writable: false,
2581
- value: DATAFRAME_SYMBOL
2582
- });
2583
- Object.defineProperty(this, "_values", {
2584
- value: [],
2585
- configurable: true,
2586
- enumerable: false,
2587
- writable: true
2588
- });
2589
- Object.defineProperty(this, "values", {
2590
- configurable: true,
2591
- enumerable: true,
2592
- get() {
2593
- if (this._values.length === 0 || !isUndefined(this._values[0]) && this._values[0].length === 0) {
2594
- return [[]];
2595
- }
2596
- return this._values;
2597
- },
2598
- set(x) {
2599
- assert(isArray(x), "The new values must be a 2-dimensional array!");
2600
- const dataShape = shape(x);
2601
- assert(
2602
- dataShape.length === 2,
2603
- "The new array of values must be 2-dimensional!"
2604
- );
2605
- if (dataShape[0] < this._index.length) {
2606
- this._index = this._index.slice(0, dataShape[0]);
2607
- } else if (dataShape[0] > this._index.length) {
2608
- this._index = this._index.concat(
2609
- range(this._index.length, dataShape[0]).map((i) => {
2610
- return "row" + leftPad(i, (dataShape[0] - 1).toString().length);
2611
- })
2612
- );
2613
- }
2614
- if (dataShape[1] < this._columns.length) {
2615
- this._columns = this._columns.slice(0, dataShape[1]);
2616
- } else if (dataShape[1] > this._columns.length) {
2617
- this._columns = this._columns.concat(
2618
- range(this._columns.length, dataShape[1]).map((i) => {
2619
- return "col" + leftPad(i, (dataShape[1] - 1).toString().length);
2620
- })
2621
- );
2622
- }
2623
- this._values = x;
2624
- }
2625
- });
2626
- Object.defineProperty(this, "_columns", {
2627
- value: [],
2628
- configurable: true,
2629
- enumerable: false,
2630
- writable: true
2631
- });
2632
- Object.defineProperty(this, "columns", {
2633
- configurable: true,
2634
- enumerable: true,
2635
- get() {
2636
- return this._columns;
2637
- },
2638
- set(x) {
2639
- assert(
2640
- isArray(x),
2641
- "The new columns list must be a 1-dimensional array of strings!"
2642
- );
2643
- assert(
2644
- this.isEmpty || x.length === this.shape[1],
2645
- "The new columns list must be the same length as the old columns list!"
2646
- );
2647
- assert(
2648
- shape(x).length === 1,
2649
- "The new columns list must be a 1-dimensional array of strings!"
2650
- );
2651
- x = x.map((v) => {
2652
- if (typeof v !== "string") {
2653
- v = JSON.stringify(v) || v.toString();
2654
- }
2655
- if (v.trim().length === 0) {
2656
- return "untitled_" + makeKey3(8);
2657
- }
2658
- return v.trim();
2659
- });
2660
- const counts = (() => {
2661
- const temp = count(x);
2662
- const out = {};
2663
- temp.values.forEach((v) => {
2664
- out[v] = temp.get(v);
2665
- });
2666
- return out;
2667
- })();
2668
- x = x.map((v) => {
2669
- if (counts[v] > 1) {
2670
- return v + "_" + makeKey3(8);
2671
- }
2672
- return v;
2673
- });
2674
- this._columns = x;
2675
- }
2676
- });
2677
- Object.defineProperty(this, "_index", {
2678
- value: [],
2679
- configurable: true,
2680
- enumerable: false,
2681
- writable: true
2682
- });
2683
- Object.defineProperty(this, "index", {
2684
- configurable: true,
2685
- enumerable: true,
2686
- get() {
2687
- return this._index;
2688
- },
2689
- set(x) {
2690
- assert(
2691
- isArray(x),
2692
- "The new index must be a 1-dimensional array of strings!"
2693
- );
2694
- assert(
2695
- this.isEmpty || x.length === this.shape[0],
2696
- "The new index must be the same length as the old index!"
2697
- );
2698
- assert(
2699
- shape(x).length === 1,
2700
- "The new index must be a 1-dimensional array of strings!"
2701
- );
2702
- x = x.map((v) => {
2703
- if (typeof v !== "string") {
2704
- v = JSON.stringify(v) || v.toString();
2705
- }
2706
- if (v.trim().length === 0) {
2707
- return "untitled_" + makeKey3(8);
2708
- }
2709
- return v.trim();
2710
- });
2711
- const counts = (() => {
2712
- const temp = count(x);
2713
- const out = {};
2714
- temp.values.forEach((v) => {
2715
- out[v] = temp.get(v);
2716
- });
2717
- return out;
2718
- })();
2719
- x = x.map((v) => {
2720
- if (counts[v] > 1) {
2721
- return v + "_" + makeKey3(8);
2722
- }
2723
- return v;
2724
- });
2725
- this._index = x;
2726
- }
2727
- });
2728
- assert(
2729
- isUndefined(data) || isObject(data) || isArray(data),
2730
- "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."
2
+ // src/index.mjs
3
+ function makeKey(keyLength, charset, randomFn) {
4
+ if (typeof keyLength !== "number" || isNaN(keyLength)) {
5
+ throw new Error(
6
+ "The first value passed into the `makeKey` function must be a number!"
2731
7
  );
2732
- if (data) {
2733
- if (data instanceof _DataFrame) {
2734
- this.values = copy(data.values);
2735
- this.columns = copy(data.columns);
2736
- this.index = copy(data.index);
2737
- } else if (isArray(data)) {
2738
- const dataShape = shape(data);
2739
- assert(
2740
- dataShape.length === 2,
2741
- "The `data` array passed into the constructor of a DataFrame must be 2-dimensional!"
2742
- );
2743
- assert(
2744
- !isJagged(data),
2745
- "The 2-dimensional array passed into the constructor of a DataFrame must not contain sub-arrays (i.e., rows) of different lengths!"
2746
- );
2747
- this.values = data;
2748
- } else {
2749
- this._columns = Object.keys(data).concat(Object.getOwnPropertySymbols(data)).map((v) => v.toString());
2750
- const temp = [];
2751
- let lastColName = null;
2752
- let lastColLength = null;
2753
- this._columns.forEach((col) => {
2754
- if (isUndefined(lastColLength)) {
2755
- lastColName = col;
2756
- lastColLength = data[col].length;
2757
- }
2758
- assert(
2759
- data[col].length === lastColLength,
2760
- `The object passed into the DataFrame constructor contains arrays of different lengths! The key "${lastColName}" points to an array containing ${lastColLength} items, and the key "${col}" points to an array containing ${data[col].length} items.`
2761
- );
2762
- lastColLength = data[col].length;
2763
- const values = data[col];
2764
- temp.push(values);
2765
- });
2766
- this._values = transpose(temp);
2767
- const dataShape = shape(this.values);
2768
- this._index = range(0, dataShape[0]).map((i) => {
2769
- return "row" + leftPad(i, (dataShape[0] - 1).toString().length);
2770
- });
2771
- }
2772
- }
2773
- }
2774
- get shape() {
2775
- return shape(this.values);
2776
- }
2777
- get length() {
2778
- return this.shape[0];
2779
8
  }
2780
- get width() {
2781
- return this.shape[1];
2782
- }
2783
- get rows() {
2784
- return this.index;
2785
- }
2786
- set rows(rows) {
2787
- this.index = rows;
2788
- }
2789
- get isEmpty() {
2790
- return this.values.length === 0 || this.values.every((row) => row.length === 0);
2791
- }
2792
- clear() {
2793
- const out = new _DataFrame(ndarray(this.shape));
2794
- out.columns = this.columns.slice();
2795
- out.index = this.index.slice();
2796
- return out;
2797
- }
2798
- get(rows, cols) {
2799
- if (arguments.length === 0) {
2800
- return this;
2801
- }
2802
- if (arguments.length === 1) {
2803
- try {
2804
- return this.get(null, rows);
2805
- } catch (e) {
2806
- return this.get(rows, null);
2807
- }
9
+ if (charset) {
10
+ if (charset instanceof Array) {
11
+ charset = charset.join("");
2808
12
  }
2809
- return dfGet(this, rows, cols);
2810
- }
2811
- getSubsetByNames(rows, cols) {
2812
- return dfGetSubsetByNames(_DataFrame, Series, this, rows, cols);
2813
- }
2814
- getSubsetByIndices(rowIndices, colIndices) {
2815
- return dfGetSubsetByIndices(this, rowIndices, colIndices);
2816
- }
2817
- getDummies(columns) {
2818
- return dfGetDummies(_DataFrame, this, columns);
2819
- }
2820
- oneHotEncode(columns) {
2821
- return dfGetDummies(_DataFrame, this, columns);
2822
- }
2823
- transpose() {
2824
- const out = new _DataFrame(transpose(this.values));
2825
- out.columns = this.index.slice();
2826
- out.index = this.columns.slice();
2827
- return out;
2828
- }
2829
- get T() {
2830
- return this.transpose();
2831
- }
2832
- resetIndex(shouldSkipCopying) {
2833
- return dfResetIndex(this, shouldSkipCopying);
2834
- }
2835
- copy() {
2836
- return dfCopy(_DataFrame, this);
2837
- }
2838
- assign(p1, p2) {
2839
- return dfAssign(_DataFrame, Series, this, p1, p2);
2840
- }
2841
- apply(fn, axis) {
2842
- return dfApply(_DataFrame, Series, this, fn, axis);
2843
- }
2844
- dropMissing(axis, condition, threshold) {
2845
- return dfDropMissing(_DataFrame, Series, this, axis, condition, threshold);
2846
- }
2847
- dropNaN(axis, condition, threshold) {
2848
- return dfDropNaN(_DataFrame, this, axis, condition, threshold);
2849
- }
2850
- drop(rows, cols) {
2851
- return dfDrop(_DataFrame, Series, this, rows, cols);
2852
- }
2853
- dropColumns(columns) {
2854
- return this.drop(null, columns);
2855
- }
2856
- dropRows(rows) {
2857
- return this.drop(rows, null);
2858
- }
2859
- toDetailedObject(axis) {
2860
- return dfToDetailedObject(this, axis);
2861
- }
2862
- toObject() {
2863
- return dfToObject(this);
2864
- }
2865
- toJSONString(axis) {
2866
- return dfToJSONString(this, axis);
2867
- }
2868
- saveAsJSON(filename, axis) {
2869
- return dfToJSON(this, filename, axis);
2870
- }
2871
- print() {
2872
- return dfPrint(_DataFrame, Series, this);
2873
- }
2874
- sort(cols, directions) {
2875
- return dfSort(this, cols, directions);
2876
- }
2877
- sortByIndex() {
2878
- return this.sort();
2879
- }
2880
- filter(fn, axis) {
2881
- return dfFilter(_DataFrame, Series, this, fn, axis);
2882
- }
2883
- shuffle(axis) {
2884
- return dfShuffle(this, axis);
2885
- }
2886
- append(x, axis) {
2887
- return dfAppend(this, x, axis);
2888
- }
2889
- concat(x, axis) {
2890
- return this.append(x, axis);
2891
- }
2892
- join(x, axis) {
2893
- return this.append(x, axis);
2894
- }
2895
- toString() {
2896
- return JSON.stringify(this);
2897
- }
2898
- };
2899
- var Series = createSeriesClass(DataFrame);
2900
-
2901
- // node_modules/@jrc03c/js-math-tools/src/max.mjs
2902
- function max(arr, shouldDropNaNs) {
2903
- return stats(arr, { shouldDropNaNs }).max;
2904
- }
2905
-
2906
- // node_modules/@jrc03c/js-math-tools/src/vectorize.mjs
2907
- function vectorize(fn) {
2908
- assert(
2909
- isFunction(fn),
2910
- "You must pass a function into the `vectorize` function!"
2911
- );
2912
- return function helper4() {
2913
- let hasSeries, hasDataFrames;
2914
- const series = [];
2915
- const dataframes = [];
2916
- const childArrays = Object.keys(arguments).filter((key) => {
2917
- const arg = arguments[key];
2918
- if (isArray(arg)) {
2919
- return true;
2920
- } else if (isSeries(arg)) {
2921
- hasSeries = true;
2922
- series.push(arg);
2923
- return true;
2924
- } else if (isDataFrame(arg)) {
2925
- hasDataFrames = true;
2926
- dataframes.push(arg);
2927
- return true;
2928
- } else {
2929
- return false;
2930
- }
2931
- }).map((key) => arguments[key]);
2932
- childArrays.slice(0, -1).forEach((s2, i) => {
2933
- assert(
2934
- isEqual(
2935
- isArray(s2) ? shape(s2) : s2.shape,
2936
- isArray(childArrays[i + 1]) ? shape(childArrays[i + 1]) : childArrays[i + 1].shape
2937
- ),
2938
- `When passing multiple arrays into the \`${fn.name}\` function, all of the arrays must have the same shape!`
2939
- );
2940
- });
2941
- if (childArrays.length > 0) {
2942
- const maxLength = max(
2943
- childArrays.map((a) => a.length ? a.length : a.values.length)
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!"
2944
16
  );
2945
- const out = range(0, maxLength).map((i) => {
2946
- const args = Object.keys(arguments).map((key) => {
2947
- if (isArray(arguments[key])) {
2948
- return arguments[key][i];
2949
- } else if (isSeries(arguments[key])) {
2950
- return arguments[key].values[i];
2951
- } else if (isDataFrame(arguments[key])) {
2952
- return arguments[key].values[i];
2953
- } else {
2954
- return arguments[key];
2955
- }
2956
- });
2957
- return helper4(...args);
2958
- });
2959
- if (hasDataFrames) {
2960
- try {
2961
- if (dataframes.length === 1 && isEqual(shape(dataframes[0]), shape(out))) {
2962
- const temp = new DataFrame(out);
2963
- temp.index = dataframes[0].index.slice();
2964
- temp.columns = dataframes[0].columns.slice();
2965
- return temp;
2966
- } else {
2967
- return new DataFrame(out);
2968
- }
2969
- } catch (e) {
2970
- return out;
2971
- }
2972
- }
2973
- if (hasSeries) {
2974
- try {
2975
- if (series.length === 1 && series[0].length === out.length) {
2976
- const temp = new Series(out);
2977
- temp.name = series[0].name;
2978
- temp.index = series[0].index.slice();
2979
- return temp;
2980
- } else {
2981
- return new Series(out);
2982
- }
2983
- } catch (e) {
2984
- return out;
2985
- }
2986
- }
2987
- return out;
2988
- } else {
2989
- return fn(...arguments);
2990
- }
2991
- };
2992
- }
2993
-
2994
- // node_modules/@jrc03c/js-math-tools/src/abs.mjs
2995
- function abs(x) {
2996
- try {
2997
- if (!isNumber(x)) return NaN;
2998
- if (typeof x === "bigint") {
2999
- return x < 0 ? -x : x;
3000
- } else {
3001
- return Math.abs(x);
3002
- }
3003
- } catch (e) {
3004
- return NaN;
3005
- }
3006
- }
3007
- var vabs = vectorize(abs);
3008
-
3009
- // node_modules/@jrc03c/js-math-tools/src/add.mjs
3010
- function add() {
3011
- try {
3012
- let out = 0;
3013
- let resultShouldBeABigInt = false;
3014
- const x = Object.values(arguments);
3015
- for (let v of x) {
3016
- if (!isNumber(v)) return NaN;
3017
- if (typeof v === "bigint") {
3018
- resultShouldBeABigInt = true;
3019
- v = Number(v);
3020
- }
3021
- out += v;
3022
- }
3023
- if (resultShouldBeABigInt) {
3024
- try {
3025
- return BigInt(out);
3026
- } catch (e) {
3027
- }
3028
- }
3029
- return out;
3030
- } catch (e) {
3031
- return NaN;
3032
- }
3033
- }
3034
- var vadd = vectorize(add);
3035
-
3036
- // node_modules/@jrc03c/js-math-tools/src/apply.mjs
3037
- function apply(x, fn) {
3038
- try {
3039
- return fn(x);
3040
- } catch (e) {
3041
- return NaN;
3042
- }
3043
- }
3044
- var vapply = vectorize(apply);
3045
-
3046
- // node_modules/@jrc03c/js-math-tools/src/arccos.mjs
3047
- function arccos(x) {
3048
- try {
3049
- if (!isNumber(x)) return NaN;
3050
- if (typeof x === "bigint") {
3051
- x = Number(x);
3052
- }
3053
- return Math.acos(x);
3054
- } catch (e) {
3055
- return NaN;
3056
- }
3057
- }
3058
- var varccos = vectorize(arccos);
3059
-
3060
- // node_modules/@jrc03c/js-math-tools/src/arcsin.mjs
3061
- function arcsin(x) {
3062
- try {
3063
- if (!isNumber(x)) return NaN;
3064
- if (typeof x === "bigint") {
3065
- x = Number(x);
3066
- }
3067
- return Math.asin(x);
3068
- } catch (e) {
3069
- return NaN;
3070
- }
3071
- }
3072
- var varcsin = vectorize(arcsin);
3073
-
3074
- // node_modules/@jrc03c/js-math-tools/src/arctan.mjs
3075
- function arctan(x) {
3076
- try {
3077
- if (!isNumber(x)) return NaN;
3078
- if (typeof x === "bigint") {
3079
- x = Number(x);
3080
- }
3081
- return Math.atan(x);
3082
- } catch (e) {
3083
- return NaN;
3084
- }
3085
- }
3086
- var varctan = vectorize(arctan);
3087
-
3088
- // node_modules/@jrc03c/js-math-tools/src/ceil.mjs
3089
- function ceil(x) {
3090
- try {
3091
- if (!isNumber(x)) return NaN;
3092
- if (typeof x === "bigint") return x;
3093
- return Math.ceil(x);
3094
- } catch (e) {
3095
- return NaN;
3096
- }
3097
- }
3098
- var vceil = vectorize(ceil);
3099
-
3100
- // node_modules/@jrc03c/js-math-tools/src/chop.mjs
3101
- function chop(x, threshold) {
3102
- try {
3103
- if (!isNumber(x)) return NaN;
3104
- if (typeof x === "bigint") return x;
3105
- if (isUndefined(threshold)) {
3106
- threshold = 1e-10;
3107
- } else if (!isNumber(threshold)) {
3108
- return NaN;
3109
- }
3110
- return vabs(x) < threshold ? 0 : x;
3111
- } catch (e) {
3112
- return NaN;
3113
- }
3114
- }
3115
- var vchop = vectorize(chop);
3116
-
3117
- // node_modules/@jrc03c/js-math-tools/src/int.mjs
3118
- function int(x) {
3119
- if (isDataFrame(x) || isSeries(x)) {
3120
- const out = x.copy();
3121
- out.values = int(out.values);
3122
- return out;
3123
- }
3124
- if (isArray(x)) {
3125
- return x.map((v) => int(v));
3126
- } else {
3127
- try {
3128
- const out = JSON.parse(x);
3129
- if (isNumber(out)) {
3130
- return typeof out === "bigint" ? Number(out) : out >= 0 ? Math.floor(out) : Math.ceil(out);
3131
- }
3132
- return NaN;
3133
- } catch (e) {
3134
- return NaN;
3135
- }
3136
- }
3137
- }
3138
- var vint = vectorize(int);
3139
-
3140
- // node_modules/@jrc03c/js-math-tools/src/clamp.mjs
3141
- function clamp(x, a, b) {
3142
- try {
3143
- if (!isNumber(x)) return NaN;
3144
- if (!isNumber(a)) return NaN;
3145
- if (!isNumber(b)) return NaN;
3146
- if (typeof x === "bigint") {
3147
- return BigInt(clamp(vint(x), a, b));
3148
- }
3149
- if (x < a) return a;
3150
- if (x > b) return b;
3151
- return x;
3152
- } catch (e) {
3153
- return NaN;
3154
- }
3155
- }
3156
- var vclamp = vectorize(clamp);
3157
-
3158
- // node_modules/@jrc03c/js-math-tools/src/cos.mjs
3159
- function cos(x) {
3160
- try {
3161
- if (!isNumber(x)) return NaN;
3162
- if (typeof x === "bigint") {
3163
- x = Number(x);
3164
- }
3165
- return Math.cos(x);
3166
- } catch (e) {
3167
- return NaN;
3168
- }
3169
- }
3170
- var vcos = vectorize(cos);
3171
-
3172
- // node_modules/@jrc03c/js-math-tools/src/helpers/data-types.mjs
3173
- var dataTypes = Object.freeze({
3174
- boolean: "boolean",
3175
- date: "date",
3176
- null: "null",
3177
- number: "number",
3178
- object: "object",
3179
- string: "string"
3180
- });
3181
-
3182
- // node_modules/@jrc03c/js-math-tools/src/pow.mjs
3183
- function pow(x, p) {
3184
- try {
3185
- if (!isNumber(x)) return NaN;
3186
- if (!isNumber(p)) return NaN;
3187
- if (typeof x === "bigint" || typeof p === "bigint") {
3188
- const out = pow(Number(x), Number(p));
3189
- try {
3190
- return BigInt(out);
3191
- } catch (e) {
3192
- return out;
3193
- }
3194
17
  }
3195
- return Math.pow(x, p);
3196
- } catch (e) {
3197
- return NaN;
3198
18
  }
3199
- }
3200
- var vpow = vectorize(pow);
3201
-
3202
- // node_modules/@jrc03c/js-math-tools/src/sqrt.mjs
3203
- function sqrt(x) {
3204
- try {
3205
- if (!isNumber(x)) return NaN;
3206
- if (typeof x === "bigint") {
3207
- const out = sqrt(Number(x));
3208
- try {
3209
- return BigInt(out);
3210
- } catch (e) {
3211
- return out;
3212
- }
3213
- }
3214
- return Math.sqrt(x);
3215
- } catch (e) {
3216
- return NaN;
3217
- }
3218
- }
3219
- var vsqrt = vectorize(sqrt);
3220
-
3221
- // node_modules/@jrc03c/js-math-tools/src/multiply.mjs
3222
- function multiply() {
3223
- try {
3224
- const x = Object.values(arguments);
3225
- if (x.length === 0) return NaN;
3226
- let resultShouldBeABigInt = false;
3227
- let out = 1;
3228
- for (let v of x) {
3229
- if (!isNumber(v)) return NaN;
3230
- if (typeof v === "bigint") {
3231
- resultShouldBeABigInt = true;
3232
- v = Number(v);
3233
- }
3234
- out *= v;
3235
- }
3236
- if (resultShouldBeABigInt) {
3237
- try {
3238
- return BigInt(out);
3239
- } catch (e) {
3240
- }
3241
- }
3242
- return out;
3243
- } catch (e) {
3244
- return NaN;
3245
- }
3246
- }
3247
- var vmultiply = vectorize(multiply);
3248
-
3249
- // node_modules/@jrc03c/js-math-tools/src/exp.mjs
3250
- function exp(x) {
3251
- try {
3252
- if (!isNumber(x)) return NaN;
3253
- if (typeof x === "bigint") {
3254
- if (x === 0n) {
3255
- return 1n;
3256
- } else {
3257
- x = Number(x);
3258
- }
3259
- }
3260
- return Math.exp(x);
3261
- } catch (e) {
3262
- return NaN;
3263
- }
3264
- }
3265
- var vexp = vectorize(exp);
3266
-
3267
- // node_modules/@jrc03c/js-math-tools/src/factorial.mjs
3268
- function factorial(n) {
3269
- try {
3270
- if (typeof n === "bigint") {
3271
- return BigInt(factorial(vint(n)));
3272
- }
3273
- if (n !== vint(n)) return NaN;
3274
- if (n <= 1) return 1;
3275
- return n * factorial(n - 1);
3276
- } catch (e) {
3277
- return NaN;
3278
- }
3279
- }
3280
- var vfactorial = vectorize(factorial);
3281
-
3282
- // node_modules/@jrc03c/js-math-tools/src/float.mjs
3283
- function float(x) {
3284
- try {
3285
- if (x === "Infinity") {
3286
- return Infinity;
3287
- }
3288
- if (x === "-Infinity") {
3289
- return -Infinity;
3290
- }
3291
- const out = JSON.parse(x);
3292
- if (isNumber(out)) return out;
3293
- return NaN;
3294
- } catch (e) {
3295
- return NaN;
3296
- }
3297
- }
3298
- var vfloat = vectorize(float);
3299
-
3300
- // node_modules/@jrc03c/js-math-tools/src/floor.mjs
3301
- function floor(x) {
3302
- try {
3303
- if (!isNumber(x)) return NaN;
3304
- if (typeof x === "bigint") {
3305
- return x;
3306
- }
3307
- return Math.floor(x);
3308
- } catch (e) {
3309
- return NaN;
3310
- }
3311
- }
3312
- var vfloor = vectorize(floor);
3313
-
3314
- // node_modules/@jrc03c/js-math-tools/src/lerp.mjs
3315
- function lerp(a, b, f) {
3316
- try {
3317
- if (!isNumber(a)) return NaN;
3318
- if (!isNumber(b)) return NaN;
3319
- if (!isNumber(f)) return NaN;
3320
- if (typeof a === "bigint" || typeof b === "bigint") {
3321
- const out = lerp(Number(a), Number(b), f);
3322
- try {
3323
- return BigInt(out);
3324
- } catch (e) {
3325
- return out;
3326
- }
3327
- }
3328
- return f * (b - a) + a;
3329
- } catch (e) {
3330
- return NaN;
3331
- }
3332
- }
3333
- var vlerp = vectorize(lerp);
3334
-
3335
- // node_modules/@jrc03c/js-math-tools/src/log.mjs
3336
- function log(x, base) {
3337
- try {
3338
- base = isUndefined(base) ? Math.E : base;
3339
- if (!isNumber(x)) return NaN;
3340
- if (!isNumber(base)) return NaN;
3341
- if (typeof x === "bigint" || typeof base === "bigint") {
3342
- const out = log(Number(x), Number(base));
3343
- try {
3344
- return BigInt(out);
3345
- } catch (e) {
3346
- return out;
3347
- }
3348
- }
3349
- return Math.log(x) / Math.log(base);
3350
- } catch (e) {
3351
- return NaN;
3352
- }
3353
- }
3354
- var vlog = vectorize(log);
3355
-
3356
- // node_modules/@jrc03c/js-math-tools/src/mod.mjs
3357
- function mod(a, b) {
3358
- try {
3359
- if (!isNumber(a)) return NaN;
3360
- if (!isNumber(b)) return NaN;
3361
- if (typeof a === "bigint" || typeof b === "bigint") {
3362
- const out = mod(Number(a), Number(b));
3363
- try {
3364
- return BigInt(out);
3365
- } catch (e) {
3366
- return out;
3367
- }
3368
- }
3369
- return a % b;
3370
- } catch (e) {
3371
- return NaN;
3372
- }
3373
- }
3374
- var vmod = vectorize(mod);
3375
-
3376
- // node_modules/@jrc03c/js-math-tools/src/remap.mjs
3377
- var helper3 = vectorize((x, a, b, c, d) => {
3378
- try {
3379
- let resultShouldBeABigInt = false;
3380
- for (const v of [x, a, b, c, d]) {
3381
- if (!isNumber(v)) {
3382
- return NaN;
3383
- }
3384
- if (typeof v === "bigint") {
3385
- resultShouldBeABigInt = true;
3386
- }
3387
- }
3388
- if (resultShouldBeABigInt) {
3389
- x = Number(x);
3390
- a = Number(a);
3391
- b = Number(b);
3392
- c = Number(c);
3393
- d = Number(d);
3394
- }
3395
- const num = (d - c) * (x - a);
3396
- const den = b - a;
3397
- if (den === 0) return NaN;
3398
- const out = num / den + c;
3399
- if (resultShouldBeABigInt) {
3400
- try {
3401
- return BigInt(out);
3402
- } catch (e) {
3403
- }
3404
- }
3405
- return out;
3406
- } catch (e) {
3407
- return NaN;
3408
- }
3409
- });
3410
-
3411
- // node_modules/@jrc03c/js-math-tools/src/round.mjs
3412
- function round(x) {
3413
- try {
3414
- if (!isNumber(x)) return NaN;
3415
- if (typeof x === "bigint") return x;
3416
- return Math.round(x);
3417
- } catch (e) {
3418
- return NaN;
3419
- }
3420
- }
3421
- var vround = vectorize(round);
3422
-
3423
- // node_modules/@jrc03c/js-math-tools/src/sign.mjs
3424
- function sign(x) {
3425
- try {
3426
- if (!isNumber(x)) return NaN;
3427
- if (typeof x === "bigint") return BigInt(sign(Number(x)));
3428
- if (x < 0) return -1;
3429
- if (x > 0) return 1;
3430
- return 0;
3431
- } catch (e) {
3432
- return NaN;
3433
- }
3434
- }
3435
- var vsign = vectorize(sign);
3436
-
3437
- // node_modules/@jrc03c/js-math-tools/src/sin.mjs
3438
- function sin(x) {
3439
- try {
3440
- if (!isNumber(x)) return NaN;
3441
- if (typeof x === "bigint") {
3442
- x = Number(x);
3443
- }
3444
- return Math.sin(x);
3445
- } catch (e) {
3446
- return NaN;
3447
- }
3448
- }
3449
- var vsin = vectorize(sin);
3450
-
3451
- // node_modules/@jrc03c/js-math-tools/src/tan.mjs
3452
- function tan(x) {
3453
- try {
3454
- if (!isNumber(x)) return NaN;
3455
- if (typeof x === "bigint") {
3456
- x = Number(x);
3457
- }
3458
- return Math.tan(x);
3459
- } catch (e) {
3460
- return NaN;
3461
- }
3462
- }
3463
- var vtan = vectorize(tan);
3464
-
3465
- // src/index.mjs
3466
- function makeKey4(keyLength, keySeed, charset) {
3467
- if (arguments.length === 2) {
3468
- if (isNumber(arguments[1])) {
3469
- charset = null;
3470
- } else {
3471
- charset = keySeed;
3472
- keySeed = null;
3473
- }
3474
- }
3475
- assert(
3476
- isNumber(keyLength) && vint(keyLength) === keyLength,
3477
- "`keyLength` must be an integer!"
3478
- );
3479
- if (keySeed) {
3480
- assert(
3481
- isNumber(keySeed) && vint(keySeed) === keySeed,
3482
- "`keySeed` must be an integer!"
19
+ randomFn = randomFn || Math.random;
20
+ if (typeof randomFn !== "function") {
21
+ throw new Error(
22
+ "The third argument passed into the `makeKey` function must be a function!"
3483
23
  );
3484
- seed(keySeed);
3485
- }
3486
- if (charset) {
3487
- assert(isString(charset), "`charset` must be a string!");
3488
24
  }
3489
25
  let out = "";
3490
- charset = charset || "abcdefg1234567890";
26
+ charset = charset || "abcdef1234567890";
3491
27
  for (let i = 0; i < keyLength; i++) {
3492
- out += charset[vint(random() * charset.length)];
28
+ out += charset[Math.floor(randomFn() * charset.length)];
3493
29
  }
3494
30
  return out;
3495
31
  }
3496
32
 
3497
33
  // src/iife.mjs
3498
34
  if (typeof globalThis !== "undefined") {
3499
- globalThis.makeKey = makeKey4;
35
+ globalThis.makeKey = makeKey;
3500
36
  }
3501
37
  })();