{"id":13396731,"url":"https://github.com/sindresorhus/string-width","last_synced_at":"2026-02-18T18:03:46.094Z","repository":{"id":35074267,"uuid":"39222730","full_name":"sindresorhus/string-width","owner":"sindresorhus","description":"Get the visual width of a string - the number of columns required to display it","archived":false,"fork":false,"pushed_at":"2024-06-30T14:48:18.000Z","size":40,"stargazers_count":477,"open_issues_count":9,"forks_count":31,"subscribers_count":12,"default_branch":"main","last_synced_at":"2024-10-29T15:46:34.252Z","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":"altairsix/eventsource","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},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2015-07-16T22:05:16.000Z","updated_at":"2024-10-25T10:06:15.000Z","dependencies_parsed_at":"2024-04-15T04:13:36.378Z","dependency_job_id":"9446d43f-3c8c-4d32-83e3-2533c5183525","html_url":"https://github.com/sindresorhus/string-width","commit_stats":{"total_commits":65,"total_committers":13,"mean_commits":5.0,"dds":"0.29230769230769227","last_synced_commit":"ac09208fd52063c2ffaa4396c9b339fec05cab67"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fstring-width","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fstring-width/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fstring-width/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fstring-width/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/string-width/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256110,"owners_count":20909240,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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:01.478Z","updated_at":"2026-01-29T05:11:45.515Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","readme":"# string-width\n\n\u003e Get the visual width of a string - the number of columns required to display it\n\nSome Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.\n\nUseful to be able to measure the actual width of command-line output.\n\n## Install\n\n```sh\nnpm install string-width\n```\n\n## Usage\n\n```js\nimport stringWidth from 'string-width';\n\nstringWidth('a');\n//=\u003e 1\n\nstringWidth('古');\n//=\u003e 2\n\nstringWidth('\\u001B[1m古\\u001B[22m');\n//=\u003e 2\n```\n\n## API\n\n### stringWidth(string, options?)\n\n#### string\n\nType: `string`\n\nThe string to be counted.\n\n#### options\n\nType: `object`\n\n##### ambiguousIsNarrow\n\nType: `boolean`\\\nDefault: `true`\n\nCount [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).\n\n\u003e Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). **If the context cannot be established reliably, they should be treated as narrow characters by default.**\n\u003e - http://www.unicode.org/reports/tr11/\n\n##### countAnsiEscapeCodes\n\nType: `boolean`\\\nDefault: `false`\n\nWhether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.\n\n## Related\n\n- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module\n- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string\n- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string\n- [get-east-asian-width](https://github.com/sindresorhus/get-east-asian-width) - Determine the East Asian Width of a Unicode character\n","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["命令行","Packages","Repository","包","Command-line utilities","JavaScript","目录"],"sub_categories":["Command-line utilities","Text/String","命令行工具","命令行实用工具"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fstring-width","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fstring-width","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fstring-width/lists"}