UNPKG

1.74 kBJavaScriptView Raw
1import { Mx } from 'veho';
2
3/** @typedef {{head:*[],rows:*[][]}} TableObject */
4
5/**
6 *
7 * @param {*[]} head
8 * @param {*[][]} rows
9 * @returns {TableObject}
10 */
11
12const slice = ({
13 head,
14 rows
15}) => ({
16 head,
17 rows
18});
19/**
20 *
21 * @param {*[]} head
22 * @param {*[][]} rows
23 * @returns {TableObject}
24 */
25
26const shallow = ({
27 head,
28 rows
29}) => ({
30 head: head.slice(),
31 rows: rows.map(row => row.slice())
32});
33/**
34 *
35 * @param {*[]} head
36 * @param {*[][]} rows
37 * @returns {TableObject}
38 */
39
40const clone = ({
41 head,
42 rows
43}) => ({
44 head: head.slice(),
45 rows: Mx.clone(rows)
46});
47
48/**
49 *
50 * @param {Object} o
51 * @returns {TableObject}
52 */
53
54const matchSlice = (o = {}) => {
55 var _o$head, _o$rows;
56
57 const head = (_o$head = o.head) !== null && _o$head !== void 0 ? _o$head : o.banner,
58 rows = (_o$rows = o.rows) !== null && _o$rows !== void 0 ? _o$rows : o.matrix;
59 return {
60 head,
61 rows
62 };
63};
64/**
65 *
66 * @param {Object} o
67 * @returns {TableObject}
68 */
69
70const matchShallow = (o = {}) => {
71 var _o$head2, _o$rows2;
72
73 const head = (_o$head2 = o.head) !== null && _o$head2 !== void 0 ? _o$head2 : o.banner,
74 rows = (_o$rows2 = o.rows) !== null && _o$rows2 !== void 0 ? _o$rows2 : o.matrix;
75 return {
76 head: head.slice(),
77 rows: rows.map(row => row.slice())
78 };
79};
80/**
81 *
82 * @param {Object} o
83 * @returns {TableObject}
84 */
85
86const matchClone = (o = {}) => {
87 var _o$head3, _o$rows3;
88
89 const head = (_o$head3 = o.head) !== null && _o$head3 !== void 0 ? _o$head3 : o.banner,
90 rows = (_o$rows3 = o.rows) !== null && _o$rows3 !== void 0 ? _o$rows3 : o.matrix;
91 return {
92 head: head.slice(),
93 rows: Mx.clone(rows)
94 };
95};
96
97export { clone, matchClone, matchShallow, matchSlice, shallow, slice };