
Security News
Next.js Patches Critical Middleware Vulnerability (CVE-2025-29927)
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
widest-line
Advanced tools
Get the visual width of the widest line in a string - the number of columns required to display it
The widest-line npm package is designed to find and return the length of the longest line in a string, taking into account and handling ANSI escape codes which are often used for coloring or styling terminal output. This can be particularly useful when trying to format console output or determine the necessary width for a text-based UI component.
Get the length of the longest line in a string
This feature allows you to determine the length of the longest line in a given multi-line string, which can be useful for formatting console output or for creating text-based UI components that need to accommodate variable-length content.
"const widestLine = require('widest-line');
const text = 'Some string with\nseveral lines\nand varying lengths.';
const longestLineLength = widestLine(text);
console.log(longestLineLength); // Outputs the length of the widest line"
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.
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
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 12,080,328 weekly downloads. As such, widest-line popularity was classified as popular.
We found that widest-line demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Next.js has patched a critical vulnerability (CVE-2025-29927) that allowed attackers to bypass middleware-based authorization checks in self-hosted apps.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.