-
Notifications
You must be signed in to change notification settings - Fork 208
/
Interfaces.ts
99 lines (90 loc) · 3.61 KB
/
Interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Quantity
*/
/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.
* @beta
*/
export interface AlternateUnitLabelsProvider {
getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;
}
/** This interface provides basic information about a Unit that is return from a UnitProvider. This info
* uniquely identifies a unit by its name.
* @beta
*/
export interface UnitProps {
/** Unique name for unit. */
readonly name: string;
/** Default label for unit. */
readonly label: string;
/** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */
readonly phenomenon: string;
/** This is set to true if the Unit is known by the UnitsProvider. */
readonly isValid: boolean;
/** Unique system name. Example "Units.USCUSTOM"," Units.METRIC", "Units.USSURVEY", "Units.IMPERIAL" */
readonly system: string;
}
/** This interface defines the required properties of a Quantity.
* @beta
*/
export interface QuantityProps {
readonly magnitude: number;
readonly unit: UnitProps;
readonly isValid: boolean;
}
/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.
* @beta
*/
export interface UnitConversionSpec {
/** Unit name that was used to locate the unit by the Unit Provider */
name: string;
/** The default label that is used to display unit */
label: string;
/** Unit system name, used to when finding preferred parse unit */
system: string;
/** the information necessary to convert the unit to a specific display unit */
conversion: UnitConversionProps;
/** Labels that may be used to represent the unit in a string that is to be parsed. */
parseLabels?: string[];
}
/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet
* or from Celsius to Fahrenheit.
* @beta
*/
export interface UnitConversionProps {
factor: number;
offset: number;
}
/** Interface that defines potential parse units that may be found in user's string input of a quantity value.
* @beta
*/
export interface PotentialParseUnit {
unitName: string;
altLabels?: string[];
}
/**
* This interface defines extra properties to be associated with Units from Units Schema by name
* @alpha
*/
export interface UnitExtraData {
readonly name: string;
readonly altDisplayLabels: string[];
}
/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.
* The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.
* @beta
*/
export interface UnitsProvider {
findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;
findUnitByName(unitName: string): Promise<UnitProps>;
getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;
}
/**
* Used to uniquely identify a unit system.
* @beta
*/
export type UnitSystemKey = "metric" | "imperial" | "usCustomary" | "usSurvey";