@@ -5944,6 +5944,69 @@ const specificDuration = prettyDuration(start, { end });
59445944console.log(specificDuration); // Returns "22 days, 6 h, 3 min, 15 sec, 0 ms"
59455945` ` `
59465946
5947+ ## printTable
5948+
5949+ Prints a formatted table to the console with support for word wrapping within
5950+ cells . Unlike console .table (), this function properly handles multi -line content
5951+ within cells , making it ideal for displaying data with long text values .
5952+
5953+ This function has been created for the
5954+ [simple -data -analysis library ](https : // github.com/nshiab/simple-data-analysis),
5955+ but can be used independently for any array of objects .
5956+
5957+ ### Signature
5958+
5959+ ` ` ` typescript
5960+ function printTable(
5961+ data: Record<string, unknown>[],
5962+ options?: {
5963+ maxColumnWidth?: number;
5964+ minColumnWidth?: number;
5965+ typesRowIndex?: number;
5966+ },
5967+ ): void;
5968+ ` ` `
5969+
5970+ ### Parameters
5971+
5972+ - **` data ` **: - An array of objects representing the rows of the table . Each
5973+ object should have string keys .
5974+ - **` options ` **: - Optional configuration for table rendering .
5975+ - **` options.maxColumnWidth ` **: - The maximum width for any column (default :
5976+ 75 ). Values exceeding this width will be wrapped at word boundaries .
5977+ - **` options.minColumnWidth ` **: - The minimum width for any column (default : 3 ).
5978+ - **` options.typesRowIndex ` **: - The index of a row that contains type
5979+ annotations (e .g . " VARCHAR/string" ). This row will be rendered in grey . If
5980+ omitted , no row is treated as a types row.
5981+
5982+ ### Returns
5983+
5984+ void - The table is printed directly to the console.
5985+
5986+ ### Examples
5987+
5988+ ` ` ` typescript
5989+ const data = [
5990+ {
5991+ name: "Alice",
5992+ description: "A software engineer with expertise in TypeScript",
5993+ },
5994+ { name: "Bob", description: "A product manager" },
5995+ ];
5996+ printTable(data, { maxColumnWidth: 30 });
5997+ // Outputs a nicely formatted table with word-wrapped description column
5998+ ` ` `
5999+
6000+ ` ` ` typescript
6001+ // With types row
6002+ const types = { name: "VARCHAR/string", age: "INTEGER/number" };
6003+ const data = [
6004+ { name: "Alice", age: 30 },
6005+ { name: "Bob", age: 25 },
6006+ ];
6007+ printTable([types, ...data], { typesRowIndex: 0 });
6008+ ` ` `
6009+
59476010## publishChartDW
59486011
59496012Publishes a specified Datawrapper chart , table , or map. This function
0 commit comments