const main = document.querySelector('main') as HTMLTextAreaElement; (async () => { const loader = document.querySelector('#loader') as HTMLElement; loader.style.display = 'block'; try { await render(); } catch (e) { main.textContent = e instanceof Error ? e.message : String(e); } loader.style.display = 'none'; })(); async function render(): Promise { const corps: Corporation[] = await fetch('corps.json').then((r) => r.json()); corps.sort((a, b) => (a.headquartersAddress?.lines.find((line) => line.type === 'SYSTEM')!.entity.naturalId ?? '\uffff') .localeCompare(b.headquartersAddress?.lines.find((line) => line.type === 'SYSTEM')!.entity.naturalId ?? '\uffff')); main.innerHTML = ` ${corps.map(renderCorpRow).join('')}
code name shareholders HQ
`; } function renderCorpRow(corp: Corporation): string { let hq = ''; if (corp.headquartersAddress !== null) { const planet = corp.headquartersAddress.lines.find((line) => line.type === 'PLANET')!.entity; hq = planet.name; if (planet.name !== planet.naturalId) hq += ` (${planet.naturalId})`; if (!corp.headquartersFinished) hq += ' [unfinished]'; } return ` ${corp.code} ${corp.name} ${corp.shareholders.length} ${hq} `; } interface Corporation { name: string; code: string; headquartersAddress: {lines: {type: 'SYSTEM' | 'PLANET', entity: {name: string, naturalId: string}}[]} | null; headquartersFinished: boolean; shareholders: {}[]; }