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.00
# is-fullwidth-code-point
1
2
Check 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.
3
4
## Package Information
5
6
- **Package Name**: is-fullwidth-code-point
7
- **Package Type**: npm
8
- **Language**: JavaScript (ES Module)
9
- **Installation**: `npm install is-fullwidth-code-point`
10
11
## Core Imports
12
13
```javascript
14
import isFullwidthCodePoint from 'is-fullwidth-code-point';
15
```
16
17
For environments that support dynamic imports:
18
19
```javascript
20
const { default: isFullwidthCodePoint } = await import('is-fullwidth-code-point');
21
```
22
23
## Architecture
24
25
This package provides a simple utility function with a focused API surface:
26
27
- **Single Function Export**: Default export of `isFullwidthCodePoint` function
28
- **Input Validation**: Uses `Number.isInteger()` for robust parameter checking
29
- **Unicode Classification**: Delegates to `get-east-asian-width` library for accurate East Asian Width property determination
30
- **Error Handling**: Returns `false` for invalid inputs rather than throwing exceptions
31
- **Zero Dependencies**: Apart from the classification library, no additional runtime dependencies
32
33
## Basic Usage
34
35
```javascript
36
import isFullwidthCodePoint from 'is-fullwidth-code-point';
37
38
// Check East Asian characters (fullwidth)
39
isFullwidthCodePoint('谢'.codePointAt(0)); // => true
40
isFullwidthCodePoint('あ'.codePointAt(0)); // => true
41
isFullwidthCodePoint('고'.codePointAt(0)); // => true
42
43
// Check ASCII characters (halfwidth)
44
isFullwidthCodePoint('a'.codePointAt(0)); // => false
45
isFullwidthCodePoint('1'.codePointAt(0)); // => false
46
47
// Using Unicode code points directly
48
isFullwidthCodePoint(0x1F251); // => true (emoji)
49
isFullwidthCodePoint(0x1B11E); // => true (musical symbol)
50
isFullwidthCodePoint(0x201D); // => false (punctuation)
51
```
52
53
## Capabilities
54
55
### Fullwidth Code Point Detection
56
57
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.
58
59
```javascript { .api }
60
/**
61
* Check if the character represented by a given Unicode code point is fullwidth
62
* @param codePoint - The Unicode code point of a character
63
* @returns true if the code point represents a fullwidth character, false otherwise
64
*/
65
export default function isFullwidthCodePoint(codePoint: number): boolean;
66
```
67
68
**Parameters:**
69
- `codePoint` (number): The Unicode code point of a character. Must be an integer value.
70
71
**Returns:**
72
- `boolean`: Returns `true` if the code point represents a fullwidth character, `false` otherwise.
73
74
**Behavior:**
75
- Returns `false` for non-integer inputs (including `NaN`, floating point numbers, and non-numeric values)
76
- Uses `Number.isInteger()` for input validation before processing
77
- Delegates to the `get-east-asian-width` library for Unicode width classification
78
- Returns `true` if the code point is classified as either "Fullwidth" or "Wide" according to Unicode East Asian Width standards
79
- Handles the full Unicode range including emoji, symbols, and extended character sets
80
81
**Error Handling:**
82
- Invalid inputs (non-integers) return `false` rather than throwing exceptions
83
- No exceptions are thrown for any input value
84
85
**Usage Examples:**
86
87
```javascript
88
// Common East Asian characters
89
isFullwidthCodePoint('中'.codePointAt(0)); // => true (Chinese)
90
isFullwidthCodePoint('に'.codePointAt(0)); // => true (Japanese Hiragana)
91
isFullwidthCodePoint('한'.codePointAt(0)); // => true (Korean Hangul)
92
93
// Emoji and symbols
94
isFullwidthCodePoint('😀'.codePointAt(0)); // => true (emoji)
95
isFullwidthCodePoint('♪'.codePointAt(0)); // => true (musical note)
96
97
// ASCII and Latin characters
98
isFullwidthCodePoint('A'.codePointAt(0)); // => false
99
isFullwidthCodePoint(' '.codePointAt(0)); // => false (space)
100
isFullwidthCodePoint('!'.codePointAt(0)); // => false (punctuation)
101
102
// Edge cases
103
isFullwidthCodePoint(NaN); // => false
104
isFullwidthCodePoint(3.14); // => false (not integer)
105
isFullwidthCodePoint(-1); // => false (negative)
106
isFullwidthCodePoint(0); // => false (null character)
107
```
108
109
## Types
110
111
```typescript { .api }
112
// TypeScript type definitions (when using TypeScript)
113
export default function isFullwidthCodePoint(codePoint: number): boolean;
114
```
115
116
## Dependencies
117
118
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:
119
120
- `_isFullWidth`: Determines if a code point represents a fullwidth character (East Asian Width property "F")
121
- `_isWide`: Determines if a code point represents a wide character (East Asian Width property "W")
122
123
The function returns `true` if either classification returns `true`, covering all characters that occupy two columns in terminal and monospace font environments.