All files / apps/huella-legal/layers/interest/app/composables useInterestRateOptions.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22        3x 42x   42x 42x   101x                      
import type { RadioGroupItem } from "@nuxt/ui";
import type { InterestRate } from "../types/InterestRate";
 
/** The radio items for the given rates, each preset labelled with its percentage. */
export const useInterestRateOptions = (rates: readonly InterestRate[]) => {
    const { t, locale } = useI18n();
 
    return computed<RadioGroupItem[]>(() => {
        const percent = new Intl.NumberFormat(locale.value, { maximumFractionDigits: 4 });
 
        return rates.map((value) => ({
            value,
            label:
                value === "custom"
                    ? t("interestCalculator.rate.options.custom")
                    : t(`interestCalculator.rate.options.${value}`, {
                          percent: percent.format(INTEREST_RATES[value]),
                      }),
        }));
    });
};