import { readFileSync, writeFileSync } from 'fs'; import { ILevelMap } from '@/level'; import { WaniKani } from '@/wanikani'; import yaml from 'js-yaml'; export async function repairBeyond() { const beyond = yaml.load( readFileSync('cache/beyond.yaml', 'utf-8'), ) as Record; const levelMap: ILevelMap = {}; for (const [levelString, vs] of Object.entries(beyond)) { const level = Number(levelString); let category: string; if (level < 71) { category = '61-70: 無限 INFINITY'; } else if (level < 76) { category = '71-75: 極端 BEYOND'; } else { category = '76+: 熟達 MASTERY'; } const catMap = levelMap[category] || {}; const ks = catMap[levelString] || []; ks.push(...vs); catMap[levelString] = ks; levelMap[category] = catMap; } writeFileSync( WaniKani.files.beyond, yaml.dump(levelMap, { sortKeys: true, flowLevel: 2, }), ); } if (require.main === module) { repairBeyond(); }