tidy up project structure and normalize formatting
This commit is contained in:
@@ -15,10 +15,10 @@ export interface CurrencyOption {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// LOCALES — ~140 worldwide locale/region combinations
|
||||
// LOCALES - ~140 worldwide locale/region combinations
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const LOCALES: LocaleOption[] = [
|
||||
const _LOCALES_RAW: LocaleOption[] = [
|
||||
// System default
|
||||
{ code: 'system', name: 'System Default' },
|
||||
|
||||
@@ -234,11 +234,16 @@ export const LOCALES: LocaleOption[] = [
|
||||
{ code: 'fj-FJ', name: 'Fijian (Fiji)' },
|
||||
]
|
||||
|
||||
export const LOCALES: LocaleOption[] = [
|
||||
{ code: 'system', name: 'System Default' },
|
||||
..._LOCALES_RAW.filter(l => l.code !== 'system').sort((a, b) => a.name.localeCompare(b.name)),
|
||||
]
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// FALLBACK_CURRENCIES — ~120+ currencies with English names
|
||||
// FALLBACK_CURRENCIES - ~120+ currencies with English names
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export const FALLBACK_CURRENCIES: CurrencyOption[] = [
|
||||
const _FALLBACK_CURRENCIES_RAW: CurrencyOption[] = [
|
||||
{ code: 'USD', name: 'US Dollar' },
|
||||
{ code: 'EUR', name: 'Euro' },
|
||||
{ code: 'GBP', name: 'British Pound' },
|
||||
@@ -369,6 +374,9 @@ export const FALLBACK_CURRENCIES: CurrencyOption[] = [
|
||||
{ code: 'BND', name: 'Brunei Dollar' },
|
||||
]
|
||||
|
||||
export const FALLBACK_CURRENCIES: CurrencyOption[] =
|
||||
[..._FALLBACK_CURRENCIES_RAW].sort((a, b) => a.name.localeCompare(b.name))
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Currency builder (runtime Intl detection with fallback)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -383,7 +391,7 @@ function buildCurrencies(): CurrencyOption[] {
|
||||
return codes.map((code) => ({
|
||||
code,
|
||||
name: displayNames.of(code) ?? code,
|
||||
}))
|
||||
})).sort((a, b) => a.name.localeCompare(b.name))
|
||||
} catch {
|
||||
return FALLBACK_CURRENCIES
|
||||
}
|
||||
@@ -423,7 +431,7 @@ export function getCurrencyCode(): string {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Short date — e.g. "Jan 5, 2025"
|
||||
* Short date - e.g. "Jan 5, 2025"
|
||||
* Parses the date-part manually to avoid timezone-shift issues.
|
||||
*/
|
||||
export function formatDate(dateString: string): string {
|
||||
@@ -437,7 +445,7 @@ export function formatDate(dateString: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Long date — e.g. "Monday, January 5, 2025"
|
||||
* Long date - e.g. "Monday, January 5, 2025"
|
||||
*/
|
||||
export function formatDateLong(dateString: string): string {
|
||||
const [year, month, day] = dateString.substring(0, 10).split('-').map(Number)
|
||||
@@ -451,7 +459,7 @@ export function formatDateLong(dateString: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Short date + time — e.g. "Jan 5, 2025, 3:42 PM"
|
||||
* Short date + time - e.g. "Jan 5, 2025, 3:42 PM"
|
||||
*/
|
||||
export function formatDateTime(dateString: string): string {
|
||||
const date = new Date(dateString)
|
||||
@@ -465,7 +473,7 @@ export function formatDateTime(dateString: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Full currency format — e.g. "$1,234.56"
|
||||
* Full currency format - e.g. "$1,234.56"
|
||||
*/
|
||||
export function formatCurrency(amount: number): string {
|
||||
return new Intl.NumberFormat(getLocaleCode(), {
|
||||
@@ -485,7 +493,7 @@ export function formatCurrencyCompact(amount: number): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Number with locale grouping — e.g. "1,234.56"
|
||||
* Number with locale grouping - e.g. "1,234.56"
|
||||
*/
|
||||
export function formatNumber(amount: number, decimals?: number): string {
|
||||
return new Intl.NumberFormat(getLocaleCode(), {
|
||||
@@ -495,7 +503,7 @@ export function formatNumber(amount: number, decimals?: number): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract just the currency symbol — e.g. "$", "\u00a3", "\u20ac"
|
||||
* Extract just the currency symbol - e.g. "$", "\u00a3", "\u20ac"
|
||||
*/
|
||||
export function getCurrencySymbol(): string {
|
||||
const parts = new Intl.NumberFormat(getLocaleCode(), {
|
||||
|
||||
Reference in New Issue
Block a user