UNPKG

@ultraviolet/plus

Version:
38 lines (37 loc) 1.16 kB
"use client"; "use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const jsxRuntime = require("@emotion/react/jsx-runtime"); const react = require("react"); const en = require("./locales/en.cjs"); const EstimateCostContext = react.createContext({ locales: en, formatNumber: () => "" }); const useEstimateCost = () => react.useContext(EstimateCostContext); const EstimateCostProvider = ({ children, locales, currency, numberLocales }) => { const newLocales = react.useMemo(() => locales ? { ...en, ...locales } : en, [locales]); const formatNumber = react.useCallback((number, options) => { const numberFormat = new Intl.NumberFormat(numberLocales, { style: "currency", currency, ...options }); return numberFormat.format(number); }, [currency, numberLocales]); const value = react.useMemo(() => ({ locales: newLocales, formatNumber }), [formatNumber, newLocales]); return /* @__PURE__ */ jsxRuntime.jsx(EstimateCostContext.Provider, { value, children }); }; exports.EstimateCostProvider = EstimateCostProvider; exports.useEstimateCost = useEstimateCost;