Skip to content

Commit

Permalink
Merge pull request #226 from zh-lx/fix-polyphonic-nonZh
Browse files Browse the repository at this point in the history
fix: 修复 polyphonic 对非中文字符的处理
  • Loading branch information
zh-lx authored Apr 18, 2024
2 parents 3dad240 + 5b1f66e commit 0ee19f8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/core/polyphonic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ const getPolyphonicList = (text: string): SingleWordResult[] => {
return text.split('').map((word) => {
const wordCode = word.charCodeAt(0);
const customPolyphonicDict = getCustomPolyphonicDict();
const pinyin = customPolyphonicDict[wordCode] || DICT1[wordCode] || '';
const pinyin = customPolyphonicDict[wordCode] || DICT1[wordCode] || word;
return {
origin: word,
result: pinyin,
isZh: !!pinyin,
isZh: pinyin !== word,
originPinyin: pinyin,
};
});
Expand Down
2 changes: 1 addition & 1 deletion test/polyphonic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('polyphonic', () => {

it('[polyphonic]nonzh', () => {
const result = polyphonic('好好学习s');
expect(result).to.deep.equal(['hǎo hào', 'hǎo hào', 'xué', 'xí', '']);
expect(result).to.deep.equal(['hǎo hào', 'hǎo hào', 'xué', 'xí', 's']);
});

it('[polyphonic]all&nonZh', () => {
Expand Down

0 comments on commit 0ee19f8

Please sign in to comment.