
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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 12,151,677 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.