Files
pinyin-pro/lib/common/type.ts
zhoulixiang 7f658c978b feat: add traditional Chinese character recognition mode
Add support for traditional Chinese characters with the `traditional` option.
This includes new `addTraditionalDict` and `getTraditionalDict` APIs,
and integration with pinyin, html, and segment functions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 12:38:30 +08:00

83 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 单字拼音转换后的结果
export interface SingleWordResult {
origin: string;
originPinyin: string;
result: string;
isZh: boolean;
delete?: boolean;
traditional?: string;
}
// toneType 属性可选参数
export type ToneType = "symbol" | "num" | "none";
export type PinyinMode = "normal" | "surname";
export type SurnameMode = "all" | "head" | "off";
export type InitialPattern = "yw" | "standard";
export type CommonOptions = {
/**
* @description 返回的拼音音调类型
* @value symbol在字母上加音调 (默认值)
* @value num以数字格式展示音调并跟在拼音后面
* @value none不展示音调
*/
toneType?: "symbol" | "num" | "none";
/**
* @description 返回的拼音格式类型
* @value pinyin返回完整拼音 (默认值)
* @value initial返回声母
* @value final返回韵母
* @value num返回音调对应的数字
* @value first返回首字母
* @value finalHead返回韵头介音
* @value finalBody返回韵腹
* @value finalTail返回韵尾
*/
pattern?:
| "pinyin"
| "initial"
| "final"
| "num"
| "first"
| "finalHead"
| "finalBody"
| "finalTail";
/**
* @description 是否移除非汉字字符(推荐使用 removeNonZh: removed 代替)
* @value false返回结果保留非汉字字符 (默认值)
* @value true返回结果移除非汉字字符
*/
removeNonZh?: boolean;
/**
* @description 非汉字字符的间距格式
* @value spaced连续非汉字字符之间用空格隔开 (默认值)
* @value consecutive连续非汉字字符无间距
* @value removed返回结果移除非汉字字符
*/
nonZh?: "spaced" | "consecutive" | "removed";
/**
* @description nonZh 生效范围的正则表达式
*/
nonZhScope?: RegExp;
/**
* @description 对于 ü 的返回是否转换成 v仅在 toneType: none 启用时生效)
* @value false返回值中保留 ü (默认值)
* @value true返回值中 ü 转换成 v
* @value string返回值中 ü 转换成指定字符
*/
v?: boolean | string;
/**
* @description 是否将 `y`、`w` 视为声母
* @value yw将 `y`、`w` 视为声母
* @value standard不将 `y`、`w` 视为声母
*/
initialPattern?: InitialPattern;
/**
* @description 是否启用繁体字模式(可以更好地识别繁体字)
* @value false不启用繁体字模式 (默认值)
* @value true启用繁体字模式
*/
traditional?: boolean;
};