Skip to content

Commit

Permalink
Merge pull request #138 from zh-lx/release-3.18.0
Browse files Browse the repository at this point in the history
## 3.18.0

- 【feat】<b>match</b>:`options` 参数新增 `insensitive` 选项用于指定匹配时是否大小写不敏感,默认为 `true`
- 【patch】词库添加以下词语:
  - 琵琶: `pí pa`
  - 蘑菇: `mó gu`
  - 葫芦: `hú lu`
  - 狐狸: `hú li`
  - 桔子: `jú zi`
  - 盒子: `hé zi`
  - 桌子: `zhuō zi`
  - 竹子: `zhú zi`
  - 师傅: `shī fu`
  - 衣服: `yī fu`
  - 袜子: `wà zi`
  - 杯子: `bēi zi`
  - 刺猬: `cì wei`
  - 麦子: `mài zi`
  - 队伍: `duì wu`
  - 知了: `zhī liao`
  - 鱼儿: `yú er`
  - 馄饨: `hún tun`
  - 灯笼: `dēng long`
  - 庄稼: `zhuāng jia`
  - 聪明: `cōng ming`
  • Loading branch information
zh-lx authored Nov 14, 2023
2 parents 144489d + 9bda5fb commit ab2eaf2
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# 更新日志

## 3.18.0

- 【feat】<b>match</b>:`options` 参数新增 `insensitive` 选项用于指定匹配时是否大小写不敏感,默认为 `true`
- 【patch】词库添加以下词语:
- 琵琶: `pí pa`
- 蘑菇: `mó gu`
- 葫芦: `hú lu`
- 狐狸: `hú li`
- 桔子: `jú zi`
- 盒子: `hé zi`
- 桌子: `zhuō zi`
- 竹子: `zhú zi`
- 师傅: `shī fu`
- 衣服: `yī fu`
- 袜子: `wà zi`
- 杯子: `bēi zi`
- 刺猬: `cì wei`
- 麦子: `mài zi`
- 队伍: `duì wu`
- 知了: `zhī liao`
- 鱼儿: `yú er`
- 馄饨: `hún tun`
- 灯笼: `dēng long`
- 庄稼: `zhuāng jia`
- 聪明: `cōng ming`

## 3.17.0

- 【feat】新增 `convert` API,用于拼音格式转换
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![pinyin-pro Logo](https://t1.wodetu.cn/2022/11/15/168e8a29acc856c48fdef4060c0ba5ad.png)](https://github.com/zh-lx/pinyin-pro)
[![pinyin-pro Logo](https://github.com/zh-lx/pinyin-pro/assets/73059627/79ffc02d-d223-40f9-a223-ddd2a9c9534b)](https://github.com/zh-lx/pinyin-pro)

[![NPM version](https://img.shields.io/npm/v/pinyin-pro.svg)](https://www.npmjs.com/package/pinyin-pro)
[![GITHUB star](https://img.shields.io/github/stars/zh-lx/pinyin-pro.svg)](https://github.com/zh-lx/pinyin-pro)
Expand Down
10 changes: 10 additions & 0 deletions lib/core/match/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ interface MatchOptions {
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 是否大小写不敏感
*/
insensitive?: boolean;
}

const DefaultMatchOptions: MatchOptions = {
precision: 'first',
continuous: false,
space: 'ignore',
lastPrecision: 'start',
insensitive: true,
};

const MAX_PINYIN_LENGTH = 6;
Expand All @@ -43,6 +48,11 @@ export const match = (text: string, pinyin: string, options?: MatchOptions) => {
...DefaultMatchOptions,
...(options || {}),
} as Required<MatchOptions>;
// 是否大小写不敏感
if (completeOptions.insensitive !== false) {
text = text.toLowerCase();
pinyin = pinyin.toLowerCase();
}
// 移除空格
if (completeOptions.space === 'ignore') {
pinyin = pinyin.replace(/\s/g, '');
Expand Down
21 changes: 21 additions & 0 deletions lib/data/dict2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,27 @@ const DICT2: { [prop: string]: string } = {
茄子: 'qié zi',
蚌埠: 'bèng bù',
崆峒: 'kōng tóng',
琵琶: 'pí pa',
蘑菇: 'mó gu',
葫芦: 'hú lu',
狐狸: 'hú li',
桔子: 'jú zi',
盒子: 'hé zi',
桌子: 'zhuō zi',
竹子: 'zhú zi',
师傅: 'shī fu',
衣服: 'yī fu',
袜子: 'wà zi',
杯子: 'bēi zi',
刺猬: 'cì wei',
麦子: 'mài zi',
队伍: 'duì wu',
知了: 'zhī liao',
鱼儿: 'yú er',
馄饨: 'hún tun',
灯笼: 'dēng long',
庄稼: 'zhuāng jia',
聪明: 'cōng ming',
};
export default DICT2;
export const Pattern2: Pattern[] = Object.keys(DICT2).map((key) => ({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pinyin-pro",
"version": "3.17.0",
"version": "3.18.0",
"description": "准确率和性能最优异的汉字转拼音库。获取中文拼音、韵母、声母、声调、首字母,支持拼音匹配",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
20 changes: 15 additions & 5 deletions test/match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,37 @@ describe('match', () => {
});

it('[match]lastPrecision every fail', () => {
const result = match('汉语拼音', 'hanyupinyi', {lastPrecision: 'every'});
const result = match('汉语拼音', 'hanyupinyi', { lastPrecision: 'every' });
expect(result).to.deep.equal(null);
});

it('[match]lastPrecision every success', () => {
const result = match('汉语拼音', 'hanyupinyin', {lastPrecision: 'every'});
const result = match('汉语拼音', 'hanyupinyin', { lastPrecision: 'every' });
expect(result).to.deep.equal([0, 1, 2, 3]);
});

it('[match]lastPrecision first fail', () => {
const result = match('汉语拼音', 'hanyupinyi', {lastPrecision: 'first'});
const result = match('汉语拼音', 'hanyupinyi', { lastPrecision: 'first' });
expect(result).to.deep.equal(null);
});

it('[match]lastPrecision first success', () => {
const result = match('汉语拼音', 'hanyupiny', {lastPrecision: 'first'});
const result = match('汉语拼音', 'hanyupiny', { lastPrecision: 'first' });
expect(result).to.deep.equal([0, 1, 2, 3]);
});

it('[match]lastPrecision any', () => {
const result = match('汉语拼音', 'hanyupini', {lastPrecision: 'any'});
const result = match('汉语拼音', 'hanyupini', { lastPrecision: 'any' });
expect(result).to.deep.equal([0, 1, 2, 3]);
});

it('[match]insensitive', () => {
const result = match('汉语KK拼音', 'hanyukkpinyin');
expect(result).to.deep.equal([0, 1, 2, 3, 4, 5]);

const result1 = match('汉语KK拼音', 'hanyukkpinyin', {
insensitive: false,
});
expect(result1).to.deep.equal(null);
});
});
4 changes: 4 additions & 0 deletions types/core/match/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ interface MatchOptions {
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 是否大小写不敏感
*/
insensitive?: boolean;
}
/**
* @description: 检测汉语字符串和拼音是否匹配
Expand Down

0 comments on commit ab2eaf2

Please sign in to comment.