
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
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 23,577,584 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.