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.
Verified import paths — ran on the pinned version, not inferred.
The package exports the `cliWidth` function as its default export. While TypeScript might sometimes allow named import, the intended usage is a default import.
This is the standard CommonJS `require` syntax for Node.js environments. The package is compatible with both CJS and ESM.
For type-only imports in TypeScript, use `import type` to ensure no runtime code is generated.
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.
Breaking-change detection hasn't run for this library yet.
CVE tracking and dependency tree are planned for a later release.