You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
643 B
JavaScript
21 lines
643 B
JavaScript
'use strict';
|
|
|
|
const tableToObject = require("./table-to-object");
|
|
const tableToArray = require("./table-to-array");
|
|
|
|
module.exports = function tableToStructure(table) {
|
|
let hasKeys = (table.fields.some((field) => field.type === "TableKeyString"));
|
|
let hasArrayValues = (table.fields.some((field) => field.type === "TableValue"));
|
|
|
|
if (hasKeys && hasArrayValues) {
|
|
let obj = tableToObject(table);
|
|
obj._ = tableToArray(table);
|
|
return obj;
|
|
} else if (hasKeys) {
|
|
return tableToObject(table);
|
|
} else if (hasArrayValues) {
|
|
return tableToArray(table);
|
|
} else {
|
|
throw new Error("Neither array values nor keys found in table");
|
|
}
|
|
} |