Files
CatoandClaude Opus 5.5 af6d128c87 feat(atlas): measured resources, producers, restrictions, sanctions and ranked peers in the country panel (#107)
* wip(resources): country panel data — OECD restrictions, sanctions, EIA energy, USGS producers

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(atlas): country panel with measured resources, producers, restrictions, sanctions and ranked peers

Replaces "Similar geologies" (first eight countries sharing any directory
resource, so Russia's peer was Timor-Leste) with "Peers on <resource>":
the other leading producers by the same USGS/EIA column. Per resource the
panel now shows production (latest and prior year, change), world rank and
share, reserves and reserves-to-production, USGS Minerals Yearbook
producers, corpus producer rows, OECD export restrictions, sanctions
measures that name the resource, and USGS/corpus statements — or "not
recorded". Adds /resources/[slug] (world ranking, HHI, CSV, restrictions by
country) and computed country headlines in place of directory blurbs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 05:31:49 -07:00

36 lines
1.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** How resource figures are printed: USGS precision for tables, readable precision for EIA's decimals. */
export function formatValue(value: number): string {
const abs = Math.abs(value);
if (abs >= 100) return Math.round(value).toLocaleString('en');
if (abs >= 10) return value.toLocaleString('en', { maximumFractionDigits: 1 });
return value.toLocaleString('en', { maximumFractionDigits: 2 });
}
/** A share as a percentage: one decimal under 10%, none above; "<0.1%" rather than a misleading zero. */
export function formatShare(share: number): string {
const pct = share * 100;
// A country against a rounded world total can reach or pass 100%.
if (pct >= 99.5) return '~100%';
if (pct > 0 && pct < 0.1) return '<0.1%';
return `${pct < 10 ? pct.toFixed(1) : Math.round(pct)}%`;
}
export function ordinal(n: number): string {
const tens = n % 100;
const suffix =
tens >= 11 && tens <= 13
? 'th'
: (({ 1: 'st', 2: 'nd', 3: 'rd' } as Record<number, string>)[n % 10] ?? 'th');
return `${n}${suffix}`;
}
export function formatChange(change: number): string {
const pct = Math.round(change * 100);
return `${pct > 0 ? '+' : pct < 0 ? '−' : '±'}${Math.abs(pct)}%`;
}
export function formatYears(years: number): string {
return years >= 1000 ? 'over 1,000 years' : `${Math.round(years).toLocaleString('en')} years`;
}