Skip to content

Commit

Permalink
feat(3.4.0): 新增姓氏模式和自定义拼音
Browse files Browse the repository at this point in the history
feat(3.4.0): 新增姓氏模式和自定义拼音
  • Loading branch information
zh-lx authored Dec 15, 2021
2 parents 9a56555 + c965b09 commit 7d018f4
Show file tree
Hide file tree
Showing 30 changed files with 971 additions and 83 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 3.4.0

当前版本: 3.3.1 -> 3.4.0

- 新增功能
- 支持姓氏模式拼音识别,具体用法见[姓氏模式](#surname)
- 支持自定义拼音功能,具体用法见[自定义拼音](#custom)
- 问题修复
修复文本过长时堆栈溢出问题
- 字音校准
- 褚: 'zhǔ' -> 'chǔ zhǔ'
- 俞: 'yù' -> 'yú yù'
- 臧: 'zàng' -> 'zāng'
- 贲: 'bì' -> 'bēn bì'
- 莘: 'xīn' -> 'shēn xīn'
- 郦: 'zhí' -> 'lì zhí'

## 3.3.1

当前版本: 3.3.0 -> 3.3.1
Expand Down
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,26 @@
- 获取拼音首字母
- 获取音调
- 获取多音字的多种拼音
- 支持人名姓氏模式
- 支持自定义拼音
- 支持字符串和数组两种输出形式

## 版本更新

当前版本: 3.3.0 -> 3.3.1
当前版本: 3.3.1 -> 3.4.0

- 新增功能
- 支持姓氏模式拼音识别,具体用法见[姓氏模式](#surname)
- 支持自定义拼音功能,具体用法见[自定义拼音](#custom)
- 问题修复
修复文本过长时堆栈溢出问题
- 字音校准
- 褚: 'zhǔ' -> 'chǔ zhǔ'
- 俞: 'yù' -> 'yú yù'
- 臧: 'zàng' -> 'zāng'
- 贲: 'bì' -> 'bēn bì'
- 莘: 'xīn' -> 'shēn xīn'
- 郦: 'zhí' -> 'lì zhí'

点击查看 [版本更新文档](./CHANGELOG.md)

Expand Down Expand Up @@ -84,6 +96,7 @@ pinyin('汉语拼音'); // 'hàn yǔ pīn yīn'
| toneType | 音调输出形式(拼音符号 / 数字 / 不加音调) | string | symbol / num / none | symbol |
| type | 输出结果类型(字符串/数组) | string | string / array | string |
| multiple | 输出多音字全部拼音(仅在 word 为长度为 1 的汉字字符串时生效) | boolean | true / false | false |
| mode | 拼音查找的模式(常规模式 / 姓氏模式) | string | normal / surname | normal |

## 使用示例

Expand Down Expand Up @@ -175,6 +188,33 @@ pinyin('好', { multiple: true }); // 'hǎo hào'
pinyin('', { multiple: true, type: 'array' }); // ["hǎo", "hào"]
```

### <a id="surname">姓氏模式</a>

通过设置 `mode: 'surname'` 开启姓氏模式后,匹配到百家姓中的姓氏优先输出姓氏拼音

```javascript
import { pinyin } from 'pinyin-pro';

// 不开启姓氏模式
pinyin('我叫曾小贤'); // 'wǒ jiào céng xiǎo xián'

// 开启姓氏模式
pinyin('我叫曾小贤', { mode: 'surname' }); // 'wǒ jiào zēng xiǎo xián'
```

### <a id="custom">自定义拼音</a>

包内部导出了 `customPinyin` 方法,支持用户自定义设置词句拼音,当中文中匹配用户自己定义的词句拼音时,优先使用用户自定义的词句拼音

```javascript
import { pinyin, customPinyin } from 'pinyin-pro';

customPinyin({
干一行行一行: 'gàn yī háng xíng yī háng',
});
pinyin('干一行行一行'); // 'gàn yī háng xíng yī háng'
```

## 贡献与反馈

参与开源贡献请参照 [pinyin-pro 贡献](./docs/contribute.md)
Expand Down
12 changes: 6 additions & 6 deletions data/dict1-pinyin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,7 @@ export const DICT1: { [prop: string]: string } = {
: 'wán',
: 'xiè',
: 'má',
: 'yù',
: 'yù',
: 'chì',
: 'shī',
: 'chéng dèng',
Expand Down Expand Up @@ -3193,7 +3193,7 @@ export const DICT1: { [prop: string]: string } = {
: 'ài',
: 'qí',
: 'róng',
: 'zàng',
: 'zāng',
: 'chán',
: 'juàn',
: 'xiā',
Expand Down Expand Up @@ -3352,7 +3352,7 @@ export const DICT1: { [prop: string]: string } = {
: 'jù',
: 'yān',
: 'zhé',
: 'zhǔ',
: 'chǔ zhǔ',
: 'hè',
: 'pài',
: 'sù',
Expand Down Expand Up @@ -3385,7 +3385,7 @@ export const DICT1: { [prop: string]: string } = {
: 'wū',
: 'jiāo',
: 'nǐng níng nìng',
: 'xīn',
: 'shēn xīn',
: 'xùn',
: 'ān',
: 'bì',
Expand Down Expand Up @@ -4089,7 +4089,7 @@ export const DICT1: { [prop: string]: string } = {
: 'wēi',
: 'yú',
: 'yuán',
: 'bì',
: 'bēn bì',
: 'hù',
: 'qí',
: 'nǐ',
Expand Down Expand Up @@ -4579,7 +4579,7 @@ export const DICT1: { [prop: string]: string } = {
: 'huái',
: 'kē',
: 'kē',
: 'zhí',
: 'zhí',
: 'liàng',
: 'lìn',
: 'lù',
Expand Down
15 changes: 8 additions & 7 deletions data/dict1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DICT1: string[] = [];
const DICT1: string[] = [];
DICT1[30340] = 'de dì dí';
DICT1[19968] = 'yī';
DICT1[22269] = 'guó';
Expand Down Expand Up @@ -2450,7 +2450,7 @@ DICT1[31161] = 'yǔ';
DICT1[20024] = 'wán';
DICT1[34809] = 'xiè';
DICT1[22043] = 'má';
DICT1[20446] = 'yù';
DICT1[20446] = 'yù';
DICT1[32709] = 'chì';
DICT1[23608] = 'shī';
DICT1[28548] = 'chéng dèng';
Expand Down Expand Up @@ -3193,7 +3193,7 @@ DICT1[20846] = 'xī';
DICT1[38552] = 'ài';
DICT1[31048] = 'qí';
DICT1[27029] = 'róng';
DICT1[33255] = 'zàng';
DICT1[33255] = 'zāng';
DICT1[34633] = 'chán';
DICT1[32482] = 'juàn';
DICT1[30606] = 'xiā';
Expand Down Expand Up @@ -3352,7 +3352,7 @@ DICT1[26564] = 'bǐng';
DICT1[36382] = 'jù';
DICT1[28937] = 'yān';
DICT1[36740] = 'zhé';
DICT1[35098] = 'zhǔ';
DICT1[35098] = 'chǔ zhǔ';
DICT1[35088] = 'hè';
DICT1[28227] = 'pài';
DICT1[22809] = 'sù';
Expand Down Expand Up @@ -3385,7 +3385,7 @@ DICT1[21683] = 'hāi ké';
DICT1[21596] = 'wū';
DICT1[34527] = 'jiāo';
DICT1[25319] = 'nǐng níng nìng';
DICT1[33688] = 'xīn';
DICT1[33688] = 'shēn xīn';
DICT1[39535] = 'xùn';
DICT1[24245] = 'ān';
DICT1[24380] = 'bì';
Expand Down Expand Up @@ -4089,7 +4089,7 @@ DICT1[22073] = 'liáo';
DICT1[23860] = 'wēi';
DICT1[26044] = 'yú';
DICT1[36757] = 'yuán';
DICT1[36146] = 'bì';
DICT1[36146] = 'bēn bì';
DICT1[25160] = 'hù';
DICT1[20238] = 'qí';
DICT1[26062] = 'nǐ';
Expand Down Expand Up @@ -4579,7 +4579,7 @@ DICT1[36315] = 'bǒ';
DICT1[36381] = 'huái';
DICT1[36722] = 'kē';
DICT1[31392] = 'kē';
DICT1[37094] = 'zhí';
DICT1[37094] = 'zhí';
DICT1[36361] = 'liàng';
DICT1[36495] = 'lìn';
DICT1[25134] = 'lù';
Expand Down Expand Up @@ -20854,3 +20854,4 @@ DICT1[31831] = 'zhuó';
DICT1[40415] = 'zhuó';
DICT1[34879] = 'zhuó';
DICT1[31857] = 'zhuó';
export default DICT1;
5 changes: 3 additions & 2 deletions data/dict2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DICT2: { [prop: string]: string } = {
const DICT2: { [prop: string]: string } = {
阿爸: 'ā bà',
阿鼻: 'ā bí',
阿呆: 'ā dāi',
Expand Down Expand Up @@ -3160,4 +3160,5 @@ export const DICT2: { [prop: string]: string } = {
作为: 'zuò wéi',
坐禅: 'zuò chán',
柞蚕: 'zuò cán',
}
};
export default DICT2;
3 changes: 2 additions & 1 deletion data/dict3.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DICT3: { [prop: string]: string } = {
const DICT3: { [prop: string]: string } = {
阿比让: 'ā bǐ ràng',
阿波罗: 'ā bō luó',
阿昌族: 'ā chāng zú',
Expand Down Expand Up @@ -401,3 +401,4 @@ export const DICT3: { [prop: string]: string } = {
钻天杨: 'zuān tiān yáng',
柞丝绸: 'zuò sī chóu',
};
export default DICT3;
5 changes: 3 additions & 2 deletions data/dict4.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DICT4: { [prop: string]: string } = {
const DICT4: { [prop: string]: string } = {
阿党相为: 'ē dǎng xiāng wéi',
阿尔及尔: 'ā ěr jí ěr',
阿狗阿猫: 'ā gǒu ā māo',
Expand Down Expand Up @@ -3475,4 +3475,5 @@ export const DICT4: { [prop: string]: string } = {
坐不重席: 'zuò bù chóng xí',
坐地自划: 'zuò dì zì huá',
坐视不救: 'zuò shī bù jiù',
}
};
export default DICT4;
3 changes: 2 additions & 1 deletion data/dict5.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DICT5: { [prop: string]: string } = {
const DICT5: { [prop: string]: string } = {
阿尔巴尼亚: 'ā ěr bā ní yà',
阿尔法射线: 'ā ěr fǎ shè xiàn',
阿尔及利亚: 'ā ěr jí lì yà',
Expand Down Expand Up @@ -69,3 +69,4 @@ export const DICT5: { [prop: string]: string } = {
嘴尖舌头快: 'zuǐ jiān shé tóu kuài',
坐山观虎斗: 'zuò shān guān hǔ dòu',
};
export default DICT5;
5 changes: 3 additions & 2 deletions data/initial.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const INITIAL_LIST = [
const INITIAL_LIST = [
'zh',
'ch',
'sh',
Expand All @@ -23,4 +23,5 @@ export const INITIAL_LIST = [
'y',
'w',
'',
]
];
export default INITIAL_LIST;
Loading

0 comments on commit 7d018f4

Please sign in to comment.