UNPKG

@cuppy/core

Version:

A lightweight currency display component with automatic inflation adjustment.

109 lines (95 loc) 3.63 kB
declare const cuppy: { (): void; options: { value?: number; from?: number; to?: number; hint: "none" | "from" | "to"; hintDisplay: "tooltip" | "inline"; locale?: string | string[]; currencyStyle?: "symbol" | "narrowSymbol" | "code" | "name"; useGrouping?: Intl.NumberFormatOptions["useGrouping"]; numberStyle?: "standard" | "scientific" | "engineering" | "compactShort" | "compactLong"; signDisplay?: Intl.NumberFormatOptions["signDisplay"]; yearDisplay: YearDisplay; hintYearDisplay: YearDisplay; inflationDataset: InflationDatasetAlias; yearFormatter: (value: string, year: number) => string; inlineHintFormatter: (value: string, hint: string) => string; } & { precisionMode: "sigfigs"; minDigits?: Intl.NumberFormatOptions["minimumSignificantDigits"]; maxDigits?: Intl.NumberFormatOptions["maximumSignificantDigits"]; }; datasets: Partial<Record<"cpiU", { data: Dataset; years: number[]; }>>; dataset: (plugin: DatasetPlugin) => void; formatCurrency: (value: number, options: Partial<CuppyOptions>) => string; adjustForInflation: (value: number, yearRange: { from: number; to?: number; } & { from?: number; to: number; }, dataset?: InflationDatasetAlias) => { adjustedValue: number; from: number; to: number; }; }; export default cuppy; export declare type CuppyOptions = { value?: number; from?: number; to?: number; hint: "none" | "from" | "to"; hintDisplay: "tooltip" | "inline"; locale?: string | string[]; currencyStyle?: "symbol" | "narrowSymbol" | "code" | "name"; useGrouping?: Intl.NumberFormatOptions["useGrouping"]; numberStyle?: "standard" | "scientific" | "engineering" | "compactShort" | "compactLong"; signDisplay?: Intl.NumberFormatOptions["signDisplay"]; yearDisplay: YearDisplay; hintYearDisplay: YearDisplay; inflationDataset: InflationDatasetAlias; yearFormatter: (value: string, year: number) => string; inlineHintFormatter: (value: string, hint: string) => string; } & PrecisionOptions; declare type Dataset = Record<DatasetYear, Record<DatasetPeriod, DatasetValue>>; declare type DatasetPeriod = `${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 0}`; declare type DatasetPlugin = (cuppy: { datasets: typeof datasets; }) => void; declare const datasets: Partial<Record<InflationDatasetAlias, { data: Dataset; years: number[]; }>>; declare type DatasetValue = number; declare type DatasetYear = string; export declare const getInflationData: (dataset: InflationDatasetAlias, from: number, to: number) => { from: { value: number; year: number; }; to: { value: number; year: number; }; }; export declare enum InflationDataset { cpiU = "CUUR0000SA0" } declare type InflationDatasetAlias = keyof typeof InflationDataset; declare type PrecisionOptions = { precisionMode: "decimalPlaces"; minDigits?: Intl.NumberFormatOptions["minimumFractionDigits"]; maxDigits?: Intl.NumberFormatOptions["maximumFractionDigits"]; } | { precisionMode: "sigfigs"; minDigits?: Intl.NumberFormatOptions["minimumSignificantDigits"]; maxDigits?: Intl.NumberFormatOptions["maximumSignificantDigits"]; }; declare type YearDisplay = "never" | "always" | "exceptCurrent" | "ifFallback"; export { }