mirror of
https://github.com/zh-lx/pinyin-pro.git
synced 2026-03-13 09:51:38 +08:00
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:
26
CHANGELOG.md
26
CHANGELOG.md
@@ -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,用于拼音格式转换
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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, '');
|
||||
|
||||
@@ -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) => ({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pinyin-pro",
|
||||
"version": "3.17.0",
|
||||
"version": "3.18.0",
|
||||
"description": "准确率和性能最优异的汉字转拼音库。获取中文拼音、韵母、声母、声调、首字母,支持拼音匹配",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
||||
@@ -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
types/core/match/index.d.ts
vendored
4
types/core/match/index.d.ts
vendored
@@ -15,6 +15,10 @@ interface MatchOptions {
|
||||
* @description 最后一个字的匹配精度
|
||||
*/
|
||||
lastPrecision?: 'first' | 'start' | 'every' | 'any';
|
||||
/**
|
||||
* @description 是否大小写不敏感
|
||||
*/
|
||||
insensitive?: boolean;
|
||||
}
|
||||
/**
|
||||
* @description: 检测汉语字符串和拼音是否匹配
|
||||
|
||||
Reference in New Issue
Block a user