Offer only ISO 4217 currencies in circulation in the picker
Browsers' Intl.supportedValuesOf('currency') includes long-withdrawn codes
(ATS, DEM, ...). Use a hand-maintained ACTIVE_CURRENCIES list in core instead,
which also drops recently replaced ones (BGN, HRK, ANG, ZWL, SLL, CUC) and
non-cash units (XDR, XSU). A withdrawn currency already in use stays selectable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
This commit is contained in:
parent
1c691cd54f
commit
6b0c80bb50
4 changed files with 52 additions and 7 deletions
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 './stats.ts';
|
||||
export * from './csv.ts';
|
||||
export * from './currencies.ts';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import { ACTIVE_CURRENCIES, isActiveCurrency } from '../src/index.ts';
|
||||
import {
|
||||
allocate, balances, convert, dueOccurrences, expensesCsv, inBase, logOrder, nthOccurrence,
|
||||
occurrenceId, parseAmount, rateToString, replay, settleUp, toDecimalString, computeStats,
|
||||
|
|
@ -230,3 +231,13 @@ describe('stats and csv', () => {
|
|||
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