jewish-date
Version:
Converts Gregorian dates to Hebrew dates and vice versa.
58 lines (57 loc) • 2.31 kB
TypeScript
/**
* Copyright (c) Shmulik Kravitz.
*
* This source code is licensed under the MIT license.
* See the LICENSE file in the root directory for more information.
*
*/
/**
* Token definitions for pattern parsing.
* Order matters - longer tokens must come first to avoid partial matches.
*/
declare const TOKEN_PATTERNS: readonly ["yyyy", "YYYY", "yy", "YY", "MMMM", "MM", "M", "dd", "D", "d"];
type TokenType = (typeof TOKEN_PATTERNS)[number];
/**
* Represents the components needed for formatting a Jewish date.
*/
export interface FormatComponents {
day: number;
month: number;
monthName: string;
year: number;
}
/**
* Formatter function type that converts a component to its string representation.
*/
type TokenFormatter = (components: FormatComponents) => string;
/**
* Creates formatters for Hebrew output.
* Lowercase tokens (d, M, y) output numeric values.
* Uppercase tokens (D, YY, YYYY) output Hebrew gematria.
* MMMM outputs Hebrew month name.
* @param convertToHebrew - Function to convert numbers to Hebrew gematria
* @param getHebrewMonthName - Function to get Hebrew month name
* @param getShortYearHebrew - Function to get short (2-letter) Hebrew year
*/
export declare const createHebrewFormatters: (convertToHebrew: (num: number) => string, getHebrewMonthName: (monthName: string) => string, getShortYearHebrew: (year: number) => string) => Record<TokenType, TokenFormatter>;
/**
* Formats a Jewish date using the given pattern and formatters.
* @param pattern - The format pattern string (e.g., "d MMMM yyyy")
* @param components - The date components to format
* @param formatters - Token formatters to use
* @returns The formatted date string
*/
export declare const formatWithPattern: (pattern: string, components: FormatComponents, formatters: Record<TokenType, TokenFormatter>) => string;
/**
* Default pattern for formatting Jewish dates (numeric).
*/
export declare const DEFAULT_PATTERN = "d MMMM yyyy";
/**
* Default pattern for formatting Jewish dates in Hebrew (gematria).
*/
export declare const DEFAULT_PATTERN_HEBREW = "D MMMM YYYY";
/**
* Gets the English formatters (singleton).
*/
export declare const getEnglishFormatters: Record<"yyyy" | "YYYY" | "yy" | "YY" | "MMMM" | "MM" | "M" | "dd" | "D" | "d", TokenFormatter>;
export {};