diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml
index 995bc5a..7f50c22 100644
--- a/.github/workflows/node.js.yml
+++ b/.github/workflows/node.js.yml
@@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
- node-version: [12.x, 14.x, 16.x]
+ node-version: [16.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
diff --git a/EXAMPLE.md b/EXAMPLE.md
index b1f2f08..610bf3c 100644
--- a/EXAMPLE.md
+++ b/EXAMPLE.md
@@ -79,6 +79,9 @@ export default function() {
+
+
+
diff --git a/README.md b/README.md
index a57fdb3..1e09c9d 100644
--- a/README.md
+++ b/README.md
@@ -122,8 +122,8 @@ export interface IPinyinOptions {
```typescript
export type IPinyinStyle =
- "normal" | "tone" | "tone2" | "to3ne" | "initials" | "first_letter" | // 推荐使用小写,和输出的拼音一致
- "NORMAL" | "TONE" | "TONE2" | "TO3NE" | "INITIALS" | "FIRST_LETTER" | // 方便老版本迁移
+ "normal" | "tone" | "tone2" | "to3ne" | "initials" | "first_letter" | "passport" | // 推荐使用小写,和输出的拼音一致
+ "NORMAL" | "TONE" | "TONE2" | "TO3NE" | "INITIALS" | "FIRST_LETTER" | "PASSPORT" | // 方便老版本迁移
0 | 1 | 2 | 5 | 3 | 4; // 兼容老版本
```
@@ -204,8 +204,8 @@ wǒ xǐhuān nǐ
```typescript
IPinyinStyle =
- "normal" | "tone" | "tone2" | "to3ne" | "initials" | "first_letter" | // 推荐使用小写,和输出的拼音一致
- "NORMAL" | "TONE" | "TONE2" | "TO3NE" | "INITIALS" | "FIRST_LETTER" | // 方便老版本迁移
+ "normal" | "tone" | "tone2" | "to3ne" | "initials" | "first_letter" | "passport" | // 推荐使用小写,和输出的拼音一致
+ "NORMAL" | "TONE" | "TONE2" | "TO3NE" | "INITIALS" | "FIRST_LETTER" | "PASSPORT" | // 方便老版本迁移
0 | 1 | 2 | 5 | 3 | 4; // 兼容老版本
```
@@ -254,6 +254,12 @@ IPinyinStyle =
如:`p y`
+#### `PASSPORT`, `passport`
+
+护照风格。转换成大写形式,并且 `ü` 会以 `YU` 形式输出。
+
+国家移民管理局门户网站于2021年9月29日发布了《关于内地居民拼音姓名中字母“ü”在出入境证件中打印规则的公告》(以下简称公告),根据《中国人名汉语拼音字母拼写规则》和《关于机读旅行证件的相关国际通用规范》, 内地居民申办出入境证件,出入境证件上打印的持证人拼音姓名中,Lü(吕等字)、Nü(女等字)中的字母“ü”应当转换为“YU”,LüE(略等字)、NüE(虐等字)中的字母“ü”应当转换为“U”。
+
### options.mode
拼音模式,默认 "NORMAL" 普通模式。
diff --git a/src/PinyinBase.ts b/src/PinyinBase.ts
index e03567e..9150315 100644
--- a/src/PinyinBase.ts
+++ b/src/PinyinBase.ts
@@ -22,6 +22,7 @@ export default class PinyinBase {
STYLE_NORMAL = ENUM_PINYIN_STYLE.NORMAL;
STYLE_INITIALS = ENUM_PINYIN_STYLE.INITIALS;
STYLE_FIRST_LETTER = ENUM_PINYIN_STYLE.FIRST_LETTER;
+ STYLE_PASSPORT = ENUM_PINYIN_STYLE.PASSPORT;
// 兼容 v2.x 中的属性透出
// pinyin mode:
@@ -297,6 +298,7 @@ export function getPinyinInstance(py: PinyinBase) {
pinyin.STYLE_NORMAL = ENUM_PINYIN_STYLE.NORMAL;
pinyin.STYLE_INITIALS = ENUM_PINYIN_STYLE.INITIALS;
pinyin.STYLE_FIRST_LETTER = ENUM_PINYIN_STYLE.FIRST_LETTER;
+ pinyin.STYLE_PASSPORT = ENUM_PINYIN_STYLE.PASSPORT;
// pinyin mode: 兼容 v2.x 中的属性透出
pinyin.MODE_NORMAL = ENUM_PINYIN_MODE.NORMAL;
diff --git a/src/constant.ts b/src/constant.ts
index 0e89215..6cdf3ca 100644
--- a/src/constant.ts
+++ b/src/constant.ts
@@ -8,6 +8,7 @@ export enum ENUM_PINYIN_STYLE {
TO3NE = 5, // 声调以数字形式在声母之后,使用数字 0~4 标识。
INITIALS = 3, // 仅需要声母部分。
FIRST_LETTER = 4, // 仅保留首字母。
+ PASSPORT = 6, // 护照风格,转换成大写,且 `ü` 会以 `YU` 形式输出。
};
// 拼音模式。
diff --git a/src/declare.ts b/src/declare.ts
index f79457c..0976e42 100644
--- a/src/declare.ts
+++ b/src/declare.ts
@@ -13,6 +13,7 @@ export interface IPinyin {
STYLE_NORMAL: ENUM_PINYIN_STYLE;
STYLE_INITIALS: ENUM_PINYIN_STYLE;
STYLE_FIRST_LETTER: ENUM_PINYIN_STYLE;
+ STYLE_PASSPORT: ENUM_PINYIN_STYLE;
// pinyin mode: 兼容 v2.x 中的属性透出
MODE_NORMAL: ENUM_PINYIN_MODE;
@@ -22,8 +23,8 @@ export interface IPinyin {
export type IPinyinStyle =
ENUM_PINYIN_STYLE |
- "normal" | "tone" | "tone2" | "to3ne" | "initials" | "first_letter" | // 推荐使用小写,和输出的拼音一致
- "NORMAL" | "TONE" | "TONE2" | "TO3NE" | "INITIALS" | "FIRST_LETTER" | // 方便老版本迁移
+ "normal" | "tone" | "tone2" | "to3ne" | "initials" | "first_letter" | "passport" | // 推荐使用小写,和输出的拼音一致
+ "NORMAL" | "TONE" | "TONE2" | "TO3NE" | "INITIALS" | "FIRST_LETTER" | "PASSPORT" | // 方便老版本迁移
0 | 1 | 2 | 5 | 3 | 4; // 兼容老版本
// 拼音模式。
diff --git a/src/format.ts b/src/format.ts
index f97f409..40f68a9 100644
--- a/src/format.ts
+++ b/src/format.ts
@@ -45,6 +45,11 @@ export function toFixed(pinyin: string, style: ENUM_PINYIN_STYLE): string {
return PHONETIC_SYMBOL[$1_phonetic].replace(RE_TONE2, "$1");
});
+ case ENUM_PINYIN_STYLE.PASSPORT:
+ return pinyin.replace(RE_PHONETIC_SYMBOL, function($0: string, $1_phonetic: string) {
+ return PHONETIC_SYMBOL[$1_phonetic].replace(RE_TONE2, "$1").replace("v", "YU");
+ }).toUpperCase();
+
case ENUM_PINYIN_STYLE.TO3NE:
return pinyin.replace(RE_PHONETIC_SYMBOL, function($0: string, $1_phonetic: string) {
return PHONETIC_SYMBOL[$1_phonetic];
diff --git a/src/util.ts b/src/util.ts
index 1499647..f3f404b 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -35,6 +35,10 @@ const pinyinStyleMap: Map = new Map([
[ "normal", ENUM_PINYIN_STYLE.NORMAL ],
[ "NORMAL", ENUM_PINYIN_STYLE.NORMAL ],
[ "0", ENUM_PINYIN_STYLE.NORMAL ],
+
+ [ "passport", ENUM_PINYIN_STYLE.PASSPORT ],
+ [ "PASSPORT", ENUM_PINYIN_STYLE.PASSPORT ],
+ [ "6", ENUM_PINYIN_STYLE.PASSPORT ],
]);
// 将用户输入的拼音形式参数转换成唯一指定的强类型。
diff --git a/test/test.ts b/test/test.ts
index c6a34cc..52e5fed 100644
--- a/test/test.ts
+++ b/test/test.ts
@@ -12,6 +12,7 @@ const cases: any[] = [
// 单音字
[ "我", {
STYLE_NORMAL: [["wo"]],
+ STYLE_PASSPORT: [["WO"]],
STYLE_TONE: [["wǒ"]],
STYLE_TONE2: [["wo3"]],
STYLE_TO3NE: [["wo3"]],
@@ -21,6 +22,7 @@ const cases: any[] = [
[ "〇", {
STYLE_NORMAL: [["ling", "xing"]],
+ STYLE_PASSPORT: [["LING", "XING"]],
STYLE_TONE: [["líng", "xīng"]],
STYLE_TONE2: [["ling2", "xing1"]],
STYLE_TO3NE: [["li2ng", "xi1ng"]],
@@ -31,6 +33,7 @@ const cases: any[] = [
// 多音字
[ "中", {
STYLE_NORMAL: [["zhong"]],
+ STYLE_PASSPORT: [["ZHONG"]],
STYLE_TONE: [["zhōng", "zhòng"]],
STYLE_TONE2: [["zhong1", "zhong4"]],
STYLE_TO3NE: [["zho1ng", "zho4ng"]],
@@ -41,6 +44,7 @@ const cases: any[] = [
// 元音字
["爱", {
STYLE_NORMAL: [["ai"]],
+ STYLE_PASSPORT: [["AI"]],
STYLE_TONE: [["ài"]],
STYLE_TONE2: [["ai4"]],
STYLE_TO3NE: [["a4i"]],
@@ -49,6 +53,7 @@ const cases: any[] = [
} ],
["啊", {
STYLE_NORMAL: [["a"]],
+ STYLE_PASSPORT: [["A"]],
STYLE_TONE: [["ā", "á", "ǎ", "à", "a"]],
STYLE_TONE2: [["a1", "a2", "a3", "a4", "a"]],
STYLE_TO3NE: [["a1", "a2", "a3", "a4", "a"]],
@@ -56,9 +61,21 @@ const cases: any[] = [
STYLE_FIRST_LETTER: [["a"]],
} ],
+ // YU
+ ["吕", {
+ STYLE_NORMAL: [["lv"]],
+ STYLE_PASSPORT: [["LYU"]],
+ STYLE_TONE: [["lǚ"]],
+ STYLE_TONE2: [["lv3"]],
+ STYLE_TO3NE: [["lv3"]],
+ STYLE_INITIALS: [["l"]],
+ STYLE_FIRST_LETTER: [["l"]],
+ } ],
+
// 单音词
[ "我是谁", {
STYLE_NORMAL: [["wo"], ["shi"], ["shui"]],
+ STYLE_PASSPORT: [["WO"], ["SHI"], ["SHUI"]],
STYLE_TONE: [["wǒ"], ["shì"], ["shuí"]],
STYLE_TONE2: [["wo3"], ["shi4"], ["shui2"]],
STYLE_TO3NE: [["wo3"], ["shi4"], ["shui2"]],
@@ -69,6 +86,7 @@ const cases: any[] = [
// 多音字,单音词。分词后可以准确识别读音。
[ "中国", {
STYLE_NORMAL: [["zhong"], ["guo"]],
+ STYLE_PASSPORT: [["ZHONG"], ["GUO"]],
STYLE_TONE: {
normal: [["zhōng", "zhòng"], ["guó"]],
segment: [["zhōng"], ["guó"]],
@@ -89,6 +107,10 @@ const cases: any[] = [
normal: [["zhong", "chong"], ["xin"]],
segment: [["zhong"], ["xin"]],
},
+ STYLE_PASSPORT: {
+ normal: [["ZHONG", "CHONG"], ["XIN"]],
+ segment: [["ZHONG"], ["XIN"]],
+ },
STYLE_TONE: {
normal: [["zhòng", "chóng"], ["xīn"]],
segment: [["zhòng"], ["xīn"]],