Rates for currencies the ECB lacks (ALL); only list currencies in circulation #5
4 changed files with 52 additions and 7 deletions
|
|
@ -1,9 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { currencyList } from '../lib/rates.ts';
|
import { currencyList } from '../lib/rates.ts';
|
||||||
import { currencyName } from '../lib/format.ts';
|
import { currencyName } from '../lib/format.ts';
|
||||||
|
import { t } from '../lib/settings.svelte.ts';
|
||||||
|
|
||||||
let { value = $bindable(), disabled = false, id }: { value: string; disabled?: boolean; id?: string } = $props();
|
let { value = $bindable(), disabled = false, id }: { value: string; disabled?: boolean; id?: string } = $props();
|
||||||
let lists = $state<{ ecb: string[]; other: string[] }>({ ecb: [], other: [] });
|
let lists = $state<{ rated: string[]; other: string[] }>({ rated: [], other: [] });
|
||||||
currencyList().then((l) => (lists = l));
|
currencyList().then((l) => (lists = l));
|
||||||
|
|
||||||
const recent = (() => {
|
const recent = (() => {
|
||||||
|
|
@ -14,9 +15,9 @@
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
// Keep the current value selectable even before the lists load, or if
|
// Keep the current value selectable even before the lists load, or if
|
||||||
// it's a code this browser doesn't know.
|
// it's a code that is no longer in circulation (e.g. an old group in BGN).
|
||||||
const ecb = $derived(
|
const rated = $derived(
|
||||||
[...lists.ecb, ...lists.other, ...recent].includes(value) ? lists.ecb : [value, ...lists.ecb],
|
[...lists.rated, ...lists.other, ...recent].includes(value) ? lists.rated : [value, ...lists.rated],
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -26,11 +27,11 @@
|
||||||
{#each recent as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
{#each recent as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
{/if}
|
{/if}
|
||||||
<optgroup label="ECB">
|
<optgroup label={t('currencies_rated')}>
|
||||||
{#each ecb as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
{#each rated as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
{#if lists.other.length}
|
{#if lists.other.length}
|
||||||
<optgroup label="…">
|
<optgroup label={t('currencies_manual')}>
|
||||||
{#each lists.other as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
{#each lists.other as c}<option value={c}>{c} · {currencyName(c)}</option>{/each}
|
||||||
</optgroup>
|
</optgroup>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
||||||
32
packages/core/src/currencies.ts
Normal file
32
packages/core/src/currencies.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
// Currencies offered in the picker. Hardcoded rather than read from
|
||||||
|
// Intl.supportedValuesOf('currency'), which in browsers also returns
|
||||||
|
// historical codes (ATS, DEM, YUM, …) that nobody can spend any more.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ISO 4217 currencies in circulation today. Excludes fund codes (CLF, USN, …),
|
||||||
|
* precious metals and other non-cash units (XAU, XDR, XSU), and codes that
|
||||||
|
* have been replaced: ANG → XCG (2025), BGN → EUR (2026), CUC (2021),
|
||||||
|
* HRK → EUR (2023), SLL → SLE (2024), ZWL → ZWG (2024).
|
||||||
|
* Update this list when ISO 4217 changes.
|
||||||
|
*/
|
||||||
|
export const ACTIVE_CURRENCIES: readonly string[] = [
|
||||||
|
'AED', 'AFN', 'ALL', 'AMD', 'AOA', 'ARS', 'AUD', 'AWG', 'AZN', 'BAM', 'BBD', 'BDT',
|
||||||
|
'BHD', 'BIF', 'BMD', 'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN', 'BZD', 'CAD',
|
||||||
|
'CDF', 'CHF', 'CLP', 'CNY', 'COP', 'CRC', 'CUP', 'CVE', 'CZK', 'DJF', 'DKK', 'DOP',
|
||||||
|
'DZD', 'EGP', 'ERN', 'ETB', 'EUR', 'FJD', 'FKP', 'GBP', 'GEL', 'GHS', 'GIP', 'GMD',
|
||||||
|
'GNF', 'GTQ', 'GYD', 'HKD', 'HNL', 'HTG', 'HUF', 'IDR', 'ILS', 'INR', 'IQD', 'IRR',
|
||||||
|
'ISK', 'JMD', 'JOD', 'JPY', 'KES', 'KGS', 'KHR', 'KMF', 'KPW', 'KRW', 'KWD', 'KYD',
|
||||||
|
'KZT', 'LAK', 'LBP', 'LKR', 'LRD', 'LSL', 'LYD', 'MAD', 'MDL', 'MGA', 'MKD', 'MMK',
|
||||||
|
'MNT', 'MOP', 'MRU', 'MUR', 'MVR', 'MWK', 'MXN', 'MYR', 'MZN', 'NAD', 'NGN', 'NIO',
|
||||||
|
'NOK', 'NPR', 'NZD', 'OMR', 'PAB', 'PEN', 'PGK', 'PHP', 'PKR', 'PLN', 'PYG', 'QAR',
|
||||||
|
'RON', 'RSD', 'RUB', 'RWF', 'SAR', 'SBD', 'SCR', 'SDG', 'SEK', 'SGD', 'SHP', 'SLE',
|
||||||
|
'SOS', 'SRD', 'SSP', 'STN', 'SVC', 'SYP', 'SZL', 'THB', 'TJS', 'TMT', 'TND', 'TOP',
|
||||||
|
'TRY', 'TTD', 'TWD', 'TZS', 'UAH', 'UGX', 'USD', 'UYU', 'UZS', 'VES', 'VND', 'VUV',
|
||||||
|
'WST', 'XAF', 'XCD', 'XCG', 'XOF', 'XPF', 'YER', 'ZAR', 'ZMW', 'ZWG',
|
||||||
|
];
|
||||||
|
|
||||||
|
const ACTIVE = new Set(ACTIVE_CURRENCIES);
|
||||||
|
|
||||||
|
export function isActiveCurrency(code: string): boolean {
|
||||||
|
return ACTIVE.has(code);
|
||||||
|
}
|
||||||
|
|
@ -6,3 +6,4 @@ export * from './settle.ts';
|
||||||
export * from './recurring.ts';
|
export * from './recurring.ts';
|
||||||
export * from './stats.ts';
|
export * from './stats.ts';
|
||||||
export * from './csv.ts';
|
export * from './csv.ts';
|
||||||
|
export * from './currencies.ts';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { ACTIVE_CURRENCIES, isActiveCurrency } from '../src/index.ts';
|
||||||
import {
|
import {
|
||||||
allocate, balances, convert, dueOccurrences, expensesCsv, inBase, logOrder, nthOccurrence,
|
allocate, balances, convert, dueOccurrences, expensesCsv, inBase, logOrder, nthOccurrence,
|
||||||
occurrenceId, parseAmount, rateToString, replay, settleUp, toDecimalString, computeStats,
|
occurrenceId, parseAmount, rateToString, replay, settleUp, toDecimalString, computeStats,
|
||||||
|
|
@ -230,3 +231,13 @@ describe('stats and csv', () => {
|
||||||
expect(expensesCsv(state)).toContain(`"'=HYPERLINK(""x"")"`);
|
expect(expensesCsv(state)).toContain(`"'=HYPERLINK(""x"")"`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ACTIVE_CURRENCIES', () => {
|
||||||
|
it('is sorted, unique ISO codes without replaced currencies', () => {
|
||||||
|
expect([...ACTIVE_CURRENCIES].sort()).toEqual(ACTIVE_CURRENCIES);
|
||||||
|
expect(new Set(ACTIVE_CURRENCIES).size).toBe(ACTIVE_CURRENCIES.length);
|
||||||
|
expect(ACTIVE_CURRENCIES.every((c) => /^[A-Z]{3}$/.test(c))).toBe(true);
|
||||||
|
for (const gone of ['ANG', 'BGN', 'CUC', 'HRK', 'SLL', 'ZWL', 'DEM', 'XDR']) expect(isActiveCurrency(gone)).toBe(false);
|
||||||
|
for (const c of ['ALL', 'CZK', 'EUR', 'XCG', 'ZWG']) expect(isActiveCurrency(c)).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue