{"id":16786,"library":"cli-columns","title":"CLI Column Formatter","description":"cli-columns is a lightweight Node.js utility designed to format arrays of strings into neatly aligned, columnated lists suitable for command-line interfaces. It is particularly noted for its robust handling of both Unicode characters and ANSI escape codes (e.g., for colored text) by accurately calculating visible widths, preventing visual misalignment common in other simpler columnizers. The current stable version is 4.0.0, which notably addressed a ReDoS vulnerability in its upstream dependencies and updated its minimum Node.js requirement to version 10 or higher. While its release cadence may appear measured, the project prioritizes stability and precise rendering for CLI output. Key differentiators include customizable padding characters, column spacing, newline characters, optional sorting, and the ability to set a maximum output width, often defaulting to `process.stdout.columns`.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/shannonmoeller/cli-columns","tags":["javascript","ansi","cli","column","columnate","columns","grid","list","log"],"install":[{"cmd":"npm install cli-columns","lang":"bash","label":"npm"},{"cmd":"yarn add cli-columns","lang":"bash","label":"yarn"},{"cmd":"pnpm add cli-columns","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The 'columns' function is the default export. Using named import 'cli-columns' might result in undefined in some ESM environments.","wrong":"import { columns } from 'cli-columns';","symbol":"columns","correct":"import columns from 'cli-columns';"},{"note":"In CommonJS, the module exports the 'columns' function directly as its default export.","wrong":"const { columns } = require('cli-columns');","symbol":"columns","correct":"const columns = require('cli-columns');"},{"note":"While 'import * as' can work, the direct default import is cleaner and more idiomatic for this module's export style.","wrong":"import * as cliColumns from 'cli-columns'; const columns = cliColumns.default;","symbol":"columns","correct":"import columns from 'cli-columns';"}],"quickstart":{"code":"import columns from 'cli-columns';\nimport chalk from 'chalk';\n\nconst values = [\n    'blue' + chalk.bgBlue('berry'),\n    '笔菠萝' + chalk.yellow('苹果笔'),\n    chalk.red('apple'), 'pomegranate',\n    'durian', chalk.green('star fruit'),\n    'パイナップル', 'apricot', 'banana',\n    'pineapple', chalk.bgRed.yellow('orange'),\n    'long-long-item-that-will-wrap-if-width-is-too-small'\n];\n\n// Basic usage, uses process.stdout.columns for width\nconsole.log('--- Default Columnation ---');\nconsole.log(columns(values));\n\n// Custom width and no sorting\nconsole.log('\\n--- Custom Width (40) & Unsorted ---');\nconsole.log(columns(values, { width: 40, sort: false }));\n\n// Custom padding character\nconsole.log('\\n--- Custom Padding Character (\".\") ---');\nconsole.log(columns(values, { character: '.' }));","lang":"javascript","description":"Demonstrates basic usage of `cli-columns` to format a list of strings, including those with Unicode and ANSI colors, into columns. It also shows how to customize width, sorting, and padding."},"warnings":[{"fix":"Upgrade Node.js to version 10 or higher, or explicitly install `cli-columns@3.x` if older Node.js versions are unavoidable (e.g., `npm install cli-columns@3`).","message":"Version 4.0.0 of `cli-columns` now requires Node.js version 10 or greater. Projects running on older Node.js versions must upgrade their environment or stick to `cli-columns@3.x`.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Upgrade to `cli-columns@4.0.0` or newer to ensure you have the patched dependencies. Run `npm install cli-columns@latest`.","message":"Version 4.0.0 includes updated dependencies to address an upstream Regular Expression Denial of Service (ReDoS) vulnerability. Older versions of `cli-columns` (prior to 4.0.0) may be exposed to this vulnerability through their transitive dependencies.","severity":"breaking","affected_versions":"<4.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Change the import statement to `import columns from 'cli-columns';` in your ES module file.","cause":"Attempting to use `require()` syntax in an ES Module context (e.g., a file with `\"type\": \"module\"` in `package.json` or a `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Use the correct default import syntax: `import columns from 'cli-columns';`.","cause":"Incorrectly importing the `columns` function using named import syntax (`import { columns } from 'cli-columns';`) when it's exported as a default.","error":"TypeError: cli_columns is not a function"},{"fix":"Ensure the argument passed to `columns()` is an array where all elements are strings. For example: `columns(['string1', 'string2'])`.","cause":"Providing a non-array or an array containing non-string elements to the `columns` function. The library expects an array of strings.","error":"Error: The 'values' argument must be an Array<String>"}],"ecosystem":"npm","meta_description":null}