cli-width is a JavaScript utility for Node.js environments that accurately determines the current width of the stdout window. It employs a robust fallback mechanism, checking `tty` information, `output.columns` property, a custom `CLI_WIDTH` environment variable, and finally a configurable default width. The package is currently stable at version 4.1.0 and is actively maintained, with releases occurring as needed for bug fixes or minor enhancements. It is designed to be lightweight and provides TypeScript types out-of-the-box, making it suitable for modern Node.js projects that require responsive command-line interfaces. Its primary differentiator is the comprehensive fallback strategy to ensure a width is always returned.
npm install cli-widthVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to get the CLI width with default settings, and how to configure it with custom options for default width, output stream, and tty module. It also shows how the `CLI_WIDTH` environment variable can influence the detected width.
Refactor calls to `cliWidth()` to pass an object literal for options: `cliWidth({ defaultWidth: 80, output: process.stderr })`.Always provide a sensible `defaultWidth` in your options if a non-zero width is critical for your application in all environments: `cliWidth({ defaultWidth: 80 })`. You can also set the `CLI_WIDTH` environment variable.This package is intended for Node.js environments. If bundling for a browser, consider conditional imports or a browser-specific alternative for width detection. For Node.js, ensure `tty` is resolvable.
Change `import { cliWidth } from 'cli-width';` to `import cliWidth from 'cli-width';` or `const cliWidth = require('cli-width');`.If your project is configured for ESM (e.g., `"type": "module"` in `package.json`), use `import cliWidth from 'cli-width';`. If you need to use `require` in an ESM file, consider dynamic `import()` or review your build setup.
No dependency data recorded yet.