Get the visual width of a string - the number of columns required to display it
Installations
npm install string-width
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>=18
Node Version
18.20.2
NPM Version
10.6.0
Score
99.4
Supply Chain
86.7
Quality
76.9
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (95.28%)
TypeScript (4.72%)
Developer
sindresorhus
Download Statistics
Total Downloads
26,410,883,290
Last Day
30,029,561
Last Week
138,311,974
Last Month
620,525,606
Last Year
7,277,934,331
GitHub Statistics
483 Stars
65 Commits
31 Forks
12 Watching
1 Branches
13 Contributors
Bundle Size
18.65 kB
Minified
4.53 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
7.2.0
Package Id
string-width@7.2.0
Unpacked Size
7.59 kB
Size
2.92 kB
File Count
5
NPM Version
10.6.0
Node Version
18.20.2
Publised On
30 Jun 2024
Total Downloads
Cumulative downloads
Total Downloads
26,410,883,290
Last day
-3.5%
30,029,561
Compared to previous day
Last week
-14.7%
138,311,974
Compared to previous week
Last month
5.4%
620,525,606
Compared to previous month
Last year
32.1%
7,277,934,331
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
string-width
Get the visual width of a string - the number of columns required to display it
Some Unicode characters are fullwidth and use double the normal width. ANSI escape codes are stripped and doesn't affect the width.
Useful to be able to measure the actual width of command-line output.
Install
1npm install string-width
Usage
1import stringWidth from 'string-width'; 2 3stringWidth('a'); 4//=> 1 5 6stringWidth('古'); 7//=> 2 8 9stringWidth('\u001B[1m古\u001B[22m'); 10//=> 2
API
stringWidth(string, options?)
string
Type: string
The string to be counted.
options
Type: object
ambiguousIsNarrow
Type: boolean
Default: true
Count ambiguous width characters as having narrow width (count of 1) instead of wide width (count of 2).
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.
countAnsiEscapeCodes
Type: boolean
Default: false
Whether ANSI escape codes should be counted.
Related
- string-width-cli - CLI for this module
- string-length - Get the real length of a string
- widest-line - Get the visual width of the widest line in a string
- get-east-asian-width - Determine the East Asian Width of a Unicode character
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
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
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
Found 11/30 approved changesets -- score normalized to 3
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
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/string-width/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/string-width/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
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
4.3
/10
Last Scanned on 2025-01-20
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to string-width
power-assert-util-string-width
calculates width of given string
is-fullwidth-code-point
Check if the character represented by a given Unicode code point is fullwidth
cli-truncate
Truncate a string to a specific width in the terminal
get-east-asian-width
Determine the East Asian Width of a Unicode character