mirror of
https://github.com/zh-lx/pinyin-pro.git
synced 2026-03-13 09:51:38 +08:00
fix: 兼容 customPinyin 文字和拼音数量不对齐的问题
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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
types/core/pinyin/handle.d.ts
vendored
2
types/core/pinyin/handle.d.ts
vendored
@@ -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, };
|
||||
|
||||
Reference in New Issue
Block a user