-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
31 lines (24 loc) · 814 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {getCategory, isAmbiguous, isFullWidth, isWide} from './lookup.js';
function validate(codePoint) {
if (!Number.isSafeInteger(codePoint)) {
throw new TypeError(`Expected a code point, got \`${typeof codePoint}\`.`);
}
}
export function eastAsianWidthType(codePoint) {
validate(codePoint);
return getCategory(codePoint);
}
export function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) {
validate(codePoint);
if (
isFullWidth(codePoint)
|| isWide(codePoint)
|| (ambiguousAsWide && isAmbiguous(codePoint))
) {
return 2;
}
return 1;
}
// For Prettier. This doesn't count "ambiguous" characters or check for valid input.
// https:/sindresorhus/get-east-asian-width/pull/6
export const _isNarrowWidth = codePoint => !(isFullWidth(codePoint) || isWide(codePoint));