Product
Introducing Socket Optimize
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.
get-east-asian-width
Advanced tools
The get-east-asian-width npm package is used to determine the East Asian Width properties of Unicode characters. This is useful for applications that need to handle text rendering, alignment, or width calculations in East Asian languages.
Get East Asian Width of a character
This feature allows you to get the East Asian Width property of a single character. In this example, the character 'あ' has a width property of 'W' (Wide).
const getEastAsianWidth = require('get-east-asian-width');
const width = getEastAsianWidth('あ');
console.log(width); // Output: 'W'
Get East Asian Width of a string
This feature allows you to get the East Asian Width properties of each character in a string. In this example, each character in the string 'こんにちは' has a width property of 'W' (Wide).
const getEastAsianWidth = require('get-east-asian-width');
const widths = 'こんにちは'.split('').map(getEastAsianWidth);
console.log(widths); // Output: ['W', 'W', 'W', 'W', 'W']
Check if a character is Fullwidth or Halfwidth
This feature allows you to check if a character is Fullwidth or Halfwidth. In this example, the character 'A' is Fullwidth, while 'A' is not.
const getEastAsianWidth = require('get-east-asian-width');
const isFullwidth = (char) => getEastAsianWidth(char) === 'F';
console.log(isFullwidth('A')); // Output: true
console.log(isFullwidth('A')); // Output: false
The east-asian-width package provides similar functionality to get-east-asian-width by determining the East Asian Width properties of Unicode characters. It offers a comprehensive set of utilities for handling East Asian text rendering and alignment.
The unicode-width package calculates the display width of Unicode strings, taking into account East Asian Width properties. It is useful for applications that need to handle text alignment and rendering in a variety of languages, including East Asian languages.
The string-width package determines the display width of a string, considering East Asian Width properties and other factors. It is commonly used in CLI applications to ensure proper text alignment and formatting.
Determine the East Asian Width of a Unicode character
East Asian Width categorizes Unicode characters based on their occupied space in East Asian typography, which helps in text layout and alignment, particularly in languages like Japanese, Chinese, and Korean.
Unlike other similar packages, this package uses the latest Unicode data (which changes each year).
npm install get-east-asian-width
import {eastAsianWidth, eastAsianWidthType} from 'get-east-asian-width';
const codePoint = '字'.codePointAt(0);
console.log(eastAsianWidth(codePoint));
//=> 2
console.log(eastAsianWidthType(codePoint));
//=> 'wide'
eastAsianWidth(codePoint: number, options?: object): 1 | 2
Returns the width as a number for the given code point.
Type: object
Type: boolean
Default: false
Whether to treat an 'ambiguous'
character as wide.
import {eastAsianWidth} from 'get-east-asian-width';
const codePoint = '⛣'.codePointAt(0);
console.log(eastAsianWidth(codePoint));
//=> 1
console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
//=> 2
Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). If the context cannot be established reliably, they should be treated as narrow characters by default.
eastAsianWidthType(codePoint: number): 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous'
Returns the type of “East Asian Width” for the given code point.
FAQs
Determine the East Asian Width of a Unicode character
The npm package get-east-asian-width receives a total of 5,521,339 weekly downloads. As such, get-east-asian-width popularity was classified as popular.
We found that get-east-asian-width 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.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.