Files
hospital-rescue-app-v2/uni_modules/x-chinesetopinyin-s/utssdk/mp-weixin/index.uts
T
2026-09-24 16:25:22 +08:00

28 lines
856 B
Plaintext

import { pinyin } from "./pinyintojs.js"
import { XuiChineseToPinYinOpts, XuiChineseToPinYinResult } from "../interface.uts"
import { XuiChineseToPinYinFailImpl } from "../unierror.uts"
/** 中文转拼音 */
export function toPinYin(opts : XuiChineseToPinYinOpts){
try {
let c = opts.char;
if (c == '') {
let errorIml = new XuiChineseToPinYinFailImpl(1002)
opts?.fail?.(errorIml)
opts?.complete?.(null)
return;
}
const result = pinyin(c, { toneType: 'none', style: pinyin.STYLE_NORMAL })
const resultZhuying = pinyin(c, { toneType: 'symbol', style: pinyin.STYLE_NORMAL })
const ok : XuiChineseToPinYinResult = {
detail: result,
zhuyin: resultZhuying
}
opts?.success?.(ok)
opts?.complete?.(ok)
} catch (error) {
console.error(error)
opts?.fail?.(new XuiChineseToPinYinFailImpl(1001))
opts?.complete?.(null)
}
}