@formatjs/intl-pluralrules
Version:
Polyfill for Intl.PluralRules
60 lines (59 loc) • 2 kB
TypeScript
import type Decimal from "decimal.js";
/**
* CLDR Spec: Operands as defined in https://unicode.org/reports/tr35/tr35-numbers.html#Operands
* ECMA-402 Spec: GetOperands abstract operation (https://tc39.es/ecma402/#sec-getoperands)
*
* Maps CLDR operand symbols to JavaScript property names:
* - n → Number (absolute value)
* - i → IntegerDigits
* - v → NumberOfFractionDigits
* - w → NumberOfFractionDigitsWithoutTrailing
* - f → FractionDigits
* - t → FractionDigitsWithoutTrailing
* - c, e → CompactExponent (extension for compact notation)
*/
export interface OperandsRecord {
/**
* CLDR operand: n (absolute value of the source number)
*/
Number: Decimal;
/**
* CLDR operand: i (integer digits of n)
* Implementation: String for very large numbers exceeding Number.MAX_SAFE_INTEGER
*/
IntegerDigits: number | string;
/**
* CLDR operand: v (number of visible fraction digits in n, with trailing zeros)
*/
NumberOfFractionDigits: number;
/**
* CLDR operand: w (number of visible fraction digits in n, without trailing zeros)
*/
NumberOfFractionDigitsWithoutTrailing: number;
/**
* CLDR operand: f (visible fractional digits in n, with trailing zeros)
*/
FractionDigits: number;
/**
* CLDR operand: t (visible fractional digits in n, without trailing zeros)
*/
FractionDigitsWithoutTrailing: number;
/**
* CLDR operands: c and e (synonyms for compact decimal exponent)
*
* Extension: Not in base ECMA-402 spec, but defined in CLDR for compact notation.
* Example: "1.2M" has exponent 6 (since M = 10^6)
* Used by 9 locales: ca, es, fr, it, lld, pt, pt-PT, scn, vec
*/
CompactExponent: number;
}
/**
* ECMA-402 Spec: GetOperands abstract operation
* https://tc39.es/ecma402/#sec-getoperands
*
* Implementation: Extended to support compact exponent (c/e operands)
*
* @param s Formatted number string
* @param exponent Compact decimal exponent (c/e operand), defaults to 0
*/
export declare function GetOperands(s: string, exponent?: number): OperandsRecord;