UNPKG

react-intlayer

Version:

Easily internationalize i18n your React applications with type-safe multilingual content management.

37 lines (34 loc) 1.27 kB
'use client'; const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_client_IntlayerProvider = require('../IntlayerProvider.cjs'); let react = require("react"); let _intlayer_core = require("@intlayer/core"); //#region src/client/format/usePercentage.ts /** * React hook to provide a percentage formatter function * based on the current application locale. * * This hook retrieves the active locale using {@link useLocaleBase} * and memoizes a `createPercentage` instance for that locale. * * @example * ```tsx * const formatPercentage = usePercentage(); * * const result = formatPercentage(0.875, { maximumFractionDigits: 1 }); * // "87.5%" (depending on locale) * ``` * * @returns {(value: string | number, options?: Omit<PercentageOptions, "value">) => string} * A function that formats numbers or numeric strings into localized percentages. */ const usePercentage = () => { const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext); return (0, react.useCallback)((...args) => (0, _intlayer_core.percentage)(args[0], { ...args[1], locale: args[1]?.locale ?? locale }), [locale]); }; //#endregion exports.usePercentage = usePercentage; //# sourceMappingURL=usePercentage.cjs.map