From 169ac1a1045e6858af629b00fcc81982a4bffef6 Mon Sep 17 00:00:00 2001 From: zhoulixiang Date: Sun, 23 Feb 2025 17:45:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=BC=E5=AE=B9=20customPinyin=20?= =?UTF-8?q?=E6=96=87=E5=AD=97=E5=92=8C=E6=8B=BC=E9=9F=B3=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9=E9=BD=90=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/core/pinyin/handle.ts | 4 ++-- test/custom.test.js | 9 +++++++++ types/core/pinyin/handle.d.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/core/pinyin/handle.ts b/lib/core/pinyin/handle.ts index 7e2cdde..c8b4d80 100644 --- a/lib/core/pinyin/handle.ts +++ b/lib/core/pinyin/handle.ts @@ -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++; } diff --git a/test/custom.test.js b/test/custom.test.js index 862f7e0..4517003 100644 --- a/test/custom.test.js +++ b/test/custom.test.js @@ -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(); + }); }); diff --git a/types/core/pinyin/handle.d.ts b/types/core/pinyin/handle.d.ts index a621907..450071a 100644 --- a/types/core/pinyin/handle.d.ts +++ b/types/core/pinyin/handle.d.ts @@ -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, };