Skip to content

Commit 5108803

Browse files
authored
Merge pull request #287 from zh-lx/feature-v-string
feat: 支持自定义 ü 要替换为的字符串
2 parents 169ac1a + 8086122 commit 5108803

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

lib/core/pinyin/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ export interface BasicOptions {
8585
* @description 对于 ü 的返回是否转换成 v(仅在 toneType: none 启用时生效)
8686
* @value false:返回值中保留 ü (默认值)
8787
* @value true:返回值中 ü 转换成 v
88+
* @value string:返回值中 ü 转换成指定字符
8889
*/
89-
v?: boolean;
90+
v?: boolean | string;
9091
/**
9192
* @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
9293
* @value true:开启

lib/core/pinyin/middlewares.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export const middlewareV = (
157157
if (options.v) {
158158
list.forEach((item) => {
159159
if (item.isZh) {
160-
item.result = item.result.replace(/ü/g, "v");
160+
item.result = item.result.replace(/ü/g, typeof options.v === 'string' ? options.v : "v");
161161
}
162162
});
163163
}

test/v.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ describe('v', () => {
2626
const result4 = pinyin('吕布ü', { toneType: 'none', v: true });
2727
expect(result4).to.be.equal('lv bu ü');
2828
});
29+
30+
it('[v]string', () => {
31+
const result4 = pinyin('吕和平', { toneType: 'none', v: 'yu' });
32+
expect(result4).to.be.equal('lyu he ping');
33+
});
2934
});

types/core/pinyin/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ export interface BasicOptions {
6060
* @description 对于 ü 的返回是否转换成 v(仅在 toneType: none 启用时生效)
6161
* @value false:返回值中保留 ü (默认值)
6262
* @value true:返回值中 ü 转换成 v
63+
* @value string:返回值中 ü 转换成指定字符
6364
*/
64-
v?: boolean;
65+
v?: boolean | string;
6566
/**
6667
* @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
6768
* @value true:开启

0 commit comments

Comments
 (0)