Skip to content

Commit

Permalink
Merge pull request #149 from zh-lx/release-3.18.6
Browse files Browse the repository at this point in the history
release: 3.18.6
  • Loading branch information
zh-lx committed Jan 2, 2024
2 parents 2545ff1 + 4d119cf commit f2929b3
Show file tree
Hide file tree
Showing 24 changed files with 558 additions and 551 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.18.6

- 【patch】词库修正以下词语,详见 [#148](https://github.com/zh-lx/pinyin-pro/pull/148)
- 【fix】<b>convert</b>:支持 `v` 输入转换,例如:`lv4 se4` -> `lǜ sè`

## 3.18.5

Expand Down
11 changes: 6 additions & 5 deletions lib/core/convert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface ConvertOptions {
separator?: string;
/**
* @description 转换的格式, 默认为 numToSymbol
* @example numToSymbol: pin yin -> pīn yīn
* @example symbolToNum: pīn yīn -> pin yin
* @example numToSymbol: pin1 yin1 -> pīn yīn
* @example symbolToNum: pīn yīn -> pin1 yin1
* @example toneNone: pīn yīn -> pin yin
*/
format?: ConvertFormat;
Expand All @@ -26,6 +26,7 @@ const toneMap = {
o: ['o', 'ō', 'ó', 'ǒ', 'ò'],
e: ['e', 'ē', 'é', 'ě', 'è'],
ü: ['ü', 'ǖ', 'ǘ', 'ǚ', 'ǜ'],
v: ['ü', 'ǖ', 'ǘ', 'ǚ', 'ǜ'],
ui: ['ui', 'uī', 'uí', 'uǐ', 'uì'],
iu: ['iu', 'īu', 'íu', 'ǐu', 'ìu'],
i: ['i', 'ī', 'í', 'ǐ', 'ì'],
Expand All @@ -35,23 +36,23 @@ const toneMap = {
};

/**
* @description: 拼音格式转换。pin yin -> pīn yīn 或 pīn yīn -> pin yin 或 pīn yīn -> pin yin
* @description: 拼音格式转换。pin1 yin1 -> pīn yīn 或 pīn yīn -> pin1 yin1 或 pīn yīn -> pin yin
* @param {string} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string} 转换后的拼音字符串或者拼音字符串数组
*/
function convert(pinyin: string, options?: ConvertOptions): string;

/**
* @description: 拼音格式转换。pin yin -> pīn yīn 或 pīn yīn -> pin yin 或 pīn yīn -> pin yin
* @description: 拼音格式转换。pin1 yin1 -> pīn yīn 或 pīn yīn -> pin1 yin1 或 pīn yīn -> pin yin
* @param {string[]} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string[]} 转换后的拼音字符串或者拼音字符串数组
*/
function convert(pinyin: string[], options?: ConvertOptions): string[];

/**
* @description: 拼音格式转换。pin yin -> pīn yīn 或 pīn yīn -> pin yin 或 pīn yīn -> pin yin
* @description: 拼音格式转换。pin1 yin1 -> pīn yīn 或 pīn yīn -> pin1 yin1 或 pīn yīn -> pin yin
* @param {string | string[]} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string | string[]} 转换后的拼音字符串或者拼音字符串数组
Expand Down
5 changes: 5 additions & 0 deletions test/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ describe('convert', () => {
const result = convert('pin1 a yin1');
expect(result).to.be.equal('pīn a yīn');
});

it('[convert]v', () => {
const result = convert('lv4 se4');
expect(result).to.be.equal('lǜ sè');
});
});
64 changes: 32 additions & 32 deletions types/common/ac.d.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
/**
* @description: AC 自动机
*/
export interface Pattern {
zh: string;
pinyin: string;
priority: number;
length: number;
isSurname?: boolean;
}
interface MatchPattern extends Pattern {
index: number;
}
declare class TrieNode {
children: Map<string, TrieNode>;
fail: TrieNode | null;
isEnd: boolean;
pattern: Pattern | null;
constructor();
}
export declare class AC {
root: TrieNode;
constructor();
buildTrie(patterns: Pattern[]): void;
reset(): void;
buildFailPointer(): void;
search(text: string, isSurname?: boolean): MatchPattern[];
filter(patterns: MatchPattern[], isSurname?: boolean): MatchPattern[];
}
export declare const PatternsNormal: Pattern[];
export declare const ACNormal: AC;
export {};
/**
* @description: AC 自动机
*/
export interface Pattern {
zh: string;
pinyin: string;
priority: number;
length: number;
isSurname?: boolean;
}
interface MatchPattern extends Pattern {
index: number;
}
declare class TrieNode {
children: Map<string, TrieNode>;
fail: TrieNode | null;
isEnd: boolean;
pattern: Pattern | null;
constructor();
}
export declare class AC {
root: TrieNode;
constructor();
buildTrie(patterns: Pattern[]): void;
reset(): void;
buildFailPointer(): void;
search(text: string, isSurname?: boolean): MatchPattern[];
filter(patterns: MatchPattern[], isSurname?: boolean): MatchPattern[];
}
export declare const PatternsNormal: Pattern[];
export declare const ACNormal: AC;
export {};
4 changes: 2 additions & 2 deletions types/common/constant.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export declare const DoubleUnicodePrefixReg: RegExp;
export declare const DoubleUnicodeSuffixReg: RegExp;
export declare const DoubleUnicodePrefixReg: RegExp;
export declare const DoubleUnicodeSuffixReg: RegExp;
18 changes: 9 additions & 9 deletions types/common/type.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface SingleWordResult {
origin: string;
originPinyin: string;
result: string;
isZh: boolean;
delete?: boolean;
}
export declare type ToneType = 'symbol' | 'num' | 'none';
export declare type PinyinMode = 'normal' | 'surname';
export interface SingleWordResult {
origin: string;
originPinyin: string;
result: string;
isZh: boolean;
delete?: boolean;
}
export type ToneType = 'symbol' | 'num' | 'none';
export type PinyinMode = 'normal' | 'surname';
6 changes: 3 additions & 3 deletions types/common/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export declare function getStringLength(string: string): number;
export declare function getSplittedWord(string: string): string[];
export declare function isZhChar(char: string): boolean;
export declare function getStringLength(string: string): number;
export declare function getSplittedWord(string: string): string[];
export declare function isZhChar(char: string): boolean;
58 changes: 29 additions & 29 deletions types/core/convert/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
declare type ConvertFormat = 'numToSymbol' | 'symbolToNum' | 'toneNone';
interface ConvertOptions {
/**
* @description 拼音之间的分隔符,默认为空格,convert方法会以该分隔符分割拼音进行转换
*/
separator?: string;
/**
* @description 转换的格式, 默认为 numToSymbol
* @example numToSymbol: pin yin -> pīn yīn
* @example symbolToNum: pīn yīn -> pin yin
* @example toneNone: pīn yīn -> pin yin
*/
format?: ConvertFormat;
}
/**
* @description: 拼音格式转换。pin yin -> pīn yīn 或 pīn yīn -> pin yin 或 pīn yīn -> pin yin
* @param {string} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string} 转换后的拼音字符串或者拼音字符串数组
*/
declare function convert(pinyin: string, options?: ConvertOptions): string;
/**
* @description: 拼音格式转换。pin yin -> pīn yīn 或 pīn yīn -> pin yin 或 pīn yīn -> pin yin
* @param {string[]} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string[]} 转换后的拼音字符串或者拼音字符串数组
*/
declare function convert(pinyin: string[], options?: ConvertOptions): string[];
export { convert };
type ConvertFormat = 'numToSymbol' | 'symbolToNum' | 'toneNone';
interface ConvertOptions {
/**
* @description 拼音之间的分隔符,默认为空格,convert方法会以该分隔符分割拼音进行转换
*/
separator?: string;
/**
* @description 转换的格式, 默认为 numToSymbol
* @example numToSymbol: pin1 yin1 -> pīn yīn
* @example symbolToNum: pīn yīn -> pin1 yin1
* @example toneNone: pīn yīn -> pin yin
*/
format?: ConvertFormat;
}
/**
* @description: 拼音格式转换。pin1 yin1 -> pīn yīn 或 pīn yīn -> pin1 yin1 或 pīn yīn -> pin yin
* @param {string} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string} 转换后的拼音字符串或者拼音字符串数组
*/
declare function convert(pinyin: string, options?: ConvertOptions): string;
/**
* @description: 拼音格式转换。pin1 yin1 -> pīn yīn 或 pīn yīn -> pin1 yin1 或 pīn yīn -> pin yin
* @param {string[]} pinyin 要转换的拼音字符串或者拼音字符串数组
* @param {ConvertOptions=} options 配置项
* @return {string[]} 转换后的拼音字符串或者拼音字符串数组
*/
declare function convert(pinyin: string[], options?: ConvertOptions): string[];
export { convert };
22 changes: 11 additions & 11 deletions types/core/custom/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @description: 用户自定义拼音
* @param {{ [key: string]: string }} config 用户自定义的拼音映射(支持汉字、词语、句子的映射),若匹配到该映射,优先将汉字转换为该映射
*/
export declare function customPinyin(config?: {
[key: string]: string;
}): void;
export declare const getCustomDict: () => {
[key: string]: string;
};
export declare function hasCustomConfig(): boolean;
/**
* @description: 用户自定义拼音
* @param {{ [key: string]: string }} config 用户自定义的拼音映射(支持汉字、词语、句子的映射),若匹配到该映射,优先将汉字转换为该映射
*/
export declare function customPinyin(config?: {
[key: string]: string;
}): void;
export declare const getCustomDict: () => {
[key: string]: string;
};
export declare function hasCustomConfig(): boolean;
68 changes: 34 additions & 34 deletions types/core/html/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
interface HtmlOptions {
/**
* @description html 结果中每个字+拼音外层 span 标签的类名。默认为 py-result-item
*/
resultClass?: string;
/**
* @description html 结果中拼音 rt 标签的类名。默认为 py-pinyin-item
*/
pinyinClass?: string;
/**
* @description html 结果中汉字 span 标签的类名。默认为 py-chinese-item
*/
chineseClass?: string;
/**
* @description 是否用 span 标签包装非汉字字符的结果。默认为 false。建议输入的文本为纯文本时可以设置为 true;输入文本本身为 html 富文本字符串设置为 false
*/
wrapNonChinese?: boolean;
/**
* @description html 非汉字字符外层 span 标签的类名,仅当 wrapNonChinese 为 true 时生效。默认为 py-non-chinese-item
*/
nonChineseClass?: string;
/**
* @description 拼音上是否标注音调
*/
toneType?: 'symbol' | 'num' | 'none';
}
/**
* @description: 获取带拼音汉字的 html 字符串
* @param {string} text 要转换的字符串
* @param {HtmlOptions=} options html 中标签类名相关配置
* @return {string} 带汉字的拼音字符串
*/
export declare const html: (text: string, options?: HtmlOptions | undefined) => string;
export {};
interface HtmlOptions {
/**
* @description html 结果中每个字+拼音外层 span 标签的类名。默认为 py-result-item
*/
resultClass?: string;
/**
* @description html 结果中拼音 rt 标签的类名。默认为 py-pinyin-item
*/
pinyinClass?: string;
/**
* @description html 结果中汉字 span 标签的类名。默认为 py-chinese-item
*/
chineseClass?: string;
/**
* @description 是否用 span 标签包装非汉字字符的结果。默认为 false。建议输入的文本为纯文本时可以设置为 true;输入文本本身为 html 富文本字符串设置为 false
*/
wrapNonChinese?: boolean;
/**
* @description html 非汉字字符外层 span 标签的类名,仅当 wrapNonChinese 为 true 时生效。默认为 py-non-chinese-item
*/
nonChineseClass?: string;
/**
* @description 拼音上是否标注音调
*/
toneType?: 'symbol' | 'num' | 'none';
}
/**
* @description: 获取带拼音汉字的 html 字符串
* @param {string} text 要转换的字符串
* @param {HtmlOptions=} options html 中标签类名相关配置
* @return {string} 带汉字的拼音字符串
*/
export declare const html: (text: string, options?: HtmlOptions) => string;
export {};
62 changes: 31 additions & 31 deletions types/core/match/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
interface MatchOptions {
/**
* @description 每个汉字和拼音需要遵从的匹配精度
*/
precision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 匹配的汉字下标是否为连续的才算匹配成功
*/
continuous?: boolean;
/**
* @description 匹配时对于空格的处理
*/
space?: 'ignore' | 'preserve';
/**
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 是否大小写不敏感
*/
insensitive?: boolean;
}
/**
* @description: 检测汉语字符串和拼音是否匹配
* @param {string} text 汉语字符串
* @param {string} pinyin 拼音,支持各种缩写形式
* @param {MatchOptions=} options 配置项
* @return {Array | null} 若匹配成功,返回 text 中匹配成功的下标数组;若匹配失败,返回 null
*/
export declare const match: (text: string, pinyin: string, options?: MatchOptions | undefined) => any;
export {};
interface MatchOptions {
/**
* @description 每个汉字和拼音需要遵从的匹配精度
*/
precision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 匹配的汉字下标是否为连续的才算匹配成功
*/
continuous?: boolean;
/**
* @description 匹配时对于空格的处理
*/
space?: 'ignore' | 'preserve';
/**
* @description 最后一个字的匹配精度
*/
lastPrecision?: 'first' | 'start' | 'every' | 'any';
/**
* @description 是否大小写不敏感
*/
insensitive?: boolean;
}
/**
* @description: 检测汉语字符串和拼音是否匹配
* @param {string} text 汉语字符串
* @param {string} pinyin 拼音,支持各种缩写形式
* @param {MatchOptions=} options 配置项
* @return {Array | null} 若匹配成功,返回 text 中匹配成功的下标数组;若匹配失败,返回 null
*/
export declare const match: (text: string, pinyin: string, options?: MatchOptions) => any;
export {};

0 comments on commit f2929b3

Please sign in to comment.