All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m38s
- 使用pinyin-pro进行汉语拼音转换 - 调整搜索权重
18 lines
412 B
TypeScript
18 lines
412 B
TypeScript
import { pinyin } from 'pinyin-pro';
|
|
|
|
/**
|
|
* 将汉语文本转换为拼音形式
|
|
*/
|
|
export function transliterateText(input: string): string {
|
|
if (!input) return '';
|
|
const text = input.normalize('NFKC').trim();
|
|
|
|
// 检测是否包含中文字符
|
|
if (/[\u4e00-\u9fa5]/.test(text)) {
|
|
return pinyin(text, { toneType: 'none', type: 'array' }).join('');
|
|
}
|
|
|
|
// 否则返回原文本
|
|
return text;
|
|
}
|