-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix more readings parse cases, move into folder
- Loading branch information
Showing
3 changed files
with
124 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
const punctuations = [ | ||
',', | ||
',', | ||
'。', | ||
'.', | ||
'?', | ||
'?', | ||
'!', | ||
'!', | ||
';', | ||
';', | ||
':', | ||
':', | ||
'、', | ||
',', | ||
',', | ||
]; | ||
|
||
/** | ||
* Returns true if the text is a Chinese character. | ||
* @param {string} text | ||
* @returns {boolean} | ||
*/ | ||
function isHanzi(text) { | ||
return /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/.test( | ||
text | ||
); | ||
} | ||
|
||
/** | ||
* Returns true if the text is a Jyutping reading. | ||
* @param {string} text | ||
* @returns {boolean} | ||
*/ | ||
function isJyuutping(text) { | ||
return /[a-zA-Z0-9]/.test(text); | ||
} | ||
|
||
/** | ||
* Returns true if the text is a punctuation. | ||
* @param {string} text | ||
* @returns {boolean} | ||
*/ | ||
function isPunctuation(text) { | ||
return punctuations.includes(text); | ||
} | ||
|
||
export { punctuations, isHanzi, isJyuutping, isPunctuation }; |