/ client / src / utils / settings.ts
settings.ts
 1  import { useGetSetting } from "./querySettings";
 2  
 3  export function useCurrency() {
 4    const { data: currency } = useGetSetting("currency");
 5    return JSON.parse(currency?.value ?? '"EUR"');
 6  }
 7  
 8  export function getCurrencySymbol(locale: string | undefined, currency: string) {
 9    return (0)
10      .toLocaleString(locale, {
11        style: "currency",
12        currency,
13        currencyDisplay: "narrowSymbol",
14        minimumFractionDigits: 0,
15        maximumFractionDigits: 0,
16      })
17      .replace(/\d/g, "")
18      .trim();
19  }
20  
21  export function useCurrencyFormatter() {
22    const currency = useCurrency();
23    const roundPrices = JSON.parse(useGetSetting("round_prices").data?.value ?? "false");
24  
25    return new Intl.NumberFormat(undefined, {
26      style: "currency",
27      currency: currency,
28      currencyDisplay: "narrowSymbol",
29      notation: roundPrices ? "compact" : "standard",
30    });
31  }