Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
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 10,915,938 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.