Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected formatCurrencyImpl(renderer: NumberRenderer, params: NumberParams,
n: DecimalArg, code: CurrencyType, options: CurrencyFormatOptions): T {
// Not much to be done with NaN and Infinity with currencies, so we always
// throw an error.
const d = coerceDecimal(n);
validate(d, FORCE_ERRORS, renderer, params);
return this.numbers.formatCurrency(this.bundle, renderer, coerceDecimal(n), code, options, params);
}
format(bundle: Bundle, renderer: NumberRenderer, q: Quantity,
options: UnitFormatOptions, params: NumberParams): T {
const n = coerceDecimal(q.value);
const [num, plural] = this.internals.numbers.formatDecimal(bundle, renderer, n, options, params);
if (q.unit === undefined) {
return num;
}
// Compute plural category for the value '1'
const singular = bundle.plurals().cardinal(DecimalConstants.ONE);
// For default and "per" compound pattern, the {0} will use
// the plural category and {1} will be singular. Examples:
// 1 meter per second
// 10 meters per second
//
// For the 'times' compound pattern, the {0} will be singular,
// and the {1} will use the plural category. Examples:
// 1 newton-meter
protected formatDecimalImpl(renderer: NumberRenderer, params: NumberParams,
n: DecimalArg, options: DecimalFormatOptions): T {
// A NaN or Infinity value will just return the locale's representation
const d = coerceDecimal(n);
const v = validate(d, options, renderer, params);
if (v !== undefined) {
return v;
}
const [result] = this.numbers.formatDecimal(this.bundle, renderer, d, options, params);
return result;
}
protected formatCurrencyImpl(renderer: NumberRenderer, params: NumberParams,
n: DecimalArg, code: CurrencyType, options: CurrencyFormatOptions): T {
// Not much to be done with NaN and Infinity with currencies, so we always
// throw an error.
const d = coerceDecimal(n);
validate(d, FORCE_ERRORS, renderer, params);
return this.numbers.formatCurrency(this.bundle, renderer, coerceDecimal(n), code, options, params);
}
adjustDecimal(n: DecimalArg, opts?: DecimalAdjustOptions): Decimal {
return this.numbers.adjustDecimal(coerceDecimal(n), opts);
}
formatRelativeTimeField(bundle: Bundle, value: DecimalArg, field: RelativeTimeFieldType,
options: RelativeTimeFormatOptions, params: NumberParams,
transform: ContextTransformInfo): string {
const width = options.width || 'wide';
const format: RelativeTimeFields = this.relativeTimes[width] || this.relativeTimes.wide;
const group = options.group === undefined ? true : options.group;
let n = coerceDecimal(value);
n = this.internals.numbers.adjustDecimal(n, options);
const negative = n.isNegative();
if (negative) {
n = n.negate();
}
const iszero = n.compare(DecimalConstants.ZERO) === 0;
let res = '';
if (iszero) {
if (options.alwaysNow || !options.numericOnly) {
res = format.current.get(bundle, field);
}
} else if (!options.numericOnly) {
switch (field) {
getPluralOrdinal(n: DecimalArg, options?: DecimalAdjustOptions): string {
const d = options ? this.adjustDecimal(n, options) : coerceDecimal(n);
return this.bundle.plurals().ordinal(d);
}
getAvailablePattern(d: CalendarDate, s: DateSkeleton): DateTimeNode[] {
let plural: PluralType = 'other';
let pattern = s.pattern;
if (!pattern) {
switch (s.skeleton) {
case 'MMMMW': {
const week = coerceDecimal(d.weekOfMonth());
plural = this.bundle.plurals().cardinal(week) as PluralType;
pattern = this.rawPluralFormats[plural][s.skeleton];
break;
}
case 'yw': {
const week = coerceDecimal(d.weekOfYear());
plural = this.bundle.plurals().cardinal(week) as PluralType;
pattern = this.rawPluralFormats[plural][s.skeleton];
break;
}
default:
pattern = this.rawAvailableFormats[s.skeleton];
break;
}
}
return this.internals.calendars.parseDatePattern(pattern || '');
}