The price string to extract the currency symbol from
The currency symbol if found, undefined otherwise
getCurrencySymbol('$1000') // Returns '$'
getCurrencySymbol('1000€') // Returns '€'
getCurrencySymbol('£99.99') // Returns '£'
getCurrencySymbol('¥10000') // Returns '¥'
getCurrencySymbol('₹1500') // Returns '₹'
getCurrencySymbol('1000') // Returns undefined (no symbol)
export function getCurrencySymbol(price: string): CurrencySymbol {
const match = price.match(/\p{Sc}/u);
if (!match) return;
return match[0] satisfies CurrencySymbol;
}
Extracts the currency symbol from a price string. Uses Unicode property escapes to match currency symbols. Supports a wide range of international currency symbols.