UNPKG

1.51 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 *
54 * @param {Object} o
55 * @returns {TableObject}
56 */
57
58const matchSlice = o => {
59 const head = o.head || o.banner,
60 rows = o.rows || o.matrix;
61 return {
62 head,
63 rows
64 };
65};
66/**
67 *
68 * @param {Object} o
69 * @returns {TableObject}
70 */
71
72const matchShallow = o => {
73 const head = o.head || o.banner,
74 rows = o.rows || 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 const head = o.head || o.banner,
88 rows = o.rows || o.matrix;
89 return {
90 head: head.slice(),
91 rows: veho.Mx.clone(rows)
92 };
93};
94
95exports.clone = clone;
96exports.matchClone = matchClone;
97exports.matchShallow = matchShallow;
98exports.matchSlice = matchSlice;
99exports.shallow = shallow;
100exports.slice = slice;