@gpc-cli/core 0.9.15 → 0.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -150,6 +150,14 @@ ${formatYaml(value, indent + 1)}`;
150
150
  }
151
151
  return String(data);
152
152
  }
153
+ function cellValue(val) {
154
+ if (val === null || val === void 0) return "";
155
+ if (typeof val === "object") {
156
+ if (Array.isArray(val)) return val.length === 0 ? "" : JSON.stringify(val);
157
+ return JSON.stringify(val);
158
+ }
159
+ return String(val);
160
+ }
153
161
  function formatTable(data) {
154
162
  const rows = toRows(data);
155
163
  if (rows.length === 0) return "";
@@ -158,11 +166,11 @@ function formatTable(data) {
158
166
  const keys = Object.keys(firstRow);
159
167
  if (keys.length === 0) return "";
160
168
  const widths = keys.map(
161
- (key) => Math.max(key.length, ...rows.map((row) => String(row[key] ?? "").length))
169
+ (key) => Math.max(key.length, ...rows.map((row) => cellValue(row[key]).length))
162
170
  );
163
171
  const header = keys.map((key, i) => key.padEnd(widths[i] ?? 0)).join(" ");
164
172
  const separator = widths.map((w) => "-".repeat(w)).join(" ");
165
- const body = rows.map((row) => keys.map((key, i) => String(row[key] ?? "").padEnd(widths[i] ?? 0)).join(" ")).join("\n");
173
+ const body = rows.map((row) => keys.map((key, i) => cellValue(row[key]).padEnd(widths[i] ?? 0)).join(" ")).join("\n");
166
174
  return `${header}
167
175
  ${separator}
168
176
  ${body}`;
@@ -175,12 +183,12 @@ function formatMarkdown(data) {
175
183
  const keys = Object.keys(firstRow);
176
184
  if (keys.length === 0) return "";
177
185
  const widths = keys.map(
178
- (key) => Math.max(key.length, ...rows.map((row) => String(row[key] ?? "").length))
186
+ (key) => Math.max(key.length, ...rows.map((row) => cellValue(row[key]).length))
179
187
  );
180
188
  const header = `| ${keys.map((key, i) => key.padEnd(widths[i] ?? 0)).join(" | ")} |`;
181
189
  const separator = `| ${widths.map((w) => "-".repeat(w)).join(" | ")} |`;
182
190
  const body = rows.map(
183
- (row) => `| ${keys.map((key, i) => String(row[key] ?? "").padEnd(widths[i] ?? 0)).join(" | ")} |`
191
+ (row) => `| ${keys.map((key, i) => cellValue(row[key]).padEnd(widths[i] ?? 0)).join(" | ")} |`
184
192
  ).join("\n");
185
193
  return `${header}
186
194
  ${separator}