@nova-ui/bits
Version:
SolarWinds Nova Framework
95 lines (94 loc) • 4.74 kB
TypeScript
import { LoggerService } from "./log-service";
import { IUnitConversionResult } from "./public-api";
import { UnitOption } from "../constants/unit-conversion.constants";
import * as i0 from "@angular/core";
/**
* <example-url>./../examples/index.html#/common/unit-conversion-service</example-url>
*
* Service for converting a raw value to a larger unit approximation of the value--for example, 1024 B to 1 MB, 12345 Hz to 12.35 kHz, etc.
*/
export declare class UnitConversionService {
private logger;
constructor(logger: LoggerService);
/**
* Converts a raw value to a larger unit approximation of the value. For example, 1024 B to 1 KB, 12345 Hz to 12.35 kHz, etc.
*
* @param value The value to convert
* @param base The base to use for the exponential expression when calculating the conversion result
*
* @returns {{ [Key in keyof Pick<IUnitConversionResult, "value" | "order">]: number }} The value and order of conversion
*/
private convertLinear;
/**
* Converts a raw value to a larger unit approximation of the value. For example, 1100ms to 1.1s, 66000ms to 1.1m, etc.
*
* @param value The value to convert
* @param factors Array of factors to use for calculating smallest possible not zero result
*
* @returns {{ [Key in keyof Pick<IUnitConversionResult, "value" | "order">]: number }} The value and order of conversion
*/
private convertNonLinear;
/**
* Converts a raw value to a larger unit approximation of the value. For example, 1024 B to 1 KB, 12345 Hz to 12.35 kHz, 66000ms to 1.1m, etc.
*
* @param value The value to convert
* @param base The base or array of factors to use for calculating the conversion result
* @param scale The number of significant digits to the right of the decimal to include in the resulting converted value
*
* @returns {IUnitConversionResult} The conversion result
*/
convert(value: number, base?: number | number[], scale?: number): IUnitConversionResult;
/**
* Gets the display string of a conversion result
*
* @param conversion The result of an invocation of this service's convert method
* @param unit The unit used in the conversion
* @param plusSign Whether to prepend the display string with a '+'
* @param nanDisplay The string to display in case the conversion result is NaN or Infinity
*
* @returns {string} The display string of the conversion result
*/
getFullDisplay(conversion: IUnitConversionResult, unit: UnitOption, plusSign?: boolean, nanDisplay?: string): string;
/**
* Gets the converted value display string
*
* @param conversion The result of an invocation of this service's convert method
* @param plusSign Whether to prepend the display string with a '+'
* @param nanDisplay The string to display in case the conversion result is NaN or Infinity
* @param localize Whether to localize the value for display. Note: It's not recommended to localize values for
* the "generic" unit, e.g. "1.1K" for 1100, as the "generic" unit is currently not i18n friendly
*
* @returns {string} The converted value display string
*/
getValueDisplay(conversion: IUnitConversionResult, plusSign?: boolean, nanDisplay?: string, localize?: boolean): string;
/**
* Gets the converted unit display string
*
* @param conversion The result of an invocation of this service's convert method
* @param unit The basic unit used in the conversion
*
* @returns {string} The converted unit display string
*/
getUnitDisplay(conversion: IUnitConversionResult, unit: UnitOption): string;
/**
* Gets the base value of the converted unit
*
* @param unit The basic unit used in the conversion
*
* @returns {string} The abbreviation for the smallest unit of the provided UnitOption
*/
getUnitDisplayBaseValue(unit: UnitOption): string;
/**
* Gets the converted value display string in scientific notation
*
* @param conversion The result of an invocation of this service's convert method
* @param plusSign Whether to prepend the display string with a '+'
* @param nanDisplay The string to display in case the conversion result is NaN or Infinity
*
* @returns {string} The converted value display string in scientific notation
*/
getScientificDisplay(conversion: IUnitConversionResult, plusSign?: boolean, nanDisplay?: string): string;
private isValidNumber;
static ɵfac: i0.ɵɵFactoryDeclaration<UnitConversionService, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<UnitConversionService>;
}