blob: 671f97f760779075aa362ec41063e7a3a528b0e8 [file] [log] [blame]
Yang Guo4fd355c2019-09-19 10:59:03 +02001/* eslint-disable yoda */
Tim van der Lipped3425b92022-01-07 14:05:09 +01002'use strict';
3
4const isFullwidthCodePoint = codePoint => {
5 if (Number.isNaN(codePoint)) {
Yang Guo4fd355c2019-09-19 10:59:03 +02006 return false;
7 }
8
Tim van der Lipped3425b92022-01-07 14:05:09 +01009 // Code points are derived from:
Yang Guo4fd355c2019-09-19 10:59:03 +020010 // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
11 if (
Tim van der Lipped3425b92022-01-07 14:05:09 +010012 codePoint >= 0x1100 && (
13 codePoint <= 0x115F || // Hangul Jamo
14 codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
15 codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
Yang Guo4fd355c2019-09-19 10:59:03 +020016 // CJK Radicals Supplement .. Enclosed CJK Letters and Months
Tim van der Lipped3425b92022-01-07 14:05:09 +010017 (0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020018 // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
Tim van der Lipped3425b92022-01-07 14:05:09 +010019 (0x3250 <= codePoint && codePoint <= 0x4DBF) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020020 // CJK Unified Ideographs .. Yi Radicals
Tim van der Lipped3425b92022-01-07 14:05:09 +010021 (0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020022 // Hangul Jamo Extended-A
Tim van der Lipped3425b92022-01-07 14:05:09 +010023 (0xA960 <= codePoint && codePoint <= 0xA97C) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020024 // Hangul Syllables
Tim van der Lipped3425b92022-01-07 14:05:09 +010025 (0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020026 // CJK Compatibility Ideographs
Tim van der Lipped3425b92022-01-07 14:05:09 +010027 (0xF900 <= codePoint && codePoint <= 0xFAFF) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020028 // Vertical Forms
Tim van der Lipped3425b92022-01-07 14:05:09 +010029 (0xFE10 <= codePoint && codePoint <= 0xFE19) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020030 // CJK Compatibility Forms .. Small Form Variants
Tim van der Lipped3425b92022-01-07 14:05:09 +010031 (0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020032 // Halfwidth and Fullwidth Forms
Tim van der Lipped3425b92022-01-07 14:05:09 +010033 (0xFF01 <= codePoint && codePoint <= 0xFF60) ||
34 (0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020035 // Kana Supplement
Tim van der Lipped3425b92022-01-07 14:05:09 +010036 (0x1B000 <= codePoint && codePoint <= 0x1B001) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020037 // Enclosed Ideographic Supplement
Tim van der Lipped3425b92022-01-07 14:05:09 +010038 (0x1F200 <= codePoint && codePoint <= 0x1F251) ||
Yang Guo4fd355c2019-09-19 10:59:03 +020039 // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
Tim van der Lipped3425b92022-01-07 14:05:09 +010040 (0x20000 <= codePoint && codePoint <= 0x3FFFD)
Yang Guo4fd355c2019-09-19 10:59:03 +020041 )
42 ) {
43 return true;
44 }
45
46 return false;
47};
Tim van der Lipped3425b92022-01-07 14:05:09 +010048
49module.exports = isFullwidthCodePoint;
50module.exports.default = isFullwidthCodePoint;