@itwin/presentation-common
Version:
Common pieces for iModel.js presentation packages
63 lines • 2.01 kB
TypeScript
/** @packageDocumentation
* @module Core
*/
import { FormatProps, FormatterSpec, ParserSpec, UnitSystemKey } from "@itwin/core-quantity";
import { SchemaContext } from "@itwin/ecschema-metadata";
/**
* A data structure that associates unit systems with property value formatting props. The associations are used for
* assigning formatting props for specific phenomenon and unit system combinations (see [[FormatsMap]]).
*
* @public
*/
export interface UnitSystemFormat {
unitSystems: UnitSystemKey[];
format: FormatProps;
}
/**
* A data structure that associates specific phenomenon with one or more formatting props for specific unit system.
*
* Example:
* ```json
* {
* length: [{
* unitSystems: ["metric"],
* format: formatForCentimeters,
* }, {
* unitSystems: ["imperial", "usCustomary"],
* format: formatForInches,
* }, {
* unitSystems: ["usSurvey"],
* format: formatForUsSurveyInches,
* }]
* }
* ```
*
* @public
*/
export interface FormatsMap {
[phenomenon: string]: UnitSystemFormat | UnitSystemFormat[];
}
/**
* Options for finding a formatter spec to use in [[KoqPropertyValueFormatter]].
* @public
*/
export interface FormatOptions {
/** Full name of the `KindOfQuantity`, e.g. `SchemaName:KoqName`. */
koqName: string;
/** Unit system to use for formatting. */
unitSystem?: UnitSystemKey;
}
/**
* An utility for formatting property values based on `KindOfQuantity` and unit system.
* @public
*/
export declare class KoqPropertyValueFormatter {
private _schemaContext;
private _unitsProvider;
private _defaultFormats?;
constructor(_schemaContext: SchemaContext, defaultFormats?: FormatsMap);
format(value: number, options: FormatOptions): Promise<string | undefined>;
getFormatterSpec(options: FormatOptions): Promise<FormatterSpec | undefined>;
getParserSpec(options: FormatOptions): Promise<ParserSpec | undefined>;
}
//# sourceMappingURL=KoqPropertyValueFormatter.d.ts.map