
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
widest-line
Advanced tools
Get the visual width of the widest line in a string - the number of columns required to display it
Get the visual width of the widest line in 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 know the maximum width a string will take up in the terminal.
npm install widest-line
import widestLine from 'widest-line';
widestLine('古\n\u001B[1m@\u001B[22m');
//=> 2
The string-width package is similar to widest-line in that it is used to calculate the visual width of a string - the number of characters that will be displayed on a terminal. Unlike widest-line, string-width does not specifically focus on multi-line strings but rather calculates the width of a single line, taking into account Unicode characters and ANSI escape codes.
The cli-truncate package provides functionality to truncate a string to a specific width in the terminal, gracefully handling the presence of ANSI escape codes. While it does not calculate the width of lines, it is related in the sense that it deals with the visual formatting of text in a terminal environment, similar to what widest-line does.
The term-size package is used to get the size (columns and rows) of the terminal window. It is not directly related to calculating the width of strings, but it can be used in conjunction with widest-line to ensure that the content fits within the terminal's current size.
FAQs
Get the visual width of the widest line in a string - the number of columns required to display it
The npm package widest-line receives a total of 25,271,377 weekly downloads. As such, widest-line popularity was classified as popular.
We found that widest-line demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.