Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
The wcwidth npm package is designed to provide functionality for determining the display width of characters in the terminal. This is particularly useful for handling characters that may take up more than one column in width, such as certain emojis or characters from languages like Chinese, Japanese, and Korean. It helps in ensuring text alignment and proper spacing in terminal applications that deal with diverse character sets.
Calculate display width of a string
This feature allows you to calculate the display width of a string, which is essential for text alignment in terminal applications. The code sample demonstrates how to use wcwidth to determine the display width of English and Chinese text.
const wcwidth = require('wcwidth');
console.log(wcwidth('hello')); // Outputs: 5
console.log(wcwidth('你好')); // Outputs: 4
Similar to wcwidth, string-width calculates and returns the display width of a string in the terminal. It handles emojis and other wide characters as well. The main difference is in the implementation details and dependencies, where string-width might use a different approach or have updated character width mappings compared to wcwidth.
This package focuses on determining the East Asian Width property of characters, which is closely related to the functionality provided by wcwidth. While wcwidth calculates the display width considering various character properties, eastasianwidth specifically targets the classification of characters based on the East Asian Width attribute, which can be useful for applications dealing with East Asian languages.
Determine columns needed for a fixed-size wide-character string
wcwidth is a simple JavaScript port of wcwidth implemented in C by Markus Kuhn.
JavaScript port originally written by Woong Jun woong.jun@gmail.com (http://code.woong.org/)
'한'.length // => 1
wcwidth('한'); // => 2
'한글'.length // => 2
wcwidth('한글'); // => 4
wcwidth()
and its string version, wcswidth()
are defined by IEEE Std
1002.1-2001, a.k.a. POSIX.1-2001, and return the number of columns used
to represent the given wide character and string.
Markus's implementation assumes the wide character given to those functions to be encoded in ISO 10646, which is almost true for JavaScript's characters.
MIT
FAQs
Port of C's wcwidth() and wcswidth()
The npm package wcwidth receives a total of 17,331,168 weekly downloads. As such, wcwidth popularity was classified as popular.
We found that wcwidth 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.