react-intlayer
Version:
Easily internationalize i18n your React applications with type-safe multilingual content management.
1 lines • 1.48 kB
Source Map (JSON)
{"version":3,"sources":["../../../../src/server/format/useNumber.ts"],"sourcesContent":["import { type LocalesValues } from '@intlayer/config/client';\nimport { number } from '@intlayer/core';\nimport { IntlayerServerContext } from '../IntlayerServerProvider';\nimport { getServerContext } from '../serverContext';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const locale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"AACA,SAAS,cAAc;AACvB,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AAwB1B,MAAM,YAAY,MAAM;AAC7B,QAAM,SAAS,iBAAgC,qBAAqB;AAEpE,SAAO,IAAI,SACT,OAAO,KAAK,CAAC,GAAG;AAAA,IACd,GAAG,KAAK,CAAC;AAAA,IACT,QAAQ,KAAK,CAAC,GAAG,UAAU;AAAA,EAC7B,CAAC;AACL;","names":[]}