This commit is contained in:
2026-09-24 16:25:22 +08:00
commit 7428184f01
1198 changed files with 314515 additions and 0 deletions
@@ -0,0 +1,28 @@
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)
}
}