index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* eslint-disable yoda */
  2. 'use strict';
  3. const isFullwidthCodePoint = codePoint => {
  4. if (Number.isNaN(codePoint)) {
  5. return false;
  6. }
  7. // Code points are derived from:
  8. // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
  9. if (
  10. codePoint >= 0x1100 && (
  11. codePoint <= 0x115F || // Hangul Jamo
  12. codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
  13. codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
  14. // CJK Radicals Supplement .. Enclosed CJK Letters and Months
  15. (0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
  16. // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
  17. (0x3250 <= codePoint && codePoint <= 0x4DBF) ||
  18. // CJK Unified Ideographs .. Yi Radicals
  19. (0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
  20. // Hangul Jamo Extended-A
  21. (0xA960 <= codePoint && codePoint <= 0xA97C) ||
  22. // Hangul Syllables
  23. (0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
  24. // CJK Compatibility Ideographs
  25. (0xF900 <= codePoint && codePoint <= 0xFAFF) ||
  26. // Vertical Forms
  27. (0xFE10 <= codePoint && codePoint <= 0xFE19) ||
  28. // CJK Compatibility Forms .. Small Form Variants
  29. (0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
  30. // Halfwidth and Fullwidth Forms
  31. (0xFF01 <= codePoint && codePoint <= 0xFF60) ||
  32. (0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
  33. // Kana Supplement
  34. (0x1B000 <= codePoint && codePoint <= 0x1B001) ||
  35. // Enclosed Ideographic Supplement
  36. (0x1F200 <= codePoint && codePoint <= 0x1F251) ||
  37. // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
  38. (0x20000 <= codePoint && codePoint <= 0x3FFFD)
  39. )
  40. ) {
  41. return true;
  42. }
  43. return false;
  44. };
  45. module.exports = isFullwidthCodePoint;
  46. module.exports.default = isFullwidthCodePoint;