MCPcopy Create free account
hub / github.com/antfu/handle / validPinyin

Function validPinyin

tools/update.ts:24–43  ·  view source on GitHub ↗
(word: string, pinyin: string)

Source from the content-addressed store, hash-verified

22}
23
24function validPinyin(word: string, pinyin: string) {
25 if (!pinyin.match(/^[a-z0-9 ]+$/))
26 return console.log(c.red(`[${word}] invalid char`), c.yellow(pinyin))
27 if (!pinyin.match(/[0-9]/))
28 return console.log(c.red(`[${word}] invalid tone`), c.magenta(pinyin))
29 const parts = pinyin.split(/\s+/g)
30 if (parts.length !== 4)
31 return console.log(c.red(`[${word}] invalid length`), c.blue(pinyin))
32 parts.forEach(async (i, idx) => {
33 const match = i.match(/^([a-z]+)([0-4])?$/)
34 if (!match)
35 return console.error(c.red(`[${word}] invalid pinyin [${idx}]:`), c.blue(i), '->', c.green(await getPinyinWeb(word[idx])))
36 // eslint-disable-next-line @typescript-eslint/no-unused-vars
37 const [full, body, tone] = match
38 if (!toZhuyin(body))
39 console.error(c.red(`[${word}] invalid pinyin [${idx}]:`), c.blue(i), '->', c.green(await getPinyinWeb(word[idx])))
40 // if (!tone)
41 // console.error(c.red(`[${word}] no tone [${idx}]:`), c.blue(i), '->', c.green(await getPinyinWeb(word[idx])))
42 })
43}
44
45async function run() {
46 const polyphonesKeys = Object.keys(polyphones)

Callers 1

runFunction · 0.85

Calls 2

toZhuyinFunction · 0.90
getPinyinWebFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…