UNPKG

@thi.ng/date

Version:

Datetime types, relative dates, math, iterators, composable formatters, locales

107 lines 2.97 kB
import type { Fn0 } from "@thi.ng/api"; import type { Locale, LocaleSpec, LocaleUnit, Precision } from "./api.js"; /** * Sets {@link LOCALE} for formatting and fills in missing default values. * Unless called explicitly, the package uses {@link EN_SHORT} by default. * * @param locale - */ export declare const setLocale: (locale: LocaleSpec) => Locale; /** * Executes given `fn` with temporarily active `locale`. Returns result of `fn`. * * @remarks * `fn` will be called within a try/catch block and the previous locale will be * restored even if `fn` throws an error. * * @param locale - * @param fn - */ export declare const withLocale: <T>(locale: LocaleSpec, fn: Fn0<T>) => T; export declare let LOCALE: Locale; /** * Returns a copy of current {@link LOCALE}'s weekday names array. */ export declare const weekdayNames: () => string[]; /** * Returns a copy of current {@link LOCALE}'s month names array. */ export declare const monthNames: () => string[]; /** * Returns a suitable version of requested `unit` from current {@link LOCALE}, * based on quantity `x` and optional dativ grammar form. If `unitsOnly` is true * (default false) only the unit (w/o quantity) will be returned. * * @remarks * Also see {@link unitsLessThan}, {@link formatRelative}, * {@link formatRelativeParts}. * * @example * ```ts tangle:../export/units.ts * import { units, withLocale, FR_LONG, DE_LONG } from "@thi.ng/date"; * * console.log( * withLocale(FR_LONG, () => units(1, "y")) * ); * // "1 année" * * console.log( * withLocale(FR_LONG, () => units(1, "y", true)) * ); * // "1 an" * * console.log( * withLocale(FR_LONG, () => units(2, "y")) * ); * // "2 ans" * * console.log( * withLocale(FR_LONG, () => units(2, "y", true)) * ); * // "2 ans" * * console.log( * withLocale(DE_LONG, () => units(2, "y")) * ); * // "2 Jahre" * * console.log( * withLocale(DE_LONG, () => units(2, "y", true)) * ); * // "2 Jahren" * ``` * * @param x - * @param unit - * @param isDativ - * @param unitsOnly - */ export declare const units: (x: number, unit: Precision | LocaleUnit, isDativ?: boolean, unitsOnly?: boolean) => string; /** * Similar to {@link units}, but for cases to express/format the phrase `less * than {x} {unit(s)}`. * * @example * ```ts tangle:../export/units-less-than.ts * import { unitsLessThan, withLocale, DE_LONG } from "@thi.ng/date"; * * console.log( * withLocale(DE_LONG, () => unitsLessThan(1, "y")) * ); * // "weniger als 1 Jahr" * ``` * * @param x - * @param unit - * @param isDativ - */ export declare const unitsLessThan: (x: number, unit: Precision | LocaleUnit, isDativ?: boolean) => string; /** * Wraps given (presumably localized) string in current {@link LOCALE}'s `past` * or `future` phrases, depending on given `sign`. * * @param sign - * @param res - */ export declare const tense: (sign: number, res: string) => string; //# sourceMappingURL=i18n.d.ts.map