get-east-asian-width
Advanced tools
Comparing version 1.1.0 to 1.2.0
23
index.js
@@ -1,2 +0,2 @@ | ||
import lookup from './lookup.js'; | ||
import {getCategory, isAmbiguous, isFullWidth, isWide} from './lookup.js'; | ||
@@ -12,10 +12,21 @@ function validate(codePoint) { | ||
return lookup(codePoint); | ||
return getCategory(codePoint); | ||
} | ||
export function eastAsianWidth(codePoint, {ambiguousAsWide = false} = {}) { | ||
const type = eastAsianWidthType(codePoint); | ||
return type === 'fullwidth' || type === 'wide' || (type === 'ambiguous' && ambiguousAsWide) | ||
? 2 | ||
: 1; | ||
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://github.com/sindresorhus/get-east-asian-width/pull/6 | ||
export const _isNarrowWidth = codePoint => !(isFullWidth(codePoint) || isWide(codePoint)); |
// Generated code. | ||
export default function lookup(x) { | ||
if ( | ||
x === 0xA1 | ||
function isAmbiguous(x) { | ||
return x === 0xA1 | ||
|| x === 0xA4 | ||
@@ -219,44 +218,13 @@ || x === 0xA7 | ||
|| x >= 0xF0000 && x <= 0xFFFFD | ||
|| x >= 0x100000 && x <= 0x10FFFD | ||
) { | ||
return 'ambiguous'; | ||
} | ||
|| x >= 0x100000 && x <= 0x10FFFD; | ||
} | ||
if ( | ||
x === 0x3000 | ||
function isFullWidth(x) { | ||
return x === 0x3000 | ||
|| x >= 0xFF01 && x <= 0xFF60 | ||
|| x >= 0xFFE0 && x <= 0xFFE6 | ||
) { | ||
return 'fullwidth'; | ||
} | ||
|| x >= 0xFFE0 && x <= 0xFFE6; | ||
} | ||
if ( | ||
x === 0x20A9 | ||
|| x >= 0xFF61 && x <= 0xFFBE | ||
|| x >= 0xFFC2 && x <= 0xFFC7 | ||
|| x >= 0xFFCA && x <= 0xFFCF | ||
|| x >= 0xFFD2 && x <= 0xFFD7 | ||
|| x >= 0xFFDA && x <= 0xFFDC | ||
|| x >= 0xFFE8 && x <= 0xFFEE | ||
) { | ||
return 'halfwidth'; | ||
} | ||
if ( | ||
x >= 0x20 && x <= 0x7E | ||
|| x === 0xA2 | ||
|| x === 0xA3 | ||
|| x === 0xA5 | ||
|| x === 0xA6 | ||
|| x === 0xAC | ||
|| x === 0xAF | ||
|| x >= 0x27E6 && x <= 0x27ED | ||
|| x === 0x2985 | ||
|| x === 0x2986 | ||
) { | ||
return 'narrow'; | ||
} | ||
if ( | ||
x >= 0x1100 && x <= 0x115F | ||
function isWide(x) { | ||
return x >= 0x1100 && x <= 0x115F | ||
|| x === 0x231A | ||
@@ -394,8 +362,42 @@ || x === 0x231B | ||
|| x >= 0x20000 && x <= 0x2FFFD | ||
|| x >= 0x30000 && x <= 0x3FFFD | ||
|| x >= 0x30000 && x <= 0x3FFFD; | ||
} | ||
function getCategory(x) { | ||
if (isAmbiguous(x)) return 'ambiguous'; | ||
if (isFullWidth(x)) return 'fullwidth'; | ||
if ( | ||
x === 0x20A9 | ||
|| x >= 0xFF61 && x <= 0xFFBE | ||
|| x >= 0xFFC2 && x <= 0xFFC7 | ||
|| x >= 0xFFCA && x <= 0xFFCF | ||
|| x >= 0xFFD2 && x <= 0xFFD7 | ||
|| x >= 0xFFDA && x <= 0xFFDC | ||
|| x >= 0xFFE8 && x <= 0xFFEE | ||
) { | ||
return 'wide'; | ||
return 'halfwidth'; | ||
} | ||
if ( | ||
x >= 0x20 && x <= 0x7E | ||
|| x === 0xA2 | ||
|| x === 0xA3 | ||
|| x === 0xA5 | ||
|| x === 0xA6 | ||
|| x === 0xAC | ||
|| x === 0xAF | ||
|| x >= 0x27E6 && x <= 0x27ED | ||
|| x === 0x2985 | ||
|| x === 0x2986 | ||
) { | ||
return 'narrow'; | ||
} | ||
if (isWide(x)) return 'wide'; | ||
return 'neutral'; | ||
} | ||
export {isAmbiguous, isFullWidth, isWide, getCategory}; |
{ | ||
"name": "get-east-asian-width", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Determine the East Asian Width of a Unicode character", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15599
459
0