/** * Sets up the file operation functions needed for the `i18n` / `locale-string-tables` support * This must be done prior to any use of the features of this module. * By default, file operations for a typical NodeJS environment are loaded. If this does not * fit your needs, you MUST call this setup function. * @param {FileOps} fileOps */ export declare function setFileOps(fileOps: FileOps): void; /** * Returns the currently loaded fileOps object * @return {FileOps} fileOps */ export declare function getFileOps(): FileOps; /** * Returns a string describing the availability and support for * W3C "Intl" library for DateTimeFormat. * * If availability is complete, and the function `useIntl(true)` is called (with `true`), * this library will be used for most of the localization aspects of the date/time formatting. * * Intl support may be necessary to support extended numbering systems or calendar options, or * to faithfully represent formats for certain locales. * * @returns {string} one of: * * - `complete` : the Intl library appears to support languages beyond the system locale * - `partial` : the Intl libary appears to support the system locale, but perhaps not others * - `none` : there is no Intl support available on this system. */ export declare function checkIntlSupport(): "none" | "complete" | "partial"; /** * Call with the option to utilize the W3C Intl library, if available. * * Use the `checkIntlSupport()` function to determine type of support available on this system. * * If set true, Intl.DateTimeFormat will be called where appropriate rather than using the formatting and localization * entirely through this library. * * Default is `false`: no use of Intl. * * @param use - pass `true` to enable Intl support, false to disable */ export declare function useIntl(use: any): void; /** * Returns the current setting of the `useIntl` choice * * @return {boolean} the choice currently in effect */ export declare function getUseIntlChoice(): boolean; /** * Object that holds the parsed results of the format specification * * - hints: a string array that holds each hint as specified by ?hint1-hint2-hint3-etc * - type: the named type of this format specification (and thus handler) * - format: the passed format string (after the |) * - locale: the passed locale (after the ~) */ export declare class SpecParts { hints: string[]; type: string; format: string; locale: string; } export interface FileOps { read(path: string): string; enumerate(relDir: string, callback: any): void; i18nPath: string; } /** * Base class that all constituent 'named' format handlers derive from. * Uts sole contract is the `format` function */ export interface IFormatHandler { /** * Formats the incoming value per this handler purpose * into a string, using the passed specs. * * @param specParts * @param value */ format(specParts: SpecParts, value: any): string; } /** * Attaches a format handler to the general Formatter choices * May be used to create a unique `IFormatHandler` instance as a new named type * @param type * @param handler * * @example * class MyFoobarFormatter extends IFormatHandler) { * format(specParts:SpecParts, value:any):string { * return 'FUBAR!' * } * } * registerFormatHandler('foobar', MyFoobarFormatter) */ export declare function registerFormatHandler(type: string, handler: IFormatHandler): void; /** * The primary export of the gen-format module: The `Formatter` operation (sometimes `F` as shorthand) * is represented by this function * * A _specifier string_ defines the type of format handler either by name (e.g. 'date') or by inference (i.e. numbers and strings) * as well as the format and any hints or locale. * * format type names are given first, followed by any locale or hint declarations, followed by a "|" character and * then the format. * * locales are preceded by a tilde character (~). Locales passed to date or number formatters may include * unicode extended values for calendar and numbering system if Intl support is available and enabled. * * hints are indicated by a ? character. If there are multiple hints, each is separated by a dash (-) character. * Hints vary according to the type of formatter used. Refer to the documentation for the specific formatter type. * * Refer to the examples elsewhere in the `gen-format` module documentation * for the types of specifier strings and values that can be passed. * * * @param {string} spec The format specifier string. * @param {any} value The value to be formatted * * @example * import F, {useIntl} from '@tremho/gen-format * useIntl(true) // assumes Intl is available. see `checkIntlSupport` * * console.log( F('date~zh-ZH-u-nu-hans-ca-chinese?Asia/Hong Kong|full', 'now') ) */ export default function formatFactory(spec: string, value: any): any; /** * Error thrown for a specified type that does not exist * * @param message * @constructor */ export declare function UnknownFormatType(message: string): { name: string; message: string; stack?: string; cause?: unknown; }; /** * Error thrown for the wrong type of value passed to a handler * * @param message * @constructor */ export declare function IncompatibleValueType(message: string): { name: string; message: string; stack?: string; cause?: unknown; }; /** * Error thrown for a syntax error in the format specifier * * @param message * @constructor */ export declare function BadFormatSpecifier(message: string): { name: string; message: string; stack?: string; cause?: unknown; }; /** * Use a format template string and passed arguments to create * a formatted output * * @param fmt The first parameter is a string that defines the format template * @param args Subsequent arguments represent the value sources that are represented * * @example * * import {formatV} from 'gen-format' * * formatV("Pi day, $(date|MMM DD} honors the value Pi which is $(1.2)", '2021-03-14Z', Math.PI) */ export declare function formatV(fmt: string, ...args: any[]): string;