cli-truncate is a JavaScript library designed for precisely truncating strings within a terminal environment, correctly accounting for the visual width occupied by characters, including those with ANSI escape codes (like colors and styles), Unicode surrogate pairs, and fullwidth characters. The current stable version is 6.0.0, which requires Node.js 22.x or later. The package has a consistent release cadence, often introducing new major versions to align with updated Node.js engine requirements, alongside minor and patch releases for bug fixes and feature enhancements. Its key differentiators lie in its robust handling of terminal-specific challenges: it ensures that styled text, such as output from `chalk`, is truncated accurately without breaking formatting, and it correctly measures the width of complex Unicode characters that standard `String.prototype.slice` or similar methods would misinterpret. It offers flexible truncation positions (start, middle, end) and options like `space` for adding a gap before the ellipsis and `preferTruncationOnSpace` to attempt truncation at a word boundary for better readability.
npm install cli-truncateVerified import paths — ran on the pinned version, not inferred.
Demonstrates truncating a long paragraph to the current terminal width, gracefully handling character widths and potential ANSI escape codes, for clean console output. It also shows using `preferTruncationOnSpace` for better readability.
Upgrade your Node.js environment to version 22 or higher, or downgrade `cli-truncate` to a compatible major version (e.g., v5 for Node.js 20, v4 for Node.js 18).
Update your import statements from `const cliTruncate = require('cli-truncate');` to `import cliTruncate from 'cli-truncate';`. Ensure your project is configured for ESM, potentially by adding `'type': 'module'` to your `package.json` or by using `.mjs` file extensions.Upgrade your Node.js environment to version 20 or higher, or downgrade `cli-truncate` to v4 if you need Node.js 18 support.
Upgrade your Node.js environment to version 18 or higher, or downgrade `cli-truncate` to v3 if you need Node.js 12.20+ support.
Be aware of this specific styling behavior if precise style continuity for the ellipsis in `position: 'middle'` is critical to your output design.
Change your import statement to `import cliTruncate from 'cli-truncate';`. Ensure your `package.json` has `'type': 'module'` or use `.mjs` file extension for your source file.
Upgrade your Node.js installation to version 22 or higher. Alternatively, install an older major version of `cli-truncate` that is compatible with your current Node.js version (e.g., `npm install cli-truncate@5` for Node.js 20).
No dependency data recorded yet.