From b98cd8385219c73646ace27f916ea5d0cf3aa084 Mon Sep 17 00:00:00 2001
From: zh-lx <18366276315@163.com>
Date: Tue, 14 Nov 2023 09:20:20 +0800
Subject: [PATCH 1/2] feat: update dict
---
lib/data/dict2.ts | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/lib/data/dict2.ts b/lib/data/dict2.ts
index 3e2d52f..bcfaa9d 100644
--- a/lib/data/dict2.ts
+++ b/lib/data/dict2.ts
@@ -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) => ({
From 9bda5fbd03fbcbf6ca9a759fc28595dfb9d0d592 Mon Sep 17 00:00:00 2001
From: zh-lx <18366276315@163.com>
Date: Tue, 14 Nov 2023 09:40:06 +0800
Subject: [PATCH 2/2] release: 3.18.0
---
CHANGELOG.md | 26 ++++++++++++++++++++++++++
README.md | 2 +-
lib/core/match/index.ts | 10 ++++++++++
package.json | 2 +-
test/match.test.js | 20 +++++++++++++++-----
types/core/match/index.d.ts | 4 ++++
6 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76cc4ff..52cb379 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,31 @@
# 更新日志
+## 3.18.0
+
+- 【feat】match:`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,用于拼音格式转换
diff --git a/README.md b/README.md
index e1c7784..2b59c33 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-[](https://github.com/zh-lx/pinyin-pro)
+[](https://github.com/zh-lx/pinyin-pro)
[](https://www.npmjs.com/package/pinyin-pro)
[](https://github.com/zh-lx/pinyin-pro)
diff --git a/lib/core/match/index.ts b/lib/core/match/index.ts
index f2595f3..c0b70cc 100644
--- a/lib/core/match/index.ts
+++ b/lib/core/match/index.ts
@@ -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;
+ // 是否大小写不敏感
+ if (completeOptions.insensitive !== false) {
+ text = text.toLowerCase();
+ pinyin = pinyin.toLowerCase();
+ }
// 移除空格
if (completeOptions.space === 'ignore') {
pinyin = pinyin.replace(/\s/g, '');
diff --git a/package.json b/package.json
index d8c26cf..deb35e9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "pinyin-pro",
- "version": "3.17.0",
+ "version": "3.18.0",
"description": "准确率和性能最优异的汉字转拼音库。获取中文拼音、韵母、声母、声调、首字母,支持拼音匹配",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
diff --git a/test/match.test.js b/test/match.test.js
index f855005..644cacf 100644
--- a/test/match.test.js
+++ b/test/match.test.js
@@ -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);
+ });
});
diff --git a/types/core/match/index.d.ts b/types/core/match/index.d.ts
index 65921d2..db1397b 100644
--- a/types/core/match/index.d.ts
+++ b/types/core/match/index.d.ts
@@ -15,6 +15,10 @@ interface MatchOptions {
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
+ /**
+ * @description 是否大小写不敏感
+ */
+ insensitive?: boolean;
}
/**
* @description: 检测汉语字符串和拼音是否匹配