{"id":13396689,"url":"https://github.com/sindresorhus/cli-truncate","last_synced_at":"2026-03-01T09:02:01.192Z","repository":{"id":46463505,"uuid":"53652842","full_name":"sindresorhus/cli-truncate","owner":"sindresorhus","description":"Truncate a string to a specific width in the terminal","archived":false,"fork":false,"pushed_at":"2025-10-23T05:01:23.000Z","size":46,"stargazers_count":88,"open_issues_count":0,"forks_count":15,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-02-24T16:44:12.623Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/security.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2016-03-11T08:46:39.000Z","updated_at":"2025-11-27T09:19:26.000Z","dependencies_parsed_at":"2024-01-11T20:42:47.091Z","dependency_job_id":"4cef9736-024c-4f55-beb9-30b6a5ad41b2","html_url":"https://github.com/sindresorhus/cli-truncate","commit_stats":{"total_commits":30,"total_committers":9,"mean_commits":"3.3333333333333335","dds":0.2666666666666667,"last_synced_commit":"7080bf23f18ebca5557796711e520feac6fdf05a"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/sindresorhus/cli-truncate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcli-truncate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcli-truncate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcli-truncate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcli-truncate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/cli-truncate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fcli-truncate/sbom","scorecard":{"id":826165,"data":{"date":"2025-08-11","repo":{"name":"github.com/sindresorhus/cli-truncate","commit":"7080bf23f18ebca5557796711e520feac6fdf05a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.2,"checks":[{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/cli-truncate/main.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/cli-truncate/main.yml/main?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/main.yml:21","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: .github/security.md:1","Info: Found linked content: .github/security.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1","Info: Found text in security policy: .github/security.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Code-Review","score":2,"reason":"Found 7/30 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/main.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: license:0","Info: FSF or OSI recognized license: MIT License: license:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 7 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-23T16:40:59.419Z","repository_id":46463505,"created_at":"2025-08-23T16:40:59.419Z","updated_at":"2025-08-23T16:40:59.419Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29965419,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T06:55:38.174Z","status":"ssl_error","status_checked_at":"2026-03-01T06:53:04.810Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:01:00.185Z","updated_at":"2026-03-01T09:02:01.183Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["打印","Packages","JavaScript","包","Command-line utilities","目录"],"sub_categories":["Command-line utilities","命令行工具","命令行实用工具"],"readme":"# cli-truncate\n\n\u003e 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//=\u003e 'uni…'\n\n// Truncate at different positions\ncliTruncate('unicorn', 4, {position: 'start'});\n//=\u003e '…orn'\n\ncliTruncate('unicorn', 4, {position: 'middle'});\n//=\u003e 'un…n'\n\ncliTruncate('unicorns rainbow dragons', 6, {position: 'end'});\n//=\u003e 'unico…'\n\ncliTruncate('\\u001B[31municorn\\u001B[39m', 4);\n//=\u003e '\\u001B[31muni…\\u001B[39m'\n\n\u003e [!NOTE]\n\u003e 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//=\u003e 'uni\\uD83C\\uDE00…'\n\n// Truncate fullwidth characters\ncliTruncate('안녕하세요', 3);\n//=\u003e '안…'\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);\n//=\u003e '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 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//=\u003e 'unic…'\n\ncliTruncate('unicorns', 5, {space: true});\n//=\u003e 'uni …'\n\ncliTruncate('unicorns', 6, {position: 'start', space: true});\n//=\u003e '… orns'\n\ncliTruncate('unicorns', 7, {position: 'middle', space: true});\n//=\u003e '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//=\u003e '…rainbow dragons'\n\n// Without preferTruncationOnSpace\ncliTruncate('unicorns rainbow dragons', 20, {position: 'start'});\n//=\u003e '…rns rainbow dragons'\n\ncliTruncate('unicorns rainbow dragons', 20, {position: 'middle', preferTruncationOnSpace: true});\n//=\u003e 'unicorns…dragons'\n\ncliTruncate('unicorns rainbow dragons', 6, {position: 'end', preferTruncationOnSpace: true});\n//=\u003e '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//=\u003e '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//=\u003e 'unic…'\n\ncliTruncate('unicorns', 5, {position: 'end', truncationCharacter: '.'});\n//=\u003e 'unic.'\n\ncliTruncate('unicorns', 5, {position: 'end', truncationCharacter: ''});\n//=\u003e 'unico'\n\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcli-truncate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fcli-truncate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fcli-truncate/lists"}