Skip to content

Commit 2099453

Browse files
committed
Merge branch 'Usualminds-fix-passport-u'
2 parents 6455ce0 + e8af3b0 commit 2099453

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

apps/website/rspress.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export default defineConfig({
106106
{
107107
icon: "discord",
108108
mode: "link",
109-
content: "https://discord.gg/zqUS5uke",
109+
content: "https://discord.gg/cxapDFhy",
110110
}
111111
],
112112
footer: {

packages/pinyin/src/format.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ export function toFixed(pinyin: string, style: ENUM_PINYIN_STYLE): string {
4646
});
4747

4848
case ENUM_PINYIN_STYLE.PASSPORT:
49+
// Normalize tones to plain letters first (like NORMAL), then apply
50+
// passport-specific ü rules:
51+
// - "lü"/"nü" -> "LYU"/"NYU"
52+
// - "lüe"/"nüe" -> "LUE"/"NUE" (i.e., ü before 'e' maps to 'U')
4953
return pinyin.replace(RE_PHONETIC_SYMBOL, function($0: string, $1_phonetic: string) {
50-
return PHONETIC_SYMBOL[$1_phonetic].replace(RE_TONE2, "$1").replace("v", "YU");
54+
return PHONETIC_SYMBOL[$1_phonetic].replace(RE_TONE2, "$1");
55+
}).replace(/v(e)?$/, function($0: string, $1_is_ve: string) {
56+
return $1_is_ve ? "UE" : "YU";
5157
}).toUpperCase();
5258

5359
case ENUM_PINYIN_STYLE.TO3NE:
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { toFixed } from "../src/format";
2+
import { ENUM_PINYIN_STYLE } from "../src/constant";
3+
4+
describe.only("toFixed function", () => {
5+
test("should return initials for ENUM_PINYIN_STYLE.INITIALS", () => {
6+
expect(toFixed("zhong", ENUM_PINYIN_STYLE.INITIALS)).toBe("zh");
7+
expect(toFixed("guo", ENUM_PINYIN_STYLE.INITIALS)).toBe("g");
8+
});
9+
10+
test("should return first letter for ENUM_PINYIN_STYLE.FIRST_LETTER", () => {
11+
expect(toFixed("zhong", ENUM_PINYIN_STYLE.FIRST_LETTER)).toBe("z");
12+
expect(toFixed("guo", ENUM_PINYIN_STYLE.FIRST_LETTER)).toBe("g");
13+
});
14+
15+
test("should return normal style for ENUM_PINYIN_STYLE.NORMAL", () => {
16+
expect(toFixed("zhōng", ENUM_PINYIN_STYLE.NORMAL)).toBe("zhong");
17+
expect(toFixed("guó", ENUM_PINYIN_STYLE.NORMAL)).toBe("guo");
18+
});
19+
20+
test("should return passport style for ENUM_PINYIN_STYLE.PASSPORT", () => {
21+
expect(toFixed("lǜ", ENUM_PINYIN_STYLE.PASSPORT)).toBe("LYU");
22+
expect(toFixed("nǚ", ENUM_PINYIN_STYLE.PASSPORT)).toBe("NYU");
23+
expect(toFixed("lüe", ENUM_PINYIN_STYLE.PASSPORT)).toBe("LUE");
24+
});
25+
26+
test("should return tone3 style for ENUM_PINYIN_STYLE.TO3NE", () => {
27+
expect(toFixed("zhōng", ENUM_PINYIN_STYLE.TO3NE)).toBe("zho1ng");
28+
expect(toFixed("guó", ENUM_PINYIN_STYLE.TO3NE)).toBe("guo2");
29+
});
30+
31+
test("should return tone2 style for ENUM_PINYIN_STYLE.TONE2", () => {
32+
expect(toFixed("zhōng", ENUM_PINYIN_STYLE.TONE2)).toBe("zhong1");
33+
expect(toFixed("guó", ENUM_PINYIN_STYLE.TONE2)).toBe("guo2");
34+
});
35+
36+
test("should return tone style for ENUM_PINYIN_STYLE.TONE", () => {
37+
expect(toFixed("zhōng", ENUM_PINYIN_STYLE.TONE)).toBe("zhōng");
38+
expect(toFixed("guó", ENUM_PINYIN_STYLE.TONE)).toBe("guó");
39+
});
40+
41+
test("should return original pinyin for unknown style", () => {
42+
expect(toFixed("zhong", -1)).toBe("zhong");
43+
});
44+
});

packages/pinyin/test/test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ const cases: any[] = [
7171
STYLE_INITIALS: [["l"]],
7272
STYLE_FIRST_LETTER: [["l"]],
7373
} ],
74+
["略", {
75+
STYLE_NORMAL: [["lve"]],
76+
STYLE_PASSPORT: [["LUE"]],
77+
STYLE_TONE: [["lüè"]],
78+
STYLE_TONE2: [["lve4"]],
79+
} ],
80+
["虐", {
81+
STYLE_NORMAL: [["nve"]],
82+
STYLE_PASSPORT: [["NUE"]],
83+
STYLE_TONE: [["nüè"]],
84+
STYLE_TONE2: [["nve4"]],
85+
} ],
7486

7587
// 单音词
7688
[ "我是谁", {
@@ -304,7 +316,7 @@ function makeTest(han: string, opt: any, style: string){
304316
pys = py.segment;
305317
py = py.normal;
306318
}
307-
const single_pinyin = [];
319+
const single_pinyin: string[][] = [];
308320
for(let i = 0, l = py.length; i < l; i++){
309321
single_pinyin[i] = [py[i][0]];
310322
}

0 commit comments

Comments
 (0)