1 | import { slice, matchSlice } from '@analys/table-init';
|
2 | import { selectTabular, selectTabularToSamples, tabularToSamples } from '@analys/tabular';
|
3 | import { randBetw } from '@aryth/rand';
|
4 | import { shuffle } from '@vect/vector-select';
|
5 | import { coin } from '@analys/table-index';
|
6 | import { nullish } from '@typen/nullish';
|
7 | import { column } from '@vect/column-getter';
|
8 | import { wind as wind$1 } from '@vect/entries-init';
|
9 | import { wind } from '@vect/object-init';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const tableSelect = function (table, fields, {
|
20 | mutate = false
|
21 | } = {}) {
|
22 | var _table;
|
23 |
|
24 | let o = mutate ? table : (_table = table, slice(_table));
|
25 | if (fields !== null && fields !== void 0 && fields.length) selectTabular.call(o, fields);
|
26 | return o;
|
27 | };
|
28 |
|
29 | const MEAN = 5;
|
30 | function tableShuffle(table, {
|
31 | h,
|
32 | w,
|
33 | oscillate
|
34 | } = {}) {
|
35 | var _table;
|
36 |
|
37 | let {
|
38 | head,
|
39 | rows
|
40 | } = (_table = table, matchSlice(_table));
|
41 | if (!h || oscillate) h = randBetw(MEAN - 1, MEAN + 5);
|
42 | if (!w || oscillate) w = randBetw(MEAN - 2, MEAN + 1);
|
43 | const headSelection = shuffle(head.slice(), w);
|
44 | rows = shuffle(rows.slice(), h);
|
45 | return selectTabular.call({
|
46 | head,
|
47 | rows
|
48 | }, headSelection);
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | const tableToObject = function (key, field, objectify = true) {
|
60 | var _table$rows;
|
61 |
|
62 | const table = this;
|
63 | const hi = table === null || table === void 0 ? void 0 : (_table$rows = table.rows) === null || _table$rows === void 0 ? void 0 : _table$rows.length;
|
64 | let x, y;
|
65 | const keys = (x = coin.call(table, key)) >= 0 ? column(table.rows, x, hi) : null;
|
66 | const values = nullish(field) || Array.isArray(field) ? field !== null && field !== void 0 && field.length ? selectTabularToSamples.call(matchSlice(table), field) : tabularToSamples.call(matchSlice(table)) : (y = coin.call(table, field)) >= 0 ? column(table.rows, y, hi) : null;
|
67 | return keys && values ? objectify ? wind(keys, values) : wind$1(keys, values) : objectify ? {} : [];
|
68 | };
|
69 |
|
70 | export { tableSelect, tableShuffle, tableToObject };
|