Check if the character represented by a given Unicode code point is fullwidth
npx @tessl/cli install tessl/npm-is-fullwidth-code-point@5.1.0Check if the character represented by a given Unicode code point is fullwidth. This package determines whether a Unicode code point represents a character that occupies two columns in monospace environments, which is essential for proper text layout in terminals, text editors, and CLI applications.
npm install is-fullwidth-code-pointimport isFullwidthCodePoint from 'is-fullwidth-code-point';For environments that support dynamic imports:
const { default: isFullwidthCodePoint } = await import('is-fullwidth-code-point');This package provides a simple utility function with a focused API surface:
isFullwidthCodePoint functionNumber.isInteger() for robust parameter checkingget-east-asian-width library for accurate East Asian Width property determinationfalse for invalid inputs rather than throwing exceptionsimport isFullwidthCodePoint from 'is-fullwidth-code-point';
// Check East Asian characters (fullwidth)
isFullwidthCodePoint('谢'.codePointAt(0)); // => true
isFullwidthCodePoint('あ'.codePointAt(0)); // => true
isFullwidthCodePoint('고'.codePointAt(0)); // => true
// Check ASCII characters (halfwidth)
isFullwidthCodePoint('a'.codePointAt(0)); // => false
isFullwidthCodePoint('1'.codePointAt(0)); // => false
// Using Unicode code points directly
isFullwidthCodePoint(0x1F251); // => true (emoji)
isFullwidthCodePoint(0x1B11E); // => true (musical symbol)
isFullwidthCodePoint(0x201D); // => false (punctuation)Determines if a Unicode code point represents a fullwidth character according to Unicode East Asian Width properties. Returns true for characters classified as either "Fullwidth (F)" or "Wide (W)" in the Unicode standard.
/**
* Check if the character represented by a given Unicode code point is fullwidth
* @param codePoint - The Unicode code point of a character
* @returns true if the code point represents a fullwidth character, false otherwise
*/
export default function isFullwidthCodePoint(codePoint: number): boolean;Parameters:
codePoint (number): The Unicode code point of a character. Must be an integer value.Returns:
boolean: Returns true if the code point represents a fullwidth character, false otherwise.Behavior:
false for non-integer inputs (including NaN, floating point numbers, and non-numeric values)Number.isInteger() for input validation before processingget-east-asian-width library for Unicode width classificationtrue if the code point is classified as either "Fullwidth" or "Wide" according to Unicode East Asian Width standardsError Handling:
false rather than throwing exceptionsUsage Examples:
// Common East Asian characters
isFullwidthCodePoint('中'.codePointAt(0)); // => true (Chinese)
isFullwidthCodePoint('に'.codePointAt(0)); // => true (Japanese Hiragana)
isFullwidthCodePoint('한'.codePointAt(0)); // => true (Korean Hangul)
// Emoji and symbols
isFullwidthCodePoint('😀'.codePointAt(0)); // => true (emoji)
isFullwidthCodePoint('♪'.codePointAt(0)); // => true (musical note)
// ASCII and Latin characters
isFullwidthCodePoint('A'.codePointAt(0)); // => false
isFullwidthCodePoint(' '.codePointAt(0)); // => false (space)
isFullwidthCodePoint('!'.codePointAt(0)); // => false (punctuation)
// Edge cases
isFullwidthCodePoint(NaN); // => false
isFullwidthCodePoint(3.14); // => false (not integer)
isFullwidthCodePoint(-1); // => false (negative)
isFullwidthCodePoint(0); // => false (null character)// TypeScript type definitions (when using TypeScript)
export default function isFullwidthCodePoint(codePoint: number): boolean;This package depends on get-east-asian-width (version ^1.3.1) for Unicode width classification logic. Specifically, it imports and uses two internal functions:
_isFullWidth: Determines if a code point represents a fullwidth character (East Asian Width property "F")_isWide: Determines if a code point represents a wide character (East Asian Width property "W")The function returns true if either classification returns true, covering all characters that occupy two columns in terminal and monospace font environments.