(word: string, pinyin: string)
| 22 | } |
| 23 | |
| 24 | function 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 | |
| 45 | async function run() { |
| 46 | const polyphonesKeys = Object.keys(polyphones) |
no test coverage detected
searching dependent graphs…