string-width

Get the visual width of strings for precise text layout.

EstablishedOpen SourceLow lock-in

Pricing

Free tier

Flat rate

Adoption

Stable

License

Open Source

Data freshness

Aging · Jun 8, 2026

Overview

What is string-width?

string-width is a utility that calculates the number of columns required to display a string, which is essential for aligning and formatting text in various applications. It supports Unicode characters, making it useful for internationalized software.

Key differentiator

string-width stands out as a lightweight, dependency-free library for calculating string width, making it ideal for developers who need precise control over text formatting in their projects.

Capability profile

Capability Radar

Ease of StartEcosystemValueMaturityFlexibilityScale Ready

Honest assessment

Strengths & Weaknesses

↑ Strengths

Supports Unicode characters for accurate width calculation.medium

Lightweight and easy to integrate into projects.medium

No external dependencies, making it simple to use.medium

↓ Weaknesses

Limited functionality for complex text formattinghigh

string-width only calculates the width of strings and does not handle more complex text formatting or alignment tasks.

No built-in support for right-to-left languagesmedium

The tool primarily supports left-to-right text, which may lead to incorrect width calculations for right-to-left languages like Arabic and Hebrew without additional custom handling.

Does not account for font metrics or rendering differenceshigh

string-width calculates the number of columns based on character widths but does not consider how different fonts might render these characters, which can lead to discrepancies in actual display width.

Does not handle combining characters wellmedium

The tool may struggle with Unicode combining characters that modify the preceding character, potentially leading to inaccurate width calculations for such text.

Fit analysis

Who is it for?

✓ Best for

Developers working on CLI tools who need precise text alignment and formatting.

Projects requiring accurate width calculation for internationalized strings.

Applications that display formatted text in a terminal or console environment.

✕ Not a fit for

Real-time text processing applications where performance is critical.

Large-scale data processing tasks where the overhead of string manipulation could be significant.

Cost structure

Pricing

Free Tier

Available

Open source — free to use

Starts at

$0

Model

Flat rate

Enterprise

None

Performance benchmarks

How Fast Is It?

Ecosystem

Relationships

Next step

Get Started with string-width

Step-by-step setup guide with code examples and common gotchas.

View Setup Guide →