{"name":"cli-truncate","version":"6.1.1","description":"Truncate a string to a specific width in the terminal","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/cli-truncate.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=22"},"scripts":{"test":"xo && ava && tsd"},"keywords":["truncate","ellipsis","text","limit","slice","cli","terminal","term","shell","width","ansi","string"],"dependencies":{"slice-ansi":"^9.0.0","string-width":"^8.2.0"},"devDependencies":{"ava":"^7.0.0","tsd":"^0.33.0","xo":"^2.0.2"},"gitHead":"00818cbd97f5bd6c9b8af39f19c0cd1e42971e54","types":"./index.d.ts","_id":"cli-truncate@6.1.1","bugs":{"url":"https://github.com/sindresorhus/cli-truncate/issues"},"homepage":"https://github.com/sindresorhus/cli-truncate#readme","_nodeVersion":"24.18.0","_npmVersion":"11.18.0","dist":{"integrity":"sha512-06p9vyLahLa4zkGcgsGxU6iEkSOiuI4fhCH6Emhe2lPAcoUv73n72DnODsnHA+5wwXGnV0n9M9/qOQJSjYhFhw==","shasum":"35ae66a040eef357aedcfffd6149d847bf7a2eb1","tarball":"http://registry-npm.ywwl.com/cli-truncate/download/cli-truncate-6.1.1.tgz","fileCount":5,"unpackedSize":14261,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDGJUW1WYyLAVLaSgfgXWwsgcIXPYscJ6WPiMFibtim3gIhAP6anmI6YyDo54uPIqIUjBCGNXV/rcPWz1ZXvjB6Zu9Z"}],"size":4226,"noattachment":false,"key":"/cli-truncate/-/cli-truncate-6.1.1.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cli-truncate_6.1.1_1783611606446_0.4942648087167716"},"_hasShrinkwrap":false,"readme":"# cli-truncate\n\n> Truncate a string to a specific width in the terminal\n\nGracefully handles [ANSI escapes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles). Like a string styled with [`chalk`](https://github.com/chalk/chalk). It also supports Unicode surrogate pairs and fullwidth characters.\n\n## Install\n\n```sh\nnpm install cli-truncate\n```\n\n## Usage\n\n```js\nimport cliTruncate from 'cli-truncate';\n\ncliTruncate('unicorn', 4);\n//=> 'uni…'\n\n// Truncate at different positions\ncliTruncate('unicorn', 4, {position: 'start'});\n//=> '…orn'\n\ncliTruncate('unicorn', 4, {position: 'middle'});\n//=> 'un…n'\n\ncliTruncate('unicorns rainbow dragons', 6, {position: 'end'});\n//=> 'unico…'\n\ncliTruncate('\\u001B[31municorn\\u001B[39m', 4);\n//=> '\\u001B[31muni…\\u001B[39m'\n\n> [!NOTE]\n> When truncating styled text (ANSI escapes), the truncation character inherits the style at the breaking point for `position: 'start'` and `position: 'end'`. This does not apply to `position: 'middle'`.\n\n// Truncate Unicode surrogate pairs\ncliTruncate('uni\\uD83C\\uDE00corn', 5);\n//=> 'uni\\uD83C\\uDE00…'\n\n// Truncate fullwidth characters\ncliTruncate('안녕하세요', 3);\n//=> '안…'\n\n// Truncate the paragraph to the terminal width\nconst paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.';\ncliTruncate(paragraph, process.stdout.columns ?? 80);\n//=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…'\n```\n\n## API\n\n### cliTruncate(text, columns, options?)\n\n#### text\n\nType: `string`\n\nThe text to truncate.\n\n#### columns\n\nType: `number`\n\nThe finite number of columns to occupy in the terminal.\n\n#### options\n\nType: `object`\n\n##### position\n\nType: `string`\\\nDefault: `'end'`\\\nValues: `'start' | 'middle' | 'end'`\n\nThe position to truncate the string.\n\n##### space\n\nType: `boolean`\\\nDefault: `false`\n\nAdd a space between the text and the ellipsis.\n\n```js\nimport cliTruncate from 'cli-truncate';\n\ncliTruncate('unicorns', 5, {space: false});\n//=> 'unic…'\n\ncliTruncate('unicorns', 5, {space: true});\n//=> 'uni …'\n\ncliTruncate('unicorns', 6, {position: 'start', space: true});\n//=> '… orns'\n\ncliTruncate('unicorns', 7, {position: 'middle', space: true});\n//=> 'uni … s'\n```\n\n##### preferTruncationOnSpace\n\nType: `boolean`\\\nDefault: `false`\n\nTruncate the string from a whitespace if it is within 3 characters from the actual breaking point.\n\n```js\nimport cliTruncate from 'cli-truncate';\n\ncliTruncate('unicorns rainbow dragons', 20, {position: 'start', preferTruncationOnSpace: true});\n//=> '…rainbow dragons'\n\n// Without preferTruncationOnSpace\ncliTruncate('unicorns rainbow dragons', 20, {position: 'start'});\n//=> '…rns rainbow dragons'\n\ncliTruncate('unicorns rainbow dragons', 20, {position: 'middle', preferTruncationOnSpace: true});\n//=> 'unicorns…dragons'\n\ncliTruncate('unicorns rainbow dragons', 6, {position: 'end', preferTruncationOnSpace: true});\n//=> 'unico…'\n\n// preferTruncationOnSpace has no effect if space isn't found within 3 characters\ncliTruncate('unicorns rainbow dragons', 6, {position: 'middle', preferTruncationOnSpace: true});\n//=> 'uni…ns'\n```\n\n##### truncationCharacter\n\nType: `string`\\\nDefault: `…`\n\nThe character to use at the breaking point.\n\n```js\nimport cliTruncate from 'cli-truncate';\n\ncliTruncate('unicorns', 5, {position: 'end'});\n//=> 'unic…'\n\ncliTruncate('unicorns', 5, {position: 'end', truncationCharacter: '.'});\n//=> 'unic.'\n\ncliTruncate('unicorns', 5, {position: 'end', truncationCharacter: ''});\n//=> 'unico'\n```\n\n## Related\n\n- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes\n- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes\n","publish_time":1783611606568,"_cnpm_publish_time":1783611606568,"dist-tags":{"latest":"6.2.0"}}