Merge pull request #138 from zh-lx/release-3.18.0

## 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`
This commit is contained in:
zhoulixiang
2023-11-13 19:42:47 -06:00
committed by GitHub
7 changed files with 78 additions and 7 deletions

View File

@@ -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用于拼音格式转换

View File

@@ -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)

View File

@@ -17,6 +17,10 @@ interface MatchOptions {
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 是否大小写不敏感
*/
insensitive?: boolean;
}
const DefaultMatchOptions: MatchOptions = {
@@ -24,6 +28,7 @@ const DefaultMatchOptions: MatchOptions = {
continuous: false,
space: 'ignore',
lastPrecision: 'start',
insensitive: true,
};
const MAX_PINYIN_LENGTH = 6;
@@ -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, '');

View File

@@ -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) => ({

View File

@@ -1,6 +1,6 @@
{
"name": "pinyin-pro",
"version": "3.17.0",
"version": "3.18.0",
"description": "准确率和性能最优异的汉字转拼音库。获取中文拼音、韵母、声母、声调、首字母,支持拼音匹配",
"main": "./dist/index.js",
"module": "./dist/index.mjs",

View File

@@ -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);
});
});

View File

@@ -15,6 +15,10 @@ interface MatchOptions {
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 是否大小写不敏感
*/
insensitive?: boolean;
}
/**
* @description: 检测汉语字符串和拼音是否匹配