string-width
npmv8.2.2TypeScriptGet the visual width of a string - the number of columns required to display it
Safe to adopt
Yes — string-width scores well across adoption, maintenance, weight, supply chain, and licensing. 508.6M downloads per week and 3 known dependents. Last published 63 days ago. 6 releases in the last 2 years.
- AAdoption: grade A, Excellent.
508.6M downloads per week and 3 known dependents.
- AMaintenance: grade A, Excellent.
Last published 63 days ago. 6 releases in the last 2 years.
- AWeight: grade A, Excellent.
Pulls in 2 transitive packages, about 26 KB installed (at least — some of the tree is still being crawled).
- BSupply chain: grade B, Good.
This package has a single maintainer (bus factor of 1).
- ALicense: grade A, Excellent.
MIT — permissive, with no copyleft found in the dependency tree.
Grades are computed deterministically from registry metadata collected by PackageGraph — downloads, dependents, publish dates, the resolved dependency tree, maintainer count, and declared licenses. No third-party scores are used.
Install cost
What you actually take on by adding string-width to a project.
Runtime packages this one declares itself.
Distinct packages in the full runtime tree, deduplicated the way a package manager would.
Unpacked size of this package plus its entire runtime tree.
Longest resolved dependency chain below this package.
Part of this dependency tree has not been crawled yet, so these figures are a lower bound rather than a final total.
Licenses in the dependency tree
Every license you inherit by installing string-width, not just its own. Check this before a legal review, not after.
Compatibility
- Node.js
- node >=20
- Module format
- ESM only
- TypeScript
- Types included
- Install scripts
- None
Quick start
A usage example from the string-width README.
import stringWidth from 'string-width';
stringWidth('a');
//=> 1
stringWidth('古');
//=> 2
stringWidth('\u001B[1m古\u001B[22m');
//=> 2string-width vs the alternatives
Packages solving a similar problem in the npm ecosystem, compared on the signals that drive an adoption decision.
| Package | Weekly downloads | Dependents | License | Last release |
|---|---|---|---|---|
| string-widththis page | 508.6M | 3 | MIT | 2 months ago |
| get-east-asian-width | 77.1M | 1 | MIT | 7 days ago |
| terminal-link | 21.2M | 1 | MIT | 6 days ago |
| string-length | 0 | 3 | MIT | 6 days ago |
| supports-hyperlinks | 40.3M | 1 | MIT | 6 days ago |
| log-symbols | 0 | 1 | MIT | 6 days ago |
Dependencies
Declared by string-width v8.2.2. Runtime dependencies are installed with the package; dev dependencies are not.
Runtime (2)
Dev (3)
Used by
Popular packages that depend on string-width.
Relationship graph
Dependencies (left) and dependents (right) of string-width.
Frequently installed together
TypeScript definitions for node
An AST-based pattern checker for JavaScript.
BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
Like which(1) unix command. Find the first instance of an executable in the PATH.
the mighty option parser used by yargs
easily create complex multi-column command-line-interfaces
A tiny (183B to 210B) and fast utility to ascend parent directories
the bare-bones internationalization library used by yargs
TypeScript definitions for chai
Cross platform child_process#spawn and child_process#spawnSync
[](https://travis-ci.org/stefanpenner/get-caller-file) [](https://ci.a
Babel preset for TypeScript.
Release history
6 releases in the last two years, typically about 73 days apart.
| Version | Published | Size | License |
|---|---|---|---|
| 8.2.2latest | 2 months ago | 11 KB | MIT |
| 8.2.1 | 4 months ago | 11 KB | MIT |
| 8.2.0 | 6 months ago | 9.0 KB | MIT |
| 8.1.1 | 7 months ago | 7.9 KB | MIT |
| 8.1.0 | 1 year ago | 7.8 KB | MIT |
| 8.0.0 | 1 year ago | 8.7 KB | MIT |
| 7.2.0 | 2 years ago | 7.6 KB | MIT |
| 7.1.0 | 2 years ago | 6.5 KB | MIT |
| 7.0.0 | 2 years ago | 6.4 KB | MIT |
| 6.1.0 | 3 years ago | 5.7 KB | MIT |
| 6.0.0 | 3 years ago | 5.8 KB | MIT |
| 5.1.2 | 4 years ago | 5.6 KB | MIT |
| 5.1.1 | 4 years ago | 5.7 KB | MIT |
| 5.1.0 | 4 years ago | 5.6 KB | MIT |
| 4.2.3 | 5 years ago | 5.0 KB | MIT |
Overview
string-width is an npm package that get the visual width of a string - the number of columns required to display it. It is extremely widely used, with about 508.6M downloads per week and 3 known dependents in the graph. The latest version is 8.2.2, released under the MIT license.
Who should use it
Teams working in the npm ecosystem who need get the visual width of a string - the number of columns required to display it and value a battle-tested, widely-adopted solution.
When not to use it
Consider an alternative if you need to or if a more actively-maintained option better fits your npm stack.
Pros
- Large, well-established user base (508.6M weekly downloads).
- Ships TypeScript type definitions.
- Clear open-source license (MIT).
Cons
- No significant drawbacks detected from available metadata.
Auto-generated from collected registry metadata. No external claims are inferred.
Maintainers
Funding
Frequently asked questions
Should I use string-width?
Yes — string-width scores well across adoption, maintenance, weight, supply chain, and licensing. 508.6M downloads per week and 3 known dependents. Last published 63 days ago. 6 releases in the last 2 years.
How do I install string-width?
Run `npm install string-width` to add string-width to your npm project.
How many dependencies does string-width have?
string-width declares 5 direct dependencies and pulls in 2 packages in total once its runtime tree is resolved totalling about 26 KB on disk.
What license is string-width released under?
string-width is distributed under the MIT license.
How popular is string-width?
string-width has approximately 508,567,931 downloads per week and 3 known dependent packages.
Is string-width still maintained?
The most recent release of string-width (v8.2.2) was published 2 months ago.
Does string-width run install scripts?
No. string-width does not define preinstall, install, or postinstall scripts, so installing it does not execute publisher-supplied code.