UNPKG

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