### Install Columnify Source: https://github.com/timoxley/columnify/blob/master/Readme.md Install the columnify package using npm. ```bash npm install columnify ``` -------------------------------- ### Configure full columnify options Source: https://context7.com/timoxley/columnify/llms.txt A comprehensive example demonstrating global options, transform functions, and per-column configuration. ```javascript const columnify = require('columnify') const data = [ { id: 1, name: 'module1', description: 'First module description', version: '1.0.0' }, { id: 2, name: 'module2', description: 'Second module with a much longer description', version: '2.0.0' } ] const result = columnify(data, { // Global options (apply to all columns) columns: ['id', 'name', 'description', 'version'], // Column order and filtering maxWidth: Infinity, // Maximum column width minWidth: 0, // Minimum column width truncate: false, // Enable truncation instead of wrapping truncateMarker: '…', // Character to show when truncated preserveNewLines: false, // Keep existing newlines in data paddingChr: ' ', // Character to pad cells with showHeaders: true, // Show column headers columnSplitter: ' ', // String between columns maxLineWidth: 'auto', // Maximum line width ('auto' uses terminal width) // Transform functions headingTransform: (heading) => heading.toUpperCase(), dataTransform: (data, column, index) => data, // Per-column configuration config: { id: { showHeaders: false, align: 'right' }, description: { maxWidth: 30, minWidth: 10, truncate: true, headingTransform: (heading) => 'Info' }, version: { align: 'center' } } }) console.log(result) ``` -------------------------------- ### Displaying Multibyte Data with Columnify Source: https://github.com/timoxley/columnify/blob/master/Readme.md Example demonstrating how columnify aligns data containing multibyte characters. ```javascript var data = [{ name: 'module-one', description: 'some description', version: '0.0.1', }, { name: '这是一个很长的名字的模块', description: '这真的是一个描述的内容这个描述很长', version: "0.3.3" }] console.log(columnify(data)) ``` -------------------------------- ### Column Alignment Source: https://context7.com/timoxley/columnify/llms.txt Align column content to 'left', 'right', or 'center' using the `align` option within the `config` object for specific columns. This example demonstrates right alignment for the 'value' column. ```javascript const columnify = require('columnify') const data = { "mocha@1.18.2": 1, "commander@2.0.0": 1, "debug@0.8.1": 1 } console.log(columnify(data, { config: { value: { align: 'right' } } })) ``` -------------------------------- ### Custom Column Splitter Source: https://context7.com/timoxley/columnify/llms.txt Customize the character(s) used to separate columns by setting the `columnSplitter` option. This example uses ' | ' for a more distinct separation. ```javascript const columnify = require('columnify') const data = [ { name: 'mod1', description: 'some description which happens to be far larger than the max', version: '0.0.1' }, { name: 'module-two', description: 'another description larger than the max', version: '0.2.0' } ] console.log(columnify(data, { columnSplitter: ' | ' })) ``` -------------------------------- ### Data Transform Function (Global and Per-Column) Source: https://context7.com/timoxley/columnify/llms.txt Transform cell content using the `dataTransform` function. It can be applied globally to all cells or specifically to individual columns via the `config` object. This example shows both global uppercase and per-column uppercase for the 'name' field. ```javascript const columnify = require('columnify') const data = [ { name: 'module1', description: 'some description', version: '0.0.1' }, { name: 'module2', description: 'another description', version: '0.2.0' } ] // Global transform - uppercase all data console.log(columnify(data, { dataTransform: function(data) { return data.toUpperCase() } })) // Per-column transform - only uppercase names console.log(columnify(data, { config: { name: { dataTransform: function(data) { return data.toUpperCase() } } } })) ``` -------------------------------- ### Set Max and Min Column Widths Source: https://github.com/timoxley/columnify/blob/master/Readme.md Configure minimum and maximum column widths globally or per-column using 'minWidth' and 'maxWidth' options. Wrapping occurs at word boundaries. ```javascript var columns = columnify([{ name: 'mod1', description: 'some description which happens to be far larger than the max', version: '0.0.1', }, { name: 'module-two', description: 'another description larger than the max', version: '0.2.0', }], { minWidth: 20, config: { description: {maxWidth: 30} } }) console.log(columns) ``` -------------------------------- ### Basic Usage of Columnify Source: https://github.com/timoxley/columnify/blob/master/Readme.md Import and use columnify to format data. The output is logged to the console. ```javascript var columnify = require('columnify') var columns = columnify(data, options) console.log(columns) ``` -------------------------------- ### Columnify Configuration Options Source: https://context7.com/timoxley/columnify/llms.txt A collection of configuration options for the columnify library to customize output formatting. ```APIDOC ## Custom Truncation Marker ### Description Change the truncation marker from the default `…` using the `truncateMarker` option. ### Parameters #### Request Body - **truncate** (boolean) - Optional - Enable truncation. - **truncateMarker** (string) - Optional - Custom character to indicate truncation. - **config** (object) - Optional - Per-column configuration (e.g., maxWidth). ## Column Alignment ### Description Align column content using the `align` option with values 'left', 'right', or 'center'. ### Parameters #### Request Body - **config** (object) - Optional - Per-column configuration (e.g., align). ## Custom Column Splitter ### Description Separate columns with custom characters using the `columnSplitter` option. ### Parameters #### Request Body - **columnSplitter** (string) - Optional - Character sequence to separate columns. ## Custom Padding Character ### Description Fill whitespace within columns with a custom character using `paddingChr`. ### Parameters #### Request Body - **paddingChr** (string) - Optional - Character used for padding. ## Hide Headers ### Description Control header display with the `showHeaders` option. ### Parameters #### Request Body - **showHeaders** (boolean) - Optional - Toggle header visibility globally or per-column. ## Preserve Newlines ### Description Keep existing newline characters in data using `preserveNewLines` instead of collapsing whitespace. ### Parameters #### Request Body - **preserveNewLines** (boolean) - Optional - Enable newline preservation. ## Data Transform Function ### Description Transform cell content using `dataTransform` function applied globally or per-column. ### Parameters #### Request Body - **dataTransform** (function) - Optional - Function to transform cell data. ``` -------------------------------- ### Render Plain Objects Source: https://context7.com/timoxley/columnify/llms.txt Converts a plain object into a two-column key/value table format. ```javascript const columnify = require('columnify') const data = { "commander@0.6.1": 1, "minimatch@0.2.14": 3, "mkdirp@0.3.5": 2, "sigmund@1.0.0": 3 } console.log(columnify(data)) ``` -------------------------------- ### Apply Column Width Constraints Source: https://context7.com/timoxley/columnify/llms.txt Control text wrapping behavior by setting maxWidth and minWidth per column. ```javascript const columnify = require('columnify') const data = [ { name: 'mod1', description: 'some description which happens to be far larger than the max', version: '0.0.1' }, { name: 'module-two', description: 'another description larger than the max', version: '0.2.0' }, { name: 'mod3', description: 'thisisaverylongwordandshouldbewrapped', version: '0.3.0' }, { name: 'module-four-four-four-four', description: '', version: '0.0.4' } ] console.log(columnify(data, { config: { description: { maxWidth: 30, minWidth: 10 } } })) ``` -------------------------------- ### Customize Column Names Source: https://context7.com/timoxley/columnify/llms.txt Use the columns option to rename or reorder columns in the output. ```javascript const columnify = require('columnify') const data = { "commander@0.6.1": 1, "minimatch@0.2.14": 3, "mkdirp@0.3.5": 2 } console.log(columnify(data, { columns: ['MODULE', 'COUNT'] })) ``` -------------------------------- ### Render Arrays of Objects Source: https://context7.com/timoxley/columnify/llms.txt Automatically detects headers from object keys to render an array into aligned columns. ```javascript const columnify = require('columnify') const data = [ { name: 'module1', version: '0.0.1' }, { name: 'module2', version: '0.2.0' } ] console.log(columnify(data)) ``` -------------------------------- ### Set maximum line width Source: https://context7.com/timoxley/columnify/llms.txt Control line wrapping by setting a numeric width or using 'auto' to detect the terminal width. ```javascript const columnify = require('columnify') const data = [ { name: 'module-one', description: 'A very long description that should be truncated at terminal width', version: '1.0.0' } ] // Set to specific width console.log(columnify(data, { maxLineWidth: 60 })) // Or auto-detect terminal width console.log(columnify(data, { maxLineWidth: 'auto' })) ``` -------------------------------- ### Filter and Order Columns Source: https://github.com/timoxley/columnify/blob/master/Readme.md Control which columns are included and their order using the 'columns' option with an array of desired keys. ```javascript var data = [{ name: 'module1', description: 'some description', version: '0.0.1', }, { name: 'module2', description: 'another description', version: '0.2.0', }] var columns = columnify(data, { columns: ['name', 'version'] }) console.log(columns) ``` -------------------------------- ### Truncate Content Source: https://context7.com/timoxley/columnify/llms.txt Enable truncate to cut off content at maxWidth with a marker instead of wrapping. ```javascript const columnify = require('columnify') const data = [ { name: 'mod1', description: 'some description', version: '0.0.1' }, { name: 'module-two', description: 'another description larger than the max', version: '0.2.0' }, { name: 'module-three', description: 'thisisaverylongwordandshouldbetruncated', version: '0.2.0' } ] console.log(columnify(data, { truncate: true, config: { description: { maxWidth: 20 } } })) ``` -------------------------------- ### Transform Column Data and Headers Source: https://github.com/timoxley/columnify/blob/master/Readme.md Utilize `dataTransform` and `headingTransform` functions to modify the presentation of column data and headers, respectively. These functions must return a string. ```javascript var columns = columnify([{ name: 'mod1', description: 'SOME DESCRIPTION TEXT.' }, { name: 'module-two', description: 'SOME SLIGHTLY LONGER DESCRIPTION TEXT.' }], { dataTransform: function(data) { return data.toLowerCase() }, headingTransform: function(heading) { return heading.toLowerCase() }, config: { name: { headingTransform: function(heading) { heading = "module " + heading return "*" + heading.toUpperCase() + "*" } } } }) ``` -------------------------------- ### Control Header Display Source: https://github.com/timoxley/columnify/blob/master/Readme.md Use `showHeaders: false` to hide all column headers. To hide a specific column's header, configure it within the `config` object. ```javascript var columns = columnify(data, { showHeaders: false }) ``` ```javascript var columns = columnify(data, { config: { id: { showHeaders: false } } }) ``` -------------------------------- ### Columnify Objects Source: https://github.com/timoxley/columnify/blob/master/Readme.md Converts a JavaScript object into a columnized string format. Keys become column headers. ```javascript var data = { "commander@0.6.1": 1, "minimatch@0.2.14": 3, "mkdirp@0.3.5": 2, "sigmund@1.0.0": 3 } console.log(columnify(data)) ``` -------------------------------- ### Columnify Arrays of Objects Source: https://github.com/timoxley/columnify/blob/master/Readme.md Formats an array of objects into columns. Column headers are derived from object keys. ```javascript var columnify = require('columnify') var columns = columnify([{ name: 'mod1', version: '0.0.1' }, { name: 'module2', version: '0.2.0' }]) console.log(columns) ``` -------------------------------- ### Align Column Data Right Source: https://github.com/timoxley/columnify/blob/master/Readme.md Use the `align: 'right'` option within the `config` object to right-align data in a specific column. This is useful for numerical data. ```javascript var data = { "mocha@1.18.2": 1, "commander@2.0.0": 1, "debug@0.8.1": 1 } columnify(data, {config: {value: {align: 'right'}}}) ``` -------------------------------- ### Custom Column Names Source: https://github.com/timoxley/columnify/blob/master/Readme.md Specify custom column names using the 'columns' option when columnifying an object. ```javascript var data = { "commander@0.6.1": 1, "minimatch@0.2.14": 3, "mkdirp@0.3.5": 2, "sigmund@1.0.0": 3 } console.log(columnify(data, {columns: ['MODULE', 'COUNT']})) ``` -------------------------------- ### Handle multibyte characters Source: https://context7.com/timoxley/columnify/llms.txt Columnify automatically handles multibyte characters to ensure proper column alignment. ```javascript const columnify = require('columnify') const data = [ { name: 'module-one', description: 'some description', version: '0.0.1' }, { name: '这是一个很长的名字的模块', description: '这真的是一个描述的内容这个描述很长', version: '0.3.3' } ] console.log(columnify(data)) // Output (properly aligned): // NAME DESCRIPTION VERSION // module-one some description 0.0.1 // 这是一个很长的名字的模块 这真的是一个描述的内容这个描述很长 0.3.3 ``` -------------------------------- ### Hide Individual Column Headers Source: https://context7.com/timoxley/columnify/llms.txt Hide headers for specific columns by configuring `showHeaders: false` within the `config` object for that column. This allows selective header display. ```javascript const columnify = require('columnify') const data = [ { id: 1, name: 'module1', version: '0.0.1' }, { id: 2, name: 'module2', version: '0.2.0' } ] console.log(columnify(data, { config: { id: { showHeaders: false } } })) ``` -------------------------------- ### Custom Column Splitter Source: https://github.com/timoxley/columnify/blob/master/Readme.md Use the `columnSplitter` option to define a custom string that separates columns, allowing for more visually distinct table layouts. ```javascript var columns = columnify(data, { columnSplitter: ' | ' }) console.log(columns) ``` -------------------------------- ### Hide Headers Source: https://context7.com/timoxley/columnify/llms.txt Control the display of column headers by setting the `showHeaders` option to `false`. This is useful when the data itself is self-explanatory or a header is not desired. ```javascript const columnify = require('columnify') const data = [ { name: 'module1', version: '0.0.1' }, { name: 'module2', version: '0.2.0' } ] console.log(columnify(data, { showHeaders: false })) ``` -------------------------------- ### Set Padding Character Source: https://github.com/timoxley/columnify/blob/master/Readme.md Use the `paddingChr` option to specify a character that fills whitespace within columns. This can improve readability for misaligned data. ```javascript var data = { "shortKey": "veryVeryVeryVeryVeryLongVal", "veryVeryVeryVeryVeryLongKey": "shortVal" } columnify(data, { paddingChr: '.'}) ``` -------------------------------- ### Custom Truncation Marker Source: https://github.com/timoxley/columnify/blob/master/Readme.md Replace the default truncation marker (`…`) with a custom character using the `truncateMarker` option when `truncate: true` is enabled. ```javascript var columns = columnify(data, { truncate: true, truncateMarker: '>', widths: { description: { maxWidth: 20 } } }) console.log(columns) ``` -------------------------------- ### Disable Newline Preservation Source: https://github.com/timoxley/columnify/blob/master/Readme.md By default, `columnify` collapses whitespace. Explicitly setting `preserveNewLines: false` or omitting the option achieves this behavior, collapsing all whitespace into single spaces. ```javascript console.log(columnify(data, {preserveNewLines: false})) ``` ```javascript // or just console.log(columnify(data)) ``` -------------------------------- ### Custom Padding Character Source: https://context7.com/timoxley/columnify/llms.txt Replace the default space padding with a custom character using the `paddingChr` option. This is useful for visually highlighting column boundaries or filling empty space. ```javascript const columnify = require('columnify') const data = { "shortKey": "veryVeryVeryVeryVeryLongVal", "veryVeryVeryVeryVeryLongKey": "shortVal" } console.log(columnify(data, { paddingChr: '.' })) ``` -------------------------------- ### Truncate Column Cells Source: https://github.com/timoxley/columnify/blob/master/Readme.md Disable text wrapping and truncate cell content at the maximum width using the 'truncate' option. A truncation marker '…' is added. ```javascript var columns = columnify(data, { truncate: true, config: { description: { maxWidth: 20 } } }) console.log(columns) ``` -------------------------------- ### Customize headers with headingTransform Source: https://context7.com/timoxley/columnify/llms.txt Use headingTransform to modify header text globally or per-column. The dataTransform function can also be used to modify cell content. ```javascript const columnify = require('columnify') const data = [ { name: 'mod1', description: 'SOME DESCRIPTION TEXT.' }, { name: 'module-two', description: 'SOME SLIGHTLY LONGER DESCRIPTION TEXT.' } ] console.log(columnify(data, { dataTransform: function(data) { return data.toLowerCase() }, headingTransform: function(heading) { return heading.toLowerCase() }, config: { name: { headingTransform: function(heading) { return "*" + ("module " + heading).toUpperCase() + "*" } } } })) // Output: // *MODULE NAME* description // mod1 some description text. // module-two some slightly longer description text. ``` -------------------------------- ### Preserve Newlines Source: https://context7.com/timoxley/columnify/llms.txt Maintain existing newline characters within cell data by setting `preserveNewLines` to `true`. This prevents columnify from collapsing whitespace and ensures multi-line content is rendered correctly. ```javascript const columnify = require('columnify') const data = [ { name: "glob@3.2.9", paths: [ "node_modules/tap/node_modules/glob", "node_modules/tape/node_modules/glob" ].join('\n') }, { name: "nopt@2.2.1", paths: "node_modules/tap/node_modules/nopt" }, { name: "runforcover@0.0.2", paths: "node_modules/tap/node_modules/runforcover" } ] console.log(columnify(data, { preserveNewLines: true })) ``` -------------------------------- ### Preserve Newlines in Column Data Source: https://github.com/timoxley/columnify/blob/master/Readme.md Set `preserveNewLines: true` to retain newline characters within column data. Note that other whitespace characters will still be collapsed into single spaces. ```javascript var data = [{ name: "glob@3.2.9", paths: [ "node_modules/tap/node_modules/glob", "node_modules/tape/node_modules/glob" ].join('\n') }, { name: "nopt@2.2.1", paths: [ "node_modules/tap/node_modules/nopt" ] }, { name: "runforcover@0.0.2", paths: "node_modules/tap/node_modules/runforcover" }] console.log(columnify(data, {preserveNewLines: true})) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.