Skip to content

Commit 169ac1a

Browse files
author
zhoulixiang
committed
fix: 兼容 customPinyin 文字和拼音数量不对齐的问题
1 parent fa07de9 commit 169ac1a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/core/pinyin/handle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const getPinyin = (
5959
const zhChars = splitString(match.zh);
6060
list[i + j] = {
6161
origin: zhChars[j],
62-
result: pinyins[pinyinIndex],
62+
result: pinyins[pinyinIndex] || '',
6363
isZh: true,
64-
originPinyin: pinyins[pinyinIndex],
64+
originPinyin: pinyins[pinyinIndex] || '',
6565
};
6666
pinyinIndex++;
6767
}

test/custom.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ describe('customConfig', () => {
130130
expect(result).to.be.equal('𧒽 shā fā lei ke 𧒽 suàn fǎ shì');
131131
clearAllCustomDicts();
132132
});
133+
134+
it('[custom] length not match', () => {
135+
customPinyin({
136+
你好: 'nihao',
137+
});
138+
const result = pinyin('你好', { toneType: 'none'});
139+
expect(result).to.be.equal('nihao ');
140+
clearAllCustomDicts();
141+
});
133142
});
134143

135144

types/core/pinyin/handle.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ declare const getPinyinWithNum: GetPinyinWithNum;
7474
* @param {string} pinyin
7575
* @return {string}
7676
*/
77-
type GetFirstLetter = (pinyin: string) => string;
77+
type GetFirstLetter = (pinyin: string, isZh: boolean) => string;
7878
declare const getFirstLetter: GetFirstLetter;
7979
export { getPinyinWithoutTone, getInitialAndFinal, getMultiplePinyin, getNumOfTone, getPinyinWithNum, getFirstLetter, getFinalParts, };

0 commit comments

Comments
 (0)