mirror of
https://github.com/zh-lx/pinyin-pro.git
synced 2026-03-13 09:51:38 +08:00
feat: 支持自定义 ü 要替换为的字符串
This commit is contained in:
@@ -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:开启
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
3
types/core/pinyin/index.d.ts
vendored
3
types/core/pinyin/index.d.ts
vendored
@@ -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:开启
|
||||
|
||||
Reference in New Issue
Block a user