diff --git a/lib/core/pinyin/index.ts b/lib/core/pinyin/index.ts index 2b52b52..276605d 100644 --- a/lib/core/pinyin/index.ts +++ b/lib/core/pinyin/index.ts @@ -85,8 +85,9 @@ export interface BasicOptions { * @description 对于 ü 的返回是否转换成 v(仅在 toneType: none 启用时生效) * @value false:返回值中保留 ü (默认值) * @value true:返回值中 ü 转换成 v + * @value string:返回值中 ü 转换成指定字符 */ - v?: boolean; + v?: boolean | string; /** * @description 是否开启「一」和 「不」字的变调。默认开启。参考:https://zh.wiktionary.org/wiki/Appendix:%E2%80%9C%E4%B8%80%E2%80%9D%E5%8F%8A%E2%80%9C%E4%B8%8D%E2%80%9D%E7%9A%84%E5%8F%98%E8%B0%83 * @value true:开启 diff --git a/lib/core/pinyin/middlewares.ts b/lib/core/pinyin/middlewares.ts index 97bbcd5..304caf7 100644 --- a/lib/core/pinyin/middlewares.ts +++ b/lib/core/pinyin/middlewares.ts @@ -157,7 +157,7 @@ export const middlewareV = ( if (options.v) { list.forEach((item) => { if (item.isZh) { - item.result = item.result.replace(/ü/g, "v"); + item.result = item.result.replace(/ü/g, typeof options.v === 'string' ? options.v : "v"); } }); } diff --git a/test/v.test.js b/test/v.test.js index 6eac6cb..6e6973b 100644 --- a/test/v.test.js +++ b/test/v.test.js @@ -26,4 +26,9 @@ describe('v', () => { const result4 = pinyin('吕布ü', { toneType: 'none', v: true }); expect(result4).to.be.equal('lv bu ü'); }); + + it('[v]string', () => { + const result4 = pinyin('吕和平', { toneType: 'none', v: 'yu' }); + expect(result4).to.be.equal('lyu he ping'); + }); }); diff --git a/types/core/pinyin/index.d.ts b/types/core/pinyin/index.d.ts index bd80711..f5b5a1b 100644 --- a/types/core/pinyin/index.d.ts +++ b/types/core/pinyin/index.d.ts @@ -60,8 +60,9 @@ export interface BasicOptions { * @description 对于 ü 的返回是否转换成 v(仅在 toneType: none 启用时生效) * @value false:返回值中保留 ü (默认值) * @value true:返回值中 ü 转换成 v + * @value string:返回值中 ü 转换成指定字符 */ - v?: boolean; + v?: boolean | string; /** * @description 是否开启「一」和 「不」字的变调。默认开启。参考:https://zh.wiktionary.org/wiki/Appendix:%E2%80%9C%E4%B8%80%E2%80%9D%E5%8F%8A%E2%80%9C%E4%B8%8D%E2%80%9D%E7%9A%84%E5%8F%98%E8%B0%83 * @value true:开启