feat: 支持自定义 ü 要替换为的字符串

This commit is contained in:
zhoulixiang
2025-02-23 18:39:32 +08:00
parent 169ac1a104
commit 80861223d0
4 changed files with 10 additions and 3 deletions

View File

@@ -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开启

View File

@@ -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");
}
});
}

View File

@@ -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');
});
});

View File

@@ -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开启