@scaleway/use-i18n
Version:
A small hook to handle i18n
40 lines (39 loc) • 1.44 kB
TypeScript
declare const exponents: {
name: string;
symbol: string;
}[];
type Exponent = (typeof exponents)[number];
type ExponentName = '' | 'kilo' | 'mega' | 'giga' | 'tera' | 'peta' | 'exa' | 'zetta' | 'yotta';
type Unit = 'bit' | 'byte';
type CompoundUnit = 'second';
declare const format: ({ compoundUnit, exponent, unit, humanize, }: {
compoundUnit?: CompoundUnit;
unit: Unit;
exponent?: Exponent;
humanize?: boolean;
}) => (locale: string, amount: number, { maximumFractionDigits, minimumFractionDigits, short, base, }: {
maximumFractionDigits?: number;
minimumFractionDigits?: number;
short?: boolean;
base?: 2 | 10;
}) => string;
type SimpleUnits = `${ExponentName}${Unit}${'-humanized' | ''}`;
type ComplexUnits = `${Unit}${'s' | ''}${'-humanized' | ''}`;
type PerSecondUnit = `${ExponentName | ''}bit${'s' | ''}${'-per-second' | ''}${'-humanized' | ''}`;
type SupportedUnits = SimpleUnits | ComplexUnits | PerSecondUnit;
export declare const supportedUnits: Partial<Record<SupportedUnits, ReturnType<typeof format>>>;
export type FormatUnitOptions = {
unit: SupportedUnits;
/**
default: true
*/
short?: boolean;
maximumFractionDigits?: number;
minimumFractionDigits?: number;
/**
default: 10
*/
base?: 2 | 10;
};
declare const formatUnit: (locale: string, number: number, { unit, ...options }: FormatUnitOptions) => string;
export default formatUnit;