Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
eastasianwidth
Advanced tools
The eastasianwidth npm package is a utility for determining the East Asian Width property of Unicode characters, which is useful for handling text display in console applications or any other context where monospaced font rendering is involved. It helps to classify characters based on their expected display width, especially when dealing with East Asian characters.
Check character width
This feature allows you to check the East Asian Width property of a character. The output 'F' indicates that the character is a fullwidth character.
"use strict";
const eastasianwidth = require('eastasianwidth');
let char = 'あ';
let width = eastasianwidth.eastAsianWidth(char);
console.log(width); // Output: 'F' (Fullwidth)
Determine if a character is fullwidth
This feature provides a boolean indicating whether a character is fullwidth or not.
"use strict";
const eastasianwidth = require('eastasianwidth');
let char = 'あ';
let isFullwidth = eastasianwidth.isFullwidth(char);
console.log(isFullwidth); // Output: true
Determine if a character is halfwidth
This feature provides a boolean indicating whether a character is halfwidth or not.
"use strict";
const eastasianwidth = require('eastasianwidth');
let char = 'ア'; // Halfwidth Katakana Letter A
let isHalfwidth = eastasianwidth.isHalfwidth(char);
console.log(isHalfwidth); // Output: true
The string-width package is used to calculate and return the visual width of a string in terminal, taking into account East Asian Width. It is similar to eastasianwidth but works on strings rather than individual characters.
The wcwidth package is another utility for determining the number of terminal column cells a string will occupy. It's based on the wcwidth() function defined in POSIX.1-2001 and POSIX.1-2008, which is similar to what eastasianwidth does but with a focus on compatibility with POSIX standards.
Get East Asian Width from a character.
'F'(Fullwidth), 'H'(Halfwidth), 'W'(Wide), 'Na'(Narrow), 'A'(Ambiguous) or 'N'(Natural).
Original Code is 東アジアの文字幅 (East Asian Width) の判定 - 中途.
$ npm install eastasianwidth
var eaw = require('eastasianwidth');
console.log(eaw.eastAsianWidth('₩')) // 'F'
console.log(eaw.eastAsianWidth('。')) // 'H'
console.log(eaw.eastAsianWidth('뀀')) // 'W'
console.log(eaw.eastAsianWidth('a')) // 'Na'
console.log(eaw.eastAsianWidth('①')) // 'A'
console.log(eaw.eastAsianWidth('ف')) // 'N'
console.log(eaw.characterLength('₩')) // 2
console.log(eaw.characterLength('。')) // 1
console.log(eaw.characterLength('뀀')) // 2
console.log(eaw.characterLength('a')) // 1
console.log(eaw.characterLength('①')) // 2
console.log(eaw.characterLength('ف')) // 1
console.log(eaw.length('あいうえお')) // 10
console.log(eaw.length('abcdefg')) // 7
console.log(eaw.length('¢₩。ᅵㄅ뀀¢⟭a⊙①بف')) // 19
FAQs
Get East Asian Width from a character.
The npm package eastasianwidth receives a total of 21,088,143 weekly downloads. As such, eastasianwidth popularity was classified as popular.
We found that eastasianwidth demonstrated a healthy version release cadence and project activity because the last version was released less than 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
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.