MCPcopy Create free account
hub / github.com/zxlie/FeHelper / buildTableViewData

Function buildTableViewData

apps/json-format/table-utils.js:72–92  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

70}
71
72export function buildTableViewData(input) {
73 const candidates = getArrayObjectCandidates(input);
74 if (candidates.length) {
75 const best = candidates.sort((a, b) => b.rows.length - a.rows.length)[0];
76 return {
77 title: best.path === '$' ? '根数组表格视图' : best.path + ' 表格视图',
78 sourcePath: best.path,
79 ...buildRowsFromObjects(best.rows)
80 };
81 }
82
83 if (isPlainObject(input)) {
84 return {
85 title: '对象键值表视图',
86 sourcePath: '$',
87 ...buildKeyValueRows(input)
88 };
89 }
90
91 throw new Error('当前 JSON 不适合表格展示。建议使用对象数组,或包含对象数组字段的 JSON。');
92}
93
94export function isRenderableTableViewData(tableViewData) {
95 if (!tableViewData || !Array.isArray(tableViewData.rows) || !tableViewData.rows.length) {

Callers 2

Calls 4

getArrayObjectCandidatesFunction · 0.85
buildRowsFromObjectsFunction · 0.85
buildKeyValueRowsFunction · 0.85
isPlainObjectFunction · 0.70

Tested by

no test coverage detected