Skip to content

Commit

Permalink
fix: 兼容 customPinyin 文字和拼音数量不对齐的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoulixiang committed Feb 23, 2025
1 parent fa07de9 commit 169ac1a
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/core/pinyin/handle.ts
Original file line number Diff line number Diff line change
@@ -59,9 +59,9 @@ export const getPinyin = (
const zhChars = splitString(match.zh);
list[i + j] = {
origin: zhChars[j],
result: pinyins[pinyinIndex],
result: pinyins[pinyinIndex] || '',
isZh: true,
originPinyin: pinyins[pinyinIndex],
originPinyin: pinyins[pinyinIndex] || '',
};
pinyinIndex++;
}
9 changes: 9 additions & 0 deletions test/custom.test.js
Original file line number Diff line number Diff line change
@@ -130,6 +130,15 @@ describe('customConfig', () => {
expect(result).to.be.equal('𧒽 shā fā lei ke 𧒽 suàn fǎ shì');
clearAllCustomDicts();
});

it('[custom] length not match', () => {
customPinyin({
你好: 'nihao',
});
const result = pinyin('你好', { toneType: 'none'});
expect(result).to.be.equal('nihao ');
clearAllCustomDicts();
});
});


2 changes: 1 addition & 1 deletion types/core/pinyin/handle.d.ts
Original file line number Diff line number Diff line change
@@ -74,6 +74,6 @@ declare const getPinyinWithNum: GetPinyinWithNum;
* @param {string} pinyin
* @return {string}
*/
type GetFirstLetter = (pinyin: string) => string;
type GetFirstLetter = (pinyin: string, isZh: boolean) => string;
declare const getFirstLetter: GetFirstLetter;
export { getPinyinWithoutTone, getInitialAndFinal, getMultiplePinyin, getNumOfTone, getPinyinWithNum, getFirstLetter, getFinalParts, };

0 comments on commit 169ac1a

Please sign in to comment.