UNPKG

react-intlayer

Version:

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

52 lines (49 loc) 1.49 kB
'use client'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../../_virtual/_rolldown/runtime.cjs'); const require_client_IntlayerProvider = require('../IntlayerProvider.cjs'); let react = require("react"); let _intlayer_core_formatters = require("@intlayer/core/formatters"); //#region src/client/format/useDate.ts /** * React client hook that provides a localized date/time formatter * bound to the current application locale. * * @returns {(date: Date | string | number, options?: DateProps) => string} * A function to format dates or timestamps into localized date/time strings. * * @example * ```tsx * const formatDate = useDate(); * * formatDate(new Date("2025-01-01")); * // "Jan 1, 2025" * * formatDate("2025-01-01T15:30:00Z", { * dateStyle: "full", * timeStyle: "short", * }); * // "Wednesday, January 1, 2025 at 3:30 PM" * * formatDate(1735689600000, { locale: "fr-FR", dateStyle: "long" }); * // "1 janvier 2025" * ``` * * @see createDate */ const useDate = () => { const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {}; return (...args) => { const options = typeof args[1] === "string" ? { ..._intlayer_core_formatters.presets[args[1]], locale } : { ...args[1], locale: args[1]?.locale ?? locale }; return (0, _intlayer_core_formatters.date)(args[0], options); }; }; //#endregion exports.useDate = useDate; //# sourceMappingURL=useDate.cjs.map