@syncfusion/react-base
Version:
A common package of core React base, methods and class definitions
272 lines (271 loc) • 9.16 kB
TypeScript
/**
* Interface for DateFormatOptions
*/
export interface DateFormatOptions {
/**
* Specifies the skeleton for date formatting.
*/
skeleton?: string;
/**
* Specifies the type of date formatting either date, dateTime or time.
*/
type?: string;
/**
* Specifies custom date formatting to be used.
*/
format?: string;
/**
* Specifies the calendar mode other than gregorian
*/
calendar?: string;
/**
* Determines the locale of the date formatting.
*
* @private
*/
locale?: string;
}
/**
* Interface for numberFormatOptions
*/
export interface NumberFormatOptions {
/**
* Specifies minimum fraction digits in formatted value.
*/
minimumFractionDigits?: number;
/**
* Specifies maximum fraction digits in formatted value.
*/
maximumFractionDigits?: number;
/**
* Specifies minimum significant digits in formatted value.
*/
minimumSignificantDigits?: number;
/**
* Specifies maximum significant digits in formatted value.
*/
maximumSignificantDigits?: number;
/**
* Specifies whether to use grouping or not in formatted value,
*/
useGrouping?: boolean;
/**
* Specifies whether to ignore currency symbol in formatted value,
*/
ignoreCurrency?: boolean;
/**
* Specifies the skeleton for perform formatting.
*/
skeleton?: string;
/**
* Specifies the currency code to be used for formatting.
*
* @private
*/
currency?: string | null;
/**
* Specifies minimum integer digits in formatted value.
*/
minimumIntegerDigits?: number;
/**
* Specifies custom number format for formatting.
*/
format?: string;
/**
* Species which currency symbol to consider.
*/
altSymbol?: string;
/**
* Determines the locale of the number formatting.
*
* @private
*/
locale?: string;
}
/**
* Specifies the CLDR data loaded for internationalization functionalities.
*
* @private
*/
export declare const cldrData: Object;
/**
* Specifies the default culture value to be considered.
*
* @private
*/
export declare const defaultCulture: string;
/**
* Specifies default currency code to be considered
*
* @private
*/
export declare const defaultCurrencyCode: string;
/**
* Gets a date formatter function for specified culture and format options
*
* @param {DateFormatOptions} props - Date formatting options
* @returns {Function} Formatter function that accepts Date objects
*/
export declare function getDateFormat(props?: DateFormatOptions): Function;
/**
* Gets a number formatter function for specified culture and format options
*
* @param {NumberFormatOptions} props - Number formatting options
* @returns {Function} Formatter function that accepts numeric values
*/
export declare function getNumberFormat(props?: NumberFormatOptions): Function;
/**
* Returns the parser function for given props.
*
* @param {DateFormatOptions} props - Specifies the format props in which the parser function will return.
* @returns {Function} The date parser function.
*/
export declare function getDateParser(props?: DateFormatOptions): Function;
/**
* Returns the parser function for given props.
*
* @param {NumberFormatOptions} props - Specifies the format props in which the parser function will return.
* @returns {Function} The number parser function.
*/
export declare function getNumberParser(props?: NumberFormatOptions): Function;
/**
* Returns the formatted string based on format props.
*
* @param {number} value - Specifies the number to format.
* @param {NumberFormatOptions} option - Specifies the format props in which the number will be formatted.
* @returns {string} The formatted number string.
*/
export declare function formatNumber(value: number, option?: NumberFormatOptions): string;
/**
* Returns the formatted date string based on format props.
*
* @param {Date} value - Specifies the number to format.
* @param {DateFormatOptions} option - Specifies the format props in which the number will be formatted.
* @returns {string} The formatted date string.
*/
export declare function formatDate(value: Date, option?: DateFormatOptions): string;
/**
* Returns the date object for given date string and props.
*
* @param {string} value - Specifies the string to parse.
* @param {DateFormatOptions} option - Specifies the parse props in which the date string will be parsed.
* @returns {Date} The parsed Date object.
*/
export declare function parseDate(value: string, option?: DateFormatOptions): Date;
/**
* Returns the number object from the given string value and props.
*
* @param {string} value - Specifies the string to parse.
* @param {NumberFormatOptions} option - Specifies the parse props in which the string number will be parsed.
* @returns {number} The parsed number.
*/
export declare function parseNumber(value: string, option?: NumberFormatOptions): number;
/**
* Returns Native Date Time Pattern
*
* @param {DateFormatOptions} option - Specifies the parse props for resultant date time pattern.
* @param {boolean} isExcelFormat - Specifies format value to be converted to excel pattern.
* @returns {string} The native date time pattern.
* @private
*/
export declare function getDatePattern(option: DateFormatOptions, isExcelFormat?: boolean): string;
/**
* Returns Native Number Pattern
*
* @param {NumberFormatOptions} option - Specifies the parse props for resultant number pattern.
* @param {boolean} isExcel - Specifies whether to return Excel format.
* @returns {string} The native number pattern.
* @private
*/
export declare function getNumberPattern(option: NumberFormatOptions, isExcel?: boolean): string;
/**
* Returns the First Day of the Week
*
* @param {string} culture - The culture code (e.g. 'en-US').
* @returns {number} The first day of the week.
*/
export declare function getFirstDayOfWeek(culture: string): number;
/**
* Load the CLDR data into context
*
* @param {Object[]} data - Specifies the CLDR data's to be used for formatting and parser.
* @returns {void}
*/
export declare function loadCldr(...data: Object[]): void;
/**
* To get the numeric CLDR object for given culture
*
* @private
* @param {string} locale - Specifies the locale for which numericObject to be returned.
* @param {string} type - Specifies the type, by default it's decimal.
* @returns {Object} Returns the numeric CLDR object containing number formatting patterns and symbols
*/
export declare function getNumericObject(locale: string, type?: string): Object;
/**
* To get the numeric CLDR number base object for given culture
*
* @private
* @param {string} locale - Specifies the locale for which numericObject to be returned.
* @param {string} currency - Specifies the currency for which numericObject to be returned.
* @returns {string} Returns the currency symbol for the specified locale and currency
*/
export declare function getNumberDependable(locale: string, currency: string): string;
/**
* To get the default date CLDR object.
*
* @private
* @param {string} mode - Specify the mode, optional.
* @returns {Object} Returns the default date CLDR object containing date formatting patterns
*/
export declare function getDefaultDateObject(mode?: string): Object;
/**
* Describes metadata for a currency within CLDR currencyData.
* Keys like _tender, _from, and _to are string-encoded flags/dates.
*
*/
interface CldrCurrencyDetails {
_tender?: string;
_from?: string;
_to?: string;
}
/**
* A single currency entry mapping a currency code to its details.
*
*/
interface CldrCurrencyEntry {
[currencyCode: string]: CldrCurrencyDetails;
}
/**
* Minimal shape of the CLDR supplemental data required for currency and locale resolution.
*
* - likelySubtags helps derive full locales (and therefore regions) from partial tags.
* - currencyData.region maps a region code to an ordered list of currency entries with validity windows.
*
*/
interface CldrSupplemental {
supplemental: {
currencyData: {
region: Record<string, CldrCurrencyEntry[]>;
};
likelySubtags: Record<string, string>;
};
}
/**
* Returns the default currency code for a given locale using loaded CLDR data.
*
* @private
* @param {string} locale - The locale string used to determine the region.
* @returns {string | null} - The default currency code (e.g., 'USD', 'EUR') or null if not found.
*/
export declare function getLocaleCurrencyCode(locale: string): string | null;
/**
* Attempts to derive the region (territory) from a locale string.
*
* @private
* @param {string} locale - The locale string (e.g., 'en-US', 'fr_FR') from which to extract the region.
* @param {Object} [cldrData] - Optional CLDR data object containing supplemental likelySubtags.
* @returns {string | null} - The region code (e.g., 'US', 'FR') or null if it cannot be determined.
*
*/
export declare function getLocaleRegionCode(locale: string, cldrData: CldrSupplemental): string | null;
export {};