String Width TS

The definitive Visual Width calculator.

Perfect alignment for Emojis, CJK, and ANSI codes.

NPM VersionLicenseTypeScriptZero Dependencies
📏

Stop Guesstimating Widths

Why your terminal output looks broken, and how to fix it.

❌ The Wrong Way

console.log("Name".padEnd(10) + "Age");
console.log("古川".padEnd(10) + "25");

Name      Age
古川        25 <-- Misaligned!

✅ The string-width-ts Way

console.log(padString("Name", 10) + "Age");
console.log(padString("古川", 10) + "25");

Name      Age
古川      25 <-- Perfect!

Comparison

Featurestring-width-tsstring-widthwcwidth
TypeScript✅ Native⚠️ @types❌ No
Emoji Support✅ Advanced✅ Basic❌ No
String Manipulation✅ Pad/Truncate❌ No❌ No
Zero Dependencies✅ Yes❌ No❌ No

Contribution

We welcome contributions to string-width-ts!

  1. 1Fork the repository on GitHub
  2. 2Clone your fork locally
  3. 3Create a new branch & Commit your changes
  4. 4Open a Pull Request

License

MIT License

This project is free and open-source software licensed under the MIT License.

Copyright © 2025 Noor Mohammad

Support the Project

If this package saves you time, consider buying me a coffee.

Your support helps keep the utilities updated and well-documented. 🙏

Zero dependenciesType-safe
Buy me a coffeeBuy me a coffee

💝 Thank you for your support!