🚀 Socket Launch Week 🚀 Day 1: Introducing .NET Support in Socket.Learn More

string-width

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-width

Get the visual width of a string - the number of columns required to display it

7.2.0
latest
Version published
Weekly downloads
184M
-7.47%
Maintainers
0
Weekly downloads
 
Created

What is string-width?

The string-width npm package is used to calculate and return the visual width of a string - the number of columns required to display it. This is particularly useful when dealing with strings containing characters that may take up more than one column in terminals or monospaced fonts, such as emojis or certain international characters.

What are string-width's main functionalities?

Calculate string width

This feature calculates the visual width of a string. For example, an ASCII character has a width of 1, while many CJK characters have a width of 2. Emojis can also have a width of 2 or more.

const stringWidth = require('string-width');
console.log(stringWidth('古')); // 2
console.log(stringWidth('a')); // 1
console.log(stringWidth('👍')); // 2

Other packages similar to string-width

FAQs

Package last updated on 30 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts