Socket
Socket
Sign inDemoInstall

wcwidth

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wcwidth

Port of C's wcwidth() and wcswidth()


Version published
Weekly downloads
20M
increased by2.78%
Maintainers
1
Install size
31.5 kB
Created
Weekly downloads
 

Package description

What is wcwidth?

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.

What are wcwidth's main functionalities?

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

Other packages similar to wcwidth

Readme

Source

wcwidth

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/)

Example

'한'.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.

Further explaination here

License

MIT

Keywords

FAQs

Last updated on 30 May 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc