/** @preserve Copyright (c) KNOWLEDGECODE - MIT License */ type CompiledObject = string[]; interface DateLike { /** * Returns the year of the date. */ getFullYear(): number; /** * Returns the month of the date (0-11). */ getMonth(): number; /** * Returns the day of the month (1-31). */ getDate(): number; /** * Returns the hours of the date (0-23). */ getHours(): number; /** * Returns the minutes of the date (0-59). */ getMinutes(): number; /** * Returns the seconds of the date (0-59). */ getSeconds(): number; /** * Returns the milliseconds of the date (0-999). */ getMilliseconds(): number; /** * Returns the day of the week (0-6, where 0 is Sunday). */ getDay(): number; /** * Returns the time value in milliseconds since the Unix epoch (January 1, 1970). */ getTime(): number; /** * Returns the timezone offset in minutes from UTC. */ getTimezoneOffset(): number; } interface LocaleOptions { compiledObj: CompiledObject; style: 'long' | 'short' | 'narrow'; case?: 'uppercase' | 'lowercase'; } interface Locale { getLocale: () => string; getMonthList: (options: LocaleOptions) => string[]; getDayOfWeekList: (options: LocaleOptions) => string[]; getMeridiemList: (options: LocaleOptions) => string[]; } interface Numeral { encode: (str: string) => string; decode: (str: string) => string; } interface TimeZone { zone_name: string; gmt_offset: number[]; } interface FormatterPluginOptions { /** * The hour format to use for formatting. * This is used when the hour is in 12-hour format. * It can be 'h11' for 11-hour format or 'h12' for 12-hour format. */ hour12: 'h11' | 'h12'; /** * The hour format to use for formatting. * This is used when the hour is in 24-hour format. * It can be 'h23' for 23-hour format or 'h24' for 24-hour format. */ hour24: 'h23' | 'h24'; /** * The numeral system to use for formatting numbers. * This is an object that provides methods to encode and decode numbers in the specified numeral system. */ numeral: Numeral; /** * The calendar system to use for formatting dates. * This can be 'buddhist' for Buddhist calendar or 'gregory' for Gregorian calendar. */ calendar: 'buddhist' | 'gregory'; /** * The time zone to use for formatting dates and times. * This can be a specific time zone object, an IANA time zone name, or 'UTC' to use Coordinated Universal Time. * If not specified, it defaults to undefined, which means the local time zone will be used. */ timeZone: TimeZone | string | undefined; /** * The locale to use for formatting dates and times. * This is an object that provides methods to get localized month names, day names, and meridiems. */ locale: Locale; } type FormatterFunction = (d: DateLike, options: FormatterPluginOptions, compiledObj: CompiledObject) => string; /** * Base class for authoring formatter plugins by extending it with token methods. * @deprecated Prefer a plain object literal typed as `FormatterPluginObject`, which statically * rejects keys that collide with built-in tokens. This class is kept only to avoid a breaking * change for existing class-based plugins and will be removed in the next major version. */ declare abstract class FormatterPlugin { [key: string]: FormatterFunction | undefined; } type ReservedFormatterToken = 'YYYY' | 'YY' | 'Y' | 'MMMM' | 'MMM' | 'MM' | 'M' | 'DD' | 'D' | 'HH' | 'H' | 'AA' | 'A' | 'aa' | 'a' | 'hh' | 'h' | 'mm' | 'm' | 'ss' | 's' | 'SSS' | 'SS' | 'S' | 'dddd' | 'ddd' | 'dd' | 'Z' | 'ZZ'; /** * Type for authoring a formatter plugin as a plain object literal. Keys matching a token * already implemented by the built-in formatter are statically rejected, which prevents * accidentally shadowing a built-in token. */ type FormatterPluginObject = Partial> & Record; type ParserToken = 'Y' | 'M' | 'D' | 'H' | 'A' | 'h' | 'm' | 's' | 'S' | 'Z'; interface ParsedComponents { /** * Year component */ Y?: number; /** * Month component (1-12) */ M?: number; /** * Day component */ D?: number; /** * Hour in 24-hour format */ H?: number; /** * Meridiem indicator (0:AM / 1:PM) */ A?: number; /** * Hour in 12-hour format */ h?: number; /** * Minute component */ m?: number; /** * Second component */ s?: number; /** * Millisecond component */ S?: number; /** * Timezone offset in minutes */ Z?: number; } interface ParserPluginOptions { /** * The hour format to use for parsing. * This is used when the hour is in 12-hour format. * It can be 'h11' for 11-hour format or 'h12' for 12-hour format. */ hour12: 'h11' | 'h12'; /** * The hour format to use for parsing. * This is used when the hour is in 24-hour format. * It can be 'h23' for 23-hour format or 'h24' for 24-hour format. */ hour24: 'h23' | 'h24'; /** * The numeral system to use for parsing numbers. * This is an object that provides methods to encode and decode numbers in the specified numeral system. */ numeral: Numeral; /** * The calendar system to use for parsing dates. * This can be 'buddhist' for Buddhist calendar or 'gregory' for Gregorian calendar. */ calendar: 'buddhist' | 'gregory'; /** * Whether to ignore case when matching strings. * This is useful for matching month names, day names, and meridiems in a case-insensitive manner. * If true, the parser will convert both the input string and the strings in the locale to lowercase before matching. */ ignoreCase: boolean; /** * The time zone to use for parsing dates and times. * This can be a specific time zone object, an IANA time zone name, or 'UTC' to use Coordinated Universal Time. * If not specified, it defaults to undefined, which means the local time zone will be used. */ timeZone: TimeZone | string | undefined; /** * The locale to use for parsing dates and times. * This is an object that provides methods to get localized month names, day names, and meridiems. */ locale: Locale; /** * Default date components to use when certain components are missing from the input string. * This allows the parser to fill in missing components with default values, which can be useful for parsing partial date strings. * For example, if the input string only contains a month and day, the parser can use the default year from this object. */ defaultDate: ParsedComponents; } interface ParseResult { value: number; length: number; token?: ParserToken; } type ParserFunction = (str: string, options: ParserPluginOptions, compiledObj: CompiledObject) => ParseResult; /** * Base class for authoring parser plugins by extending it with token methods. * @deprecated Prefer a plain object literal typed as `ParserPluginObject`, which statically * rejects keys that collide with built-in tokens. This class is kept only to avoid a breaking * change for existing class-based plugins and will be removed in the next major version. */ declare abstract class ParserPlugin { [key: string]: ParserFunction | undefined; } /** * Executes a regular expression against a string and returns parsed result. * @param re - The regular expression to execute * @param str - The string to execute the regex against * @param [token] - Optional parser token to associate with the result * @returns ParseResult containing the numeric value, length, and token */ declare const exec: (re: RegExp, str: string, token?: ParserToken) => { value: number; length: number; token: ParserToken | undefined; }; /** * Finds the best matching string from an array based on length and string position. * @param array - Array of strings to search through * @param str - The string to match against * @param options - Parser plugin options * @param [token] - Optional parser token to associate with the result * @returns ParseResult with the index of the longest matching string at the start position */ declare const find: (array: string[], str: string, options: ParserPluginOptions, token?: ParserToken) => ParseResult; type ReservedParserToken = 'YYYY' | 'Y' | 'MMMM' | 'MMM' | 'MM' | 'M' | 'DD' | 'D' | 'HH' | 'H' | 'AA' | 'A' | 'aa' | 'a' | 'hh' | 'h' | 'mm' | 'm' | 'ss' | 's' | 'SSS' | 'SS' | 'S' | 'Z' | 'ZZ'; /** * Type for authoring a parser plugin as a plain object literal. Keys matching a token already * implemented by the built-in parser are statically rejected, which prevents accidentally * shadowing a built-in token. */ type ParserPluginObject = Partial> & Record; export { FormatterPlugin, ParserPlugin, exec, find }; export type { CompiledObject, DateLike, FormatterPluginObject, FormatterPluginOptions, Locale, Numeral, ParseResult, ParserPluginObject, ParserPluginOptions, TimeZone };