@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
57 lines (56 loc) • 2.61 kB
TypeScript
/**
* Shared format plumbing used by the variant formatters
* (`formatNumber`, `formatPercent`, `formatCurrency`, etc.).
*/
import { ABSENT_VALUE_FORMAT, isAbsent } from './constants';
import { cleanNumber } from './cleanNumber';
import { formatDecimals } from './decimals';
import { formatNumberCore, prepareMinus, enhanceSR } from './formatNumberCore';
import { handleCompactBeforeDisplay, handleCompactBeforeAria } from './compact';
import type { NumberFormatType, NumberFormatValue, NumberFormatReturnValue, NumberFormatFunction, NumberFormatOptionParams, InternalNumberFormatOptions, FormattedParts } from './types';
/**
* Normalises locale (handles `null` + `auto`).
*/
export declare function resolveLocale(locale: string | null): string;
/**
* Parses the `options` argument (may be a JSON string) and mixes in
* `signDisplay` when provided.
*/
export declare function prepareFormatOptions({ options, signDisplay, }: {
options: string | InternalNumberFormatOptions | null;
signDisplay: NumberFormatOptionParams['signDisplay'] | null;
}): InternalNumberFormatOptions;
/**
* Marker value used when `value` was absent (null/undefined/empty).
*/
export { ABSENT_VALUE_FORMAT, isAbsent };
/**
* Builds a default return object that a variant formatter can extend.
*/
export declare function buildReturn({ value, locale, display, aria, type, opts, cleanCopyValue, invalidAriaText, }: {
value: NumberFormatValue;
locale: string;
display: string;
aria: string;
type: NumberFormatType;
opts: InternalNumberFormatOptions;
cleanCopyValue: boolean | null;
invalidAriaText: string | null;
}): NumberFormatReturnValue;
/**
* Applies the sensible `maximumFractionDigits` defaults and runs `formatDecimals`.
*/
export declare function applyDecimalsForPlain({ value, decimals, rounding, opts, }: {
value: NumberFormatValue;
decimals: number | string | null;
rounding: string | boolean | null | undefined;
opts: InternalNumberFormatOptions;
}): NumberFormatValue;
export { cleanNumber, formatDecimals, formatNumberCore, prepareMinus, enhanceSR, handleCompactBeforeDisplay, handleCompactBeforeAria, };
/**
* Creates a public variant formatter given a type tag and a raw
* `(number, locale) => { number, aria }` function. The returned function
* accepts `(value, options)` and returns either a formatted string or –
* when `returnAria: true` – the full `NumberFormatReturnValue` object.
*/
export declare function formatWith(type: NumberFormatType, formatterFn: (value: NumberFormatValue, locale: string) => FormattedParts): NumberFormatFunction;