{"name":"cli-truncate","version":"5.1.0","keywords":["truncate","ellipsis","text","limit","slice","cli","terminal","term","shell","width","ansi","string"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"cli-truncate@5.1.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/cli-truncate#readme","bugs":{"url":"https://github.com/sindresorhus/cli-truncate/issues"},"dist":{"shasum":"bb12607a62f0e4bb91a54aa4653b23347900bb55","tarball":"http://registry-npm.ywwl.com/cli-truncate/download/cli-truncate-5.1.0.tgz","fileCount":5,"integrity":"sha512-7JDGG+4Zp0CsknDCedl0DYdaeOhc46QNpXi3NLQblkZpXXgA6LncLDUUyvrjSvZeF3VRQa+KiMGomazQrC1V8g==","signatures":[{"sig":"MEYCIQDSGzqG7UV+jET+SjIheMT2L8GQHxyzHcSXa629BaKZ/wIhAMfPPIS+lgV8Eb+oBd3TniGG4/3rAiu20YRE6v6dciXi","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":13083,"size":3917,"noattachment":false,"key":"/cli-truncate/-/cli-truncate-5.1.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=20"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"fa0cd8e25aa3f3f39737d775b71c194b2c79b301","scripts":{"test":"xo && ava && tsd"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/cli-truncate.git","type":"git"},"_npmVersion":"10.9.2","description":"Truncate a string to a specific width in the terminal","directories":{},"sideEffects":false,"_nodeVersion":"20.19.1","dependencies":{"slice-ansi":"^7.1.0","string-width":"^8.0.0"},"_hasShrinkwrap":false,"devDependencies":{"xo":"^1.2.2","ava":"^6.4.1","tsd":"^0.33.0"},"_npmOperationalInternal":{"tmp":"tmp/cli-truncate_5.1.0_1757966793791_0.5593671551347861","host":"s3://npm-registry-packages-npm-production"},"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":1757966794000,"_cnpm_publish_time":1757966794000,"dist-tags":{"latest":"6.2.0"}}