{"id":10637,"library":"cli-util","title":"CLI Utilities Toolkit","description":"cli-util is an abandoned Node.js package providing a collection of utility functions designed for building command-line interface applications. It offers basic functionalities for logging, styled output (colors, headers, indentation), string padding, and column formatting. The package is built on top of very old versions of `colors` (0.6.2) and `commander` (2.0.0) for styling and argument parsing, respectively. Its last update was in 2014, making it unsuitable for modern projects due to outdated dependencies, lack of maintenance, and CommonJS-only module format. There is no active development or defined release cadence, and the current stable version is 1.1.27.","status":"abandoned","version":"1.1.27","language":"javascript","source_language":"en","source_url":"https://github.com/freeformsystems/cli-util","tags":["javascript","cli","string","util"],"install":[{"cmd":"npm install cli-util","lang":"bash","label":"npm"},{"cmd":"yarn add cli-util","lang":"bash","label":"yarn"},{"cmd":"pnpm add cli-util","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for adding ANSI color and style to terminal output. Note: this old version modifies String.prototype.","package":"colors","optional":false},{"reason":"Used for parsing command-line arguments and options. Note: this is a very old version (2.0.0) with a significantly different API than current versions.","package":"commander","optional":false},{"reason":"Used for command-line argument parsing based on usage strings. Note: this is a very old version (0.6.0).","package":"docopt","optional":false}],"imports":[{"note":"The package is CommonJS-only and does not support ES modules directly. Functions are accessed via the main export object.","wrong":"import { log } from 'cli-util';","symbol":"log","correct":"const cli = require('cli-util');\ncli.log('message');"},{"note":"The 'colors' library is an internal dependency (v0.6.2) that modifies String.prototype, making methods like `.green` available on strings after the `cli-util` module is required. It's not directly exposed for import.","wrong":"import colors from 'colors';","symbol":"colors","correct":"const cli = require('cli-util');\ncli.log('Hello'.green); // Uses String.prototype modification from the internal 'colors' dependency"},{"note":"All utility functions are properties of the main module export.","wrong":"const { header } = require('cli-util'); // While technically correct, it's more idiomatic for CJS to assign the entire module.exports object.","symbol":"header","correct":"const cli = require('cli-util');\ncli.header('My CLI Tool', { indent: 2 });"}],"quickstart":{"code":"const cli = require('cli-util');\n\n// Logging with colors (due to internal 'colors' dependency modifying String.prototype)\ncli.log('Starting CLI application...'.green);\ncli.warn('A warning message.'.yellow);\ncli.error('An error occurred!'.red);\n\n// Displaying a header\ncli.header('CLI-Util Example', { indent: 1 });\n\n// Formatting lines and columns\nconst data = [\n  ['Name:', 'John Doe'],\n  ['Email:', 'john.doe@example.com'],\n  ['Status:', 'Active']\n];\ncli.lines(data.map(row => cli.pad(row[0], 10) + row[1]));\n\nconsole.log(cli.line()); // Prints a separator line\n\n// Example of padding\nconst paddedText = cli.rightPad('Hello', 15, '.');\ncli.log(`Padded text: ${paddedText}`);\n\ncli.ok('Application finished successfully.'.blue);\n","lang":"javascript","description":"Demonstrates basic usage of cli-util for logging, styling output with colors, displaying headers, and formatting text in columns and with padding."},"warnings":[{"fix":"Migrate to actively maintained CLI utility libraries such as `commander.js` (latest), `yargs`, `chalk`, `ora`, or `enquirer` for modern CLI development.","message":"The package is abandoned since 2014 and is not maintained. It relies on extremely old versions of dependencies (e.g., `colors@0.6.2`, `commander@2.0.0`, `docopt@0.6.0`) that have known security vulnerabilities, outdated APIs, or adverse side effects (like `colors` modifying `String.prototype`). Using this package in modern applications is highly discouraged and poses security risks and compatibility issues.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Avoid using this package. If absolutely necessary, be aware of the global `String.prototype` modifications and test thoroughly for conflicts. Consider encapsulating its usage if possible.","message":"The `colors` dependency (version 0.6.2) included in this package modifies the global `String.prototype`. This means methods like `.red`, `.green`, `.yellow`, etc., become available on all string objects globally after `cli-util` is required. This can lead to unexpected behavior, conflicts with other libraries, or make code harder to reason about due to global state modification.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If used in an ESM project, you must use `require()` to import it, typically by wrapping it or adjusting your build setup for CJS compatibility. For example: `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const cli = require('cli-util');` However, given the 'abandoned' status, migrating away is the recommended fix.","message":"This package is strictly CommonJS (CJS) and does not provide ES module (ESM) exports. Attempting to `import` it in an ESM context will result in a runtime error.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to current, actively maintained CLI argument parsing libraries like the latest `commander.js` or `yargs`. This will require a complete rewrite of the argument parsing logic.","message":"The `commander` (version 2.0.0) and `docopt` (version 0.6.0) dependencies are severely outdated. Their APIs have changed significantly over many major versions since then, and they lack modern features, bug fixes, and security patches. Code relying on these old APIs will be incompatible with newer versions and potentially insecure.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to CommonJS `require()` syntax: `const cli = require('cli-util');`","cause":"Attempting to import `cli-util` using ES module `import` syntax in a JavaScript module when `cli-util` is a CommonJS module.","error":"ERR_REQUIRE_ESM: require() of ES Module ...cli-util' from ... not supported."},{"fix":"Ensure `const cli = require('cli-util');` is called at least once in your application's lifecycle before attempting to use string color methods. Note that this package is abandoned, and `colors` modifies `String.prototype`.","cause":"The `colors` library, which adds color methods to `String.prototype`, was not loaded or `cli-util` (which loads `colors`) was not required.","error":"TypeError: \"some string\".green is not a function"}],"ecosystem":"npm"}