UNPKG

react-intlayer

Version:

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

1 lines 1.03 kB
{"version":3,"file":"useCompact.cjs","names":["IntlayerClientContext"],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["'use client';\n\nimport { compact } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,MAAa,mBAAmB;CAC9B,MAAM,EAAE,iCAAsBA,sDAAsB;AAEpD,gCACG,GAAG,qCACM,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,IAAI,UAAU;EAC5B,CAAC,EACJ,CAAC,OAAO,CACT"}