1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.CharacterType = void 0;
|
28 | exports.getCharacterType = getCharacterType;
|
29 | const CharacterType = {
|
30 | SPACE: 0,
|
31 | ALPHA_LETTER: 1,
|
32 | PUNCT: 2,
|
33 | HAN_LETTER: 3,
|
34 | KATAKANA_LETTER: 4,
|
35 | HIRAGANA_LETTER: 5,
|
36 | HALFWIDTH_KATAKANA_LETTER: 6,
|
37 | THAI_LETTER: 7
|
38 | };
|
39 | exports.CharacterType = CharacterType;
|
40 |
|
41 | function isAlphabeticalScript(charCode) {
|
42 | return charCode < 0x2e80;
|
43 | }
|
44 |
|
45 | function isAscii(charCode) {
|
46 | return (charCode & 0xff80) === 0;
|
47 | }
|
48 |
|
49 | function isAsciiAlpha(charCode) {
|
50 | return charCode >= 0x61 && charCode <= 0x7a || charCode >= 0x41 && charCode <= 0x5a;
|
51 | }
|
52 |
|
53 | function isAsciiDigit(charCode) {
|
54 | return charCode >= 0x30 && charCode <= 0x39;
|
55 | }
|
56 |
|
57 | function isAsciiSpace(charCode) {
|
58 | return charCode === 0x20 || charCode === 0x09 || charCode === 0x0d || charCode === 0x0a;
|
59 | }
|
60 |
|
61 | function isHan(charCode) {
|
62 | return charCode >= 0x3400 && charCode <= 0x9fff || charCode >= 0xf900 && charCode <= 0xfaff;
|
63 | }
|
64 |
|
65 | function isKatakana(charCode) {
|
66 | return charCode >= 0x30a0 && charCode <= 0x30ff;
|
67 | }
|
68 |
|
69 | function isHiragana(charCode) {
|
70 | return charCode >= 0x3040 && charCode <= 0x309f;
|
71 | }
|
72 |
|
73 | function isHalfwidthKatakana(charCode) {
|
74 | return charCode >= 0xff60 && charCode <= 0xff9f;
|
75 | }
|
76 |
|
77 | function isThai(charCode) {
|
78 | return (charCode & 0xff80) === 0x0e00;
|
79 | }
|
80 |
|
81 | function getCharacterType(charCode) {
|
82 | if (isAlphabeticalScript(charCode)) {
|
83 | if (isAscii(charCode)) {
|
84 | if (isAsciiSpace(charCode)) {
|
85 | return CharacterType.SPACE;
|
86 | } else if (isAsciiAlpha(charCode) || isAsciiDigit(charCode) || charCode === 0x5f) {
|
87 | return CharacterType.ALPHA_LETTER;
|
88 | }
|
89 |
|
90 | return CharacterType.PUNCT;
|
91 | } else if (isThai(charCode)) {
|
92 | return CharacterType.THAI_LETTER;
|
93 | } else if (charCode === 0xa0) {
|
94 | return CharacterType.SPACE;
|
95 | }
|
96 |
|
97 | return CharacterType.ALPHA_LETTER;
|
98 | }
|
99 |
|
100 | if (isHan(charCode)) {
|
101 | return CharacterType.HAN_LETTER;
|
102 | } else if (isKatakana(charCode)) {
|
103 | return CharacterType.KATAKANA_LETTER;
|
104 | } else if (isHiragana(charCode)) {
|
105 | return CharacterType.HIRAGANA_LETTER;
|
106 | } else if (isHalfwidthKatakana(charCode)) {
|
107 | return CharacterType.HALFWIDTH_KATAKANA_LETTER;
|
108 | }
|
109 |
|
110 | return CharacterType.ALPHA_LETTER;
|
111 | } |
\ | No newline at end of file |