@itwin/core-quantity 4.0.0-dev.48 → 4.0.0-dev.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Constants.d.ts +27 -27
- package/lib/cjs/Constants.js +52 -52
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Exception.d.ts +26 -26
- package/lib/cjs/Exception.js +38 -38
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Formatter/Format.d.ts +91 -91
- package/lib/cjs/Formatter/Format.js +328 -328
- package/lib/cjs/Formatter/Format.js.map +1 -1
- package/lib/cjs/Formatter/FormatEnums.d.ts +133 -133
- package/lib/cjs/Formatter/FormatEnums.js +318 -318
- package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
- package/lib/cjs/Formatter/Formatter.d.ts +44 -44
- package/lib/cjs/Formatter/Formatter.js +371 -371
- package/lib/cjs/Formatter/Formatter.js.map +1 -1
- package/lib/cjs/Formatter/FormatterSpec.d.ts +39 -39
- package/lib/cjs/Formatter/FormatterSpec.js +101 -101
- package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
- package/lib/cjs/Formatter/Interfaces.d.ts +62 -62
- package/lib/cjs/Formatter/Interfaces.js +17 -17
- package/lib/cjs/Formatter/Interfaces.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +86 -86
- package/lib/cjs/Interfaces.js +9 -9
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Parser.d.ts +93 -93
- package/lib/cjs/Parser.js +592 -592
- package/lib/cjs/Parser.js.map +1 -1
- package/lib/cjs/ParserSpec.d.ts +34 -34
- package/lib/cjs/ParserSpec.js +47 -47
- package/lib/cjs/ParserSpec.js.map +1 -1
- package/lib/cjs/Quantity.d.ts +27 -27
- package/lib/cjs/Quantity.js +46 -46
- package/lib/cjs/Quantity.js.map +1 -1
- package/lib/cjs/Unit.d.ts +25 -25
- package/lib/cjs/Unit.js +44 -44
- package/lib/cjs/Unit.js.map +1 -1
- package/lib/cjs/core-quantity.d.ts +19 -19
- package/lib/cjs/core-quantity.js +35 -35
- package/lib/cjs/core-quantity.js.map +1 -1
- package/lib/esm/Constants.d.ts +27 -27
- package/lib/esm/Constants.js +48 -48
- package/lib/esm/Constants.js.map +1 -1
- package/lib/esm/Exception.d.ts +26 -26
- package/lib/esm/Exception.js +34 -34
- package/lib/esm/Exception.js.map +1 -1
- package/lib/esm/Formatter/Format.d.ts +91 -91
- package/lib/esm/Formatter/Format.js +323 -323
- package/lib/esm/Formatter/Format.js.map +1 -1
- package/lib/esm/Formatter/FormatEnums.d.ts +133 -133
- package/lib/esm/Formatter/FormatEnums.js +302 -302
- package/lib/esm/Formatter/FormatEnums.js.map +1 -1
- package/lib/esm/Formatter/Formatter.d.ts +44 -44
- package/lib/esm/Formatter/Formatter.js +367 -367
- package/lib/esm/Formatter/Formatter.js.map +1 -1
- package/lib/esm/Formatter/FormatterSpec.d.ts +39 -39
- package/lib/esm/Formatter/FormatterSpec.js +97 -97
- package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
- package/lib/esm/Formatter/Interfaces.d.ts +62 -62
- package/lib/esm/Formatter/Interfaces.js +13 -13
- package/lib/esm/Formatter/Interfaces.js.map +1 -1
- package/lib/esm/Interfaces.d.ts +86 -86
- package/lib/esm/Interfaces.js +8 -8
- package/lib/esm/Interfaces.js.map +1 -1
- package/lib/esm/Parser.d.ts +93 -93
- package/lib/esm/Parser.js +588 -588
- package/lib/esm/Parser.js.map +1 -1
- package/lib/esm/ParserSpec.d.ts +34 -34
- package/lib/esm/ParserSpec.js +43 -43
- package/lib/esm/ParserSpec.js.map +1 -1
- package/lib/esm/Quantity.d.ts +27 -27
- package/lib/esm/Quantity.js +42 -42
- package/lib/esm/Quantity.js.map +1 -1
- package/lib/esm/Unit.d.ts +25 -25
- package/lib/esm/Unit.js +39 -39
- package/lib/esm/Unit.js.map +1 -1
- package/lib/esm/core-quantity.d.ts +19 -19
- package/lib/esm/core-quantity.js +23 -23
- package/lib/esm/core-quantity.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,303 +1,303 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Quantity
|
|
7
|
-
*/
|
|
8
|
-
import { QuantityError, QuantityStatus } from "../Exception";
|
|
9
|
-
/** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)
|
|
10
|
-
* provided in serialized formats as well as the full name of an [[OverrideFormat]].
|
|
11
|
-
*
|
|
12
|
-
* `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`
|
|
13
|
-
*
|
|
14
|
-
* Explanation of the regex:
|
|
15
|
-
* - ([\w.:]+)
|
|
16
|
-
* - Grabs the format full name
|
|
17
|
-
* - (\(([^\)]+)\))?
|
|
18
|
-
* - Grabs the precision part with and without the `()`.
|
|
19
|
-
* - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)
|
|
20
|
-
* - (\[([^\|\]]+)([\|])?([^\]]+)?\])?
|
|
21
|
-
* - 4 of these make up the rest of the regex, none of them are required so each end in `?`
|
|
22
|
-
* - Grabs the unit name and label including the `[]`
|
|
23
|
-
* - Grabs the unit name, `|` and label separately
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export const formatStringRgx = /([\w.:]+)(\(([^\)]+)\))?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?/;
|
|
27
|
-
/** @internal */
|
|
28
|
-
export function* getItemNamesFromFormatString(formatString) {
|
|
29
|
-
const match = formatString.split(formatStringRgx);
|
|
30
|
-
yield match[1]; // the Format Name
|
|
31
|
-
let index = 4;
|
|
32
|
-
while (index < match.length - 1) { // index 0 and 21 are empty strings
|
|
33
|
-
if (match[index] !== undefined)
|
|
34
|
-
yield match[index + 1]; // Unit Name
|
|
35
|
-
else
|
|
36
|
-
break;
|
|
37
|
-
index += 4;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
/** @beta */
|
|
41
|
-
export var FormatTraits;
|
|
42
|
-
(function (FormatTraits) {
|
|
43
|
-
FormatTraits[FormatTraits["Uninitialized"] = 0] = "Uninitialized";
|
|
44
|
-
/** Show trailing zeroes to requested precision. */
|
|
45
|
-
FormatTraits[FormatTraits["TrailZeroes"] = 1] = "TrailZeroes";
|
|
46
|
-
/** Indicates that the fractional part of the number is required when the fraction is zero */
|
|
47
|
-
FormatTraits[FormatTraits["KeepSingleZero"] = 2] = "KeepSingleZero";
|
|
48
|
-
/** Zero magnitude returns blank display value */
|
|
49
|
-
FormatTraits[FormatTraits["ZeroEmpty"] = 4] = "ZeroEmpty";
|
|
50
|
-
/** Show decimal point when value to right of decimal is empty */
|
|
51
|
-
FormatTraits[FormatTraits["KeepDecimalPoint"] = 8] = "KeepDecimalPoint";
|
|
52
|
-
/** Use the rounding factor. Not yet supported */
|
|
53
|
-
FormatTraits[FormatTraits["ApplyRounding"] = 16] = "ApplyRounding";
|
|
54
|
-
/** Show a dash between whole value and fractional value */
|
|
55
|
-
FormatTraits[FormatTraits["FractionDash"] = 32] = "FractionDash";
|
|
56
|
-
/** Append the quantity's unit label */
|
|
57
|
-
FormatTraits[FormatTraits["ShowUnitLabel"] = 64] = "ShowUnitLabel";
|
|
58
|
-
/** Prepend unit label. Not yet supported */
|
|
59
|
-
FormatTraits[FormatTraits["PrependUnitLabel"] = 128] = "PrependUnitLabel";
|
|
60
|
-
/** show a grouping in each group of 1000. */
|
|
61
|
-
FormatTraits[FormatTraits["Use1000Separator"] = 256] = "Use1000Separator";
|
|
62
|
-
/** Indicates that if an exponent value is positive to not include a `+`. By default a sign, `+` or `-`, is always shown. Not yet supported */
|
|
63
|
-
FormatTraits[FormatTraits["ExponentOnlyNegative"] = 512] = "ExponentOnlyNegative";
|
|
64
|
-
})(FormatTraits || (FormatTraits = {}));
|
|
65
|
-
/** Precision for Fractional formatted value types. Range from Whole (1/1) through 1/256.
|
|
66
|
-
* @beta */
|
|
67
|
-
export var FractionalPrecision;
|
|
68
|
-
(function (FractionalPrecision) {
|
|
69
|
-
FractionalPrecision[FractionalPrecision["One"] = 1] = "One";
|
|
70
|
-
FractionalPrecision[FractionalPrecision["Two"] = 2] = "Two";
|
|
71
|
-
FractionalPrecision[FractionalPrecision["Four"] = 4] = "Four";
|
|
72
|
-
FractionalPrecision[FractionalPrecision["Eight"] = 8] = "Eight";
|
|
73
|
-
FractionalPrecision[FractionalPrecision["Sixteen"] = 16] = "Sixteen";
|
|
74
|
-
FractionalPrecision[FractionalPrecision["ThirtyTwo"] = 32] = "ThirtyTwo";
|
|
75
|
-
FractionalPrecision[FractionalPrecision["SixtyFour"] = 64] = "SixtyFour";
|
|
76
|
-
FractionalPrecision[FractionalPrecision["OneHundredTwentyEight"] = 128] = "OneHundredTwentyEight";
|
|
77
|
-
FractionalPrecision[FractionalPrecision["TwoHundredFiftySix"] = 256] = "TwoHundredFiftySix";
|
|
78
|
-
})(FractionalPrecision || (FractionalPrecision = {}));
|
|
79
|
-
/** Precision for Decimal, Scientific, and Station formatted value types. Range from 1/(10^0) through 1/(10^12).
|
|
80
|
-
* @beta */
|
|
81
|
-
export var DecimalPrecision;
|
|
82
|
-
(function (DecimalPrecision) {
|
|
83
|
-
DecimalPrecision[DecimalPrecision["Zero"] = 0] = "Zero";
|
|
84
|
-
DecimalPrecision[DecimalPrecision["One"] = 1] = "One";
|
|
85
|
-
DecimalPrecision[DecimalPrecision["Two"] = 2] = "Two";
|
|
86
|
-
DecimalPrecision[DecimalPrecision["Three"] = 3] = "Three";
|
|
87
|
-
DecimalPrecision[DecimalPrecision["Four"] = 4] = "Four";
|
|
88
|
-
DecimalPrecision[DecimalPrecision["Five"] = 5] = "Five";
|
|
89
|
-
DecimalPrecision[DecimalPrecision["Six"] = 6] = "Six";
|
|
90
|
-
DecimalPrecision[DecimalPrecision["Seven"] = 7] = "Seven";
|
|
91
|
-
DecimalPrecision[DecimalPrecision["Eight"] = 8] = "Eight";
|
|
92
|
-
DecimalPrecision[DecimalPrecision["Nine"] = 9] = "Nine";
|
|
93
|
-
DecimalPrecision[DecimalPrecision["Ten"] = 10] = "Ten";
|
|
94
|
-
DecimalPrecision[DecimalPrecision["Eleven"] = 11] = "Eleven";
|
|
95
|
-
DecimalPrecision[DecimalPrecision["Twelve"] = 12] = "Twelve";
|
|
96
|
-
})(DecimalPrecision || (DecimalPrecision = {}));
|
|
97
|
-
/** Supported format types
|
|
98
|
-
* @beta */
|
|
99
|
-
export var FormatType;
|
|
100
|
-
(function (FormatType) {
|
|
101
|
-
/** Decimal display (ie 2.125) */
|
|
102
|
-
FormatType[FormatType["Decimal"] = 0] = "Decimal";
|
|
103
|
-
/** Fractional display (ie 2-1/8) */
|
|
104
|
-
FormatType[FormatType["Fractional"] = 1] = "Fractional";
|
|
105
|
-
/** Scientific Notation (ie 1.04e3) */
|
|
106
|
-
FormatType[FormatType["Scientific"] = 2] = "Scientific";
|
|
107
|
-
/** Civil Engineering Stationing (ie 1+00). */
|
|
108
|
-
FormatType[FormatType["Station"] = 3] = "Station";
|
|
109
|
-
})(FormatType || (FormatType = {}));
|
|
110
|
-
/** required if type is scientific
|
|
111
|
-
* @beta */
|
|
112
|
-
export var ScientificType;
|
|
113
|
-
(function (ScientificType) {
|
|
114
|
-
/** Non-zero value left of decimal point (ie 1.2345e3) */
|
|
115
|
-
ScientificType[ScientificType["Normalized"] = 0] = "Normalized";
|
|
116
|
-
/** Zero value left of decimal point (ie 0.12345e4) */
|
|
117
|
-
ScientificType[ScientificType["ZeroNormalized"] = 1] = "ZeroNormalized";
|
|
118
|
-
})(ScientificType || (ScientificType = {}));
|
|
119
|
-
/** Determines how the sign of values are displayed
|
|
120
|
-
* @beta */
|
|
121
|
-
export var ShowSignOption;
|
|
122
|
-
(function (ShowSignOption) {
|
|
123
|
-
/** Never show a sign even if the value is negative. */
|
|
124
|
-
ShowSignOption[ShowSignOption["NoSign"] = 0] = "NoSign";
|
|
125
|
-
/** Only show a sign when the value is negative. */
|
|
126
|
-
ShowSignOption[ShowSignOption["OnlyNegative"] = 1] = "OnlyNegative";
|
|
127
|
-
/** Always show a sign whether the value is positive or negative. */
|
|
128
|
-
ShowSignOption[ShowSignOption["SignAlways"] = 2] = "SignAlways";
|
|
129
|
-
/** Only show a sign when the value is negative but use parentheses instead of a negative sign. For example, -10 is formatted as `(10)`. */
|
|
130
|
-
ShowSignOption[ShowSignOption["NegativeParentheses"] = 3] = "NegativeParentheses";
|
|
131
|
-
})(ShowSignOption || (ShowSignOption = {}));
|
|
132
|
-
// parse and toString methods
|
|
133
|
-
/** @beta */
|
|
134
|
-
export function parseScientificType(scientificType, formatName) {
|
|
135
|
-
switch (scientificType.toLowerCase()) {
|
|
136
|
-
case "normalized": return ScientificType.Normalized;
|
|
137
|
-
case "zeronormalized": return ScientificType.ZeroNormalized;
|
|
138
|
-
default:
|
|
139
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'scientificType' attribute.`);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/** @beta */
|
|
143
|
-
export function scientificTypeToString(scientificType) {
|
|
144
|
-
return (scientificType === ScientificType.Normalized) ? "Normalized" : "ZeroNormalized";
|
|
145
|
-
}
|
|
146
|
-
/** @beta */
|
|
147
|
-
export function parseShowSignOption(showSignOption, formatName) {
|
|
148
|
-
switch (showSignOption.toLowerCase()) {
|
|
149
|
-
case "nosign": return ShowSignOption.NoSign;
|
|
150
|
-
case "onlynegative": return ShowSignOption.OnlyNegative;
|
|
151
|
-
case "signalways": return ShowSignOption.SignAlways;
|
|
152
|
-
case "negativeparentheses": return ShowSignOption.NegativeParentheses;
|
|
153
|
-
default:
|
|
154
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'showSignOption' attribute.`);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/** @beta */
|
|
158
|
-
export function showSignOptionToString(showSign) {
|
|
159
|
-
switch (showSign) {
|
|
160
|
-
case ShowSignOption.NegativeParentheses: return "NegativeParentheses";
|
|
161
|
-
case ShowSignOption.NoSign: return "NoSign";
|
|
162
|
-
case ShowSignOption.OnlyNegative: return "OnlyNegative";
|
|
163
|
-
case ShowSignOption.SignAlways: return "SignAlways";
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/** @beta */
|
|
167
|
-
export function parseFormatTrait(formatTraitsString, formatName) {
|
|
168
|
-
switch (formatTraitsString.toLowerCase()) {
|
|
169
|
-
case "trailzeroes": return FormatTraits.TrailZeroes;
|
|
170
|
-
case "keepsinglezero": return FormatTraits.KeepSingleZero;
|
|
171
|
-
case "zeroempty": return FormatTraits.ZeroEmpty;
|
|
172
|
-
case "keepdecimalpoint": return FormatTraits.KeepDecimalPoint;
|
|
173
|
-
case "applyrounding": return FormatTraits.ApplyRounding;
|
|
174
|
-
case "fractiondash": return FormatTraits.FractionDash;
|
|
175
|
-
case "showunitlabel": return FormatTraits.ShowUnitLabel;
|
|
176
|
-
case "prependunitlabel": return FormatTraits.PrependUnitLabel;
|
|
177
|
-
case "use1000separator": return FormatTraits.Use1000Separator;
|
|
178
|
-
case "exponentonlynegative": return FormatTraits.ExponentOnlyNegative;
|
|
179
|
-
default:
|
|
180
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'formatTraits' attribute.`);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/** @beta */
|
|
184
|
-
export function getTraitString(trait) {
|
|
185
|
-
switch (trait) {
|
|
186
|
-
case FormatTraits.TrailZeroes:
|
|
187
|
-
return "trailZeroes";
|
|
188
|
-
case FormatTraits.KeepSingleZero:
|
|
189
|
-
return "keepSingleZero";
|
|
190
|
-
case FormatTraits.ZeroEmpty:
|
|
191
|
-
return "zeroEmpty";
|
|
192
|
-
case FormatTraits.KeepDecimalPoint:
|
|
193
|
-
return "keepDecimalPoint";
|
|
194
|
-
case FormatTraits.ApplyRounding:
|
|
195
|
-
return "applyRounding";
|
|
196
|
-
case FormatTraits.FractionDash:
|
|
197
|
-
return "fractionDash";
|
|
198
|
-
case FormatTraits.ShowUnitLabel:
|
|
199
|
-
return "showUnitLabel";
|
|
200
|
-
case FormatTraits.PrependUnitLabel:
|
|
201
|
-
return "prependUnitLabel";
|
|
202
|
-
case FormatTraits.Use1000Separator:
|
|
203
|
-
return "use1000Separator";
|
|
204
|
-
case FormatTraits.ExponentOnlyNegative:
|
|
205
|
-
default:
|
|
206
|
-
return "exponentOnlyNegative";
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
/** @beta */
|
|
210
|
-
export function formatTraitsToArray(currentFormatTrait) {
|
|
211
|
-
const formatTraitsArr = Array();
|
|
212
|
-
if ((currentFormatTrait & FormatTraits.TrailZeroes) === FormatTraits.TrailZeroes)
|
|
213
|
-
formatTraitsArr.push("TrailZeroes");
|
|
214
|
-
if ((currentFormatTrait & FormatTraits.KeepSingleZero) === FormatTraits.KeepSingleZero)
|
|
215
|
-
formatTraitsArr.push("KeepSingleZero");
|
|
216
|
-
if ((currentFormatTrait & FormatTraits.ZeroEmpty) === FormatTraits.ZeroEmpty)
|
|
217
|
-
formatTraitsArr.push("ZeroEmpty");
|
|
218
|
-
if ((currentFormatTrait & FormatTraits.KeepDecimalPoint) === FormatTraits.KeepDecimalPoint)
|
|
219
|
-
formatTraitsArr.push("KeepDecimalPoint");
|
|
220
|
-
if ((currentFormatTrait & FormatTraits.ApplyRounding) === FormatTraits.ApplyRounding)
|
|
221
|
-
formatTraitsArr.push("ApplyRounding");
|
|
222
|
-
if ((currentFormatTrait & FormatTraits.FractionDash) === FormatTraits.FractionDash)
|
|
223
|
-
formatTraitsArr.push("FractionDash");
|
|
224
|
-
if ((currentFormatTrait & FormatTraits.ShowUnitLabel) === FormatTraits.ShowUnitLabel)
|
|
225
|
-
formatTraitsArr.push("ShowUnitLabel");
|
|
226
|
-
if ((currentFormatTrait & FormatTraits.PrependUnitLabel) === FormatTraits.PrependUnitLabel)
|
|
227
|
-
formatTraitsArr.push("PrependUnitLabel");
|
|
228
|
-
if ((currentFormatTrait & FormatTraits.Use1000Separator) === FormatTraits.Use1000Separator)
|
|
229
|
-
formatTraitsArr.push("Use1000Separator");
|
|
230
|
-
if ((currentFormatTrait & FormatTraits.ExponentOnlyNegative) === FormatTraits.ExponentOnlyNegative)
|
|
231
|
-
formatTraitsArr.push("ExponentOnlyNegative");
|
|
232
|
-
return formatTraitsArr;
|
|
233
|
-
}
|
|
234
|
-
/** @beta */
|
|
235
|
-
export function parseFormatType(jsonObjType, formatName) {
|
|
236
|
-
switch (jsonObjType.toLowerCase()) {
|
|
237
|
-
case "decimal": return FormatType.Decimal;
|
|
238
|
-
case "scientific": return FormatType.Scientific;
|
|
239
|
-
case "station": return FormatType.Station;
|
|
240
|
-
case "fractional": return FormatType.Fractional;
|
|
241
|
-
default:
|
|
242
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'type' attribute.`);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
/** @beta */
|
|
246
|
-
export function formatTypeToString(type) {
|
|
247
|
-
switch (type) {
|
|
248
|
-
case FormatType.Decimal: return "Decimal";
|
|
249
|
-
case FormatType.Scientific: return "Scientific";
|
|
250
|
-
case FormatType.Station: return "Station";
|
|
251
|
-
case FormatType.Fractional: return "Fractional";
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
/** @beta */
|
|
255
|
-
export function parseDecimalPrecision(jsonObjPrecision, formatName) {
|
|
256
|
-
switch (jsonObjPrecision) {
|
|
257
|
-
case 0: return DecimalPrecision.Zero;
|
|
258
|
-
case 1: return DecimalPrecision.One;
|
|
259
|
-
case 2: return DecimalPrecision.Two;
|
|
260
|
-
case 3: return DecimalPrecision.Three;
|
|
261
|
-
case 4: return DecimalPrecision.Four;
|
|
262
|
-
case 5: return DecimalPrecision.Five;
|
|
263
|
-
case 6: return DecimalPrecision.Six;
|
|
264
|
-
case 7: return DecimalPrecision.Seven;
|
|
265
|
-
case 8: return DecimalPrecision.Eight;
|
|
266
|
-
case 9: return DecimalPrecision.Nine;
|
|
267
|
-
case 10: return DecimalPrecision.Ten;
|
|
268
|
-
case 11: return DecimalPrecision.Eleven;
|
|
269
|
-
case 12: return DecimalPrecision.Twelve;
|
|
270
|
-
default:
|
|
271
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid FractionalPrecision */
|
|
275
|
-
export function parseFractionalPrecision(jsonObjPrecision, formatName) {
|
|
276
|
-
switch (jsonObjPrecision) {
|
|
277
|
-
case 1: return FractionalPrecision.One;
|
|
278
|
-
case 2: return FractionalPrecision.Two;
|
|
279
|
-
case 4: return FractionalPrecision.Four;
|
|
280
|
-
case 8: return FractionalPrecision.Eight;
|
|
281
|
-
case 16: return FractionalPrecision.Sixteen;
|
|
282
|
-
case 32: return FractionalPrecision.ThirtyTwo;
|
|
283
|
-
case 64: return FractionalPrecision.SixtyFour;
|
|
284
|
-
case 128: return FractionalPrecision.OneHundredTwentyEight;
|
|
285
|
-
case 256: return FractionalPrecision.TwoHundredFiftySix;
|
|
286
|
-
default:
|
|
287
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid DecimalPrecision or FractionalPrecision. */
|
|
291
|
-
export function parsePrecision(precision, type, formatName) {
|
|
292
|
-
switch (type) { // type must be decimal, fractional, scientific, or station
|
|
293
|
-
case FormatType.Decimal:
|
|
294
|
-
case FormatType.Scientific:
|
|
295
|
-
case FormatType.Station:
|
|
296
|
-
return parseDecimalPrecision(precision, formatName);
|
|
297
|
-
case FormatType.Fractional:
|
|
298
|
-
return parseFractionalPrecision(precision, formatName);
|
|
299
|
-
default:
|
|
300
|
-
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Quantity
|
|
7
|
+
*/
|
|
8
|
+
import { QuantityError, QuantityStatus } from "../Exception";
|
|
9
|
+
/** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)
|
|
10
|
+
* provided in serialized formats as well as the full name of an [[OverrideFormat]].
|
|
11
|
+
*
|
|
12
|
+
* `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`
|
|
13
|
+
*
|
|
14
|
+
* Explanation of the regex:
|
|
15
|
+
* - ([\w.:]+)
|
|
16
|
+
* - Grabs the format full name
|
|
17
|
+
* - (\(([^\)]+)\))?
|
|
18
|
+
* - Grabs the precision part with and without the `()`.
|
|
19
|
+
* - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)
|
|
20
|
+
* - (\[([^\|\]]+)([\|])?([^\]]+)?\])?
|
|
21
|
+
* - 4 of these make up the rest of the regex, none of them are required so each end in `?`
|
|
22
|
+
* - Grabs the unit name and label including the `[]`
|
|
23
|
+
* - Grabs the unit name, `|` and label separately
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
export const formatStringRgx = /([\w.:]+)(\(([^\)]+)\))?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?(\[([^\|\]]+)([\|])?([^\]]+)?\])?/;
|
|
27
|
+
/** @internal */
|
|
28
|
+
export function* getItemNamesFromFormatString(formatString) {
|
|
29
|
+
const match = formatString.split(formatStringRgx);
|
|
30
|
+
yield match[1]; // the Format Name
|
|
31
|
+
let index = 4;
|
|
32
|
+
while (index < match.length - 1) { // index 0 and 21 are empty strings
|
|
33
|
+
if (match[index] !== undefined)
|
|
34
|
+
yield match[index + 1]; // Unit Name
|
|
35
|
+
else
|
|
36
|
+
break;
|
|
37
|
+
index += 4;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** @beta */
|
|
41
|
+
export var FormatTraits;
|
|
42
|
+
(function (FormatTraits) {
|
|
43
|
+
FormatTraits[FormatTraits["Uninitialized"] = 0] = "Uninitialized";
|
|
44
|
+
/** Show trailing zeroes to requested precision. */
|
|
45
|
+
FormatTraits[FormatTraits["TrailZeroes"] = 1] = "TrailZeroes";
|
|
46
|
+
/** Indicates that the fractional part of the number is required when the fraction is zero */
|
|
47
|
+
FormatTraits[FormatTraits["KeepSingleZero"] = 2] = "KeepSingleZero";
|
|
48
|
+
/** Zero magnitude returns blank display value */
|
|
49
|
+
FormatTraits[FormatTraits["ZeroEmpty"] = 4] = "ZeroEmpty";
|
|
50
|
+
/** Show decimal point when value to right of decimal is empty */
|
|
51
|
+
FormatTraits[FormatTraits["KeepDecimalPoint"] = 8] = "KeepDecimalPoint";
|
|
52
|
+
/** Use the rounding factor. Not yet supported */
|
|
53
|
+
FormatTraits[FormatTraits["ApplyRounding"] = 16] = "ApplyRounding";
|
|
54
|
+
/** Show a dash between whole value and fractional value */
|
|
55
|
+
FormatTraits[FormatTraits["FractionDash"] = 32] = "FractionDash";
|
|
56
|
+
/** Append the quantity's unit label */
|
|
57
|
+
FormatTraits[FormatTraits["ShowUnitLabel"] = 64] = "ShowUnitLabel";
|
|
58
|
+
/** Prepend unit label. Not yet supported */
|
|
59
|
+
FormatTraits[FormatTraits["PrependUnitLabel"] = 128] = "PrependUnitLabel";
|
|
60
|
+
/** show a grouping in each group of 1000. */
|
|
61
|
+
FormatTraits[FormatTraits["Use1000Separator"] = 256] = "Use1000Separator";
|
|
62
|
+
/** Indicates that if an exponent value is positive to not include a `+`. By default a sign, `+` or `-`, is always shown. Not yet supported */
|
|
63
|
+
FormatTraits[FormatTraits["ExponentOnlyNegative"] = 512] = "ExponentOnlyNegative";
|
|
64
|
+
})(FormatTraits || (FormatTraits = {}));
|
|
65
|
+
/** Precision for Fractional formatted value types. Range from Whole (1/1) through 1/256.
|
|
66
|
+
* @beta */
|
|
67
|
+
export var FractionalPrecision;
|
|
68
|
+
(function (FractionalPrecision) {
|
|
69
|
+
FractionalPrecision[FractionalPrecision["One"] = 1] = "One";
|
|
70
|
+
FractionalPrecision[FractionalPrecision["Two"] = 2] = "Two";
|
|
71
|
+
FractionalPrecision[FractionalPrecision["Four"] = 4] = "Four";
|
|
72
|
+
FractionalPrecision[FractionalPrecision["Eight"] = 8] = "Eight";
|
|
73
|
+
FractionalPrecision[FractionalPrecision["Sixteen"] = 16] = "Sixteen";
|
|
74
|
+
FractionalPrecision[FractionalPrecision["ThirtyTwo"] = 32] = "ThirtyTwo";
|
|
75
|
+
FractionalPrecision[FractionalPrecision["SixtyFour"] = 64] = "SixtyFour";
|
|
76
|
+
FractionalPrecision[FractionalPrecision["OneHundredTwentyEight"] = 128] = "OneHundredTwentyEight";
|
|
77
|
+
FractionalPrecision[FractionalPrecision["TwoHundredFiftySix"] = 256] = "TwoHundredFiftySix";
|
|
78
|
+
})(FractionalPrecision || (FractionalPrecision = {}));
|
|
79
|
+
/** Precision for Decimal, Scientific, and Station formatted value types. Range from 1/(10^0) through 1/(10^12).
|
|
80
|
+
* @beta */
|
|
81
|
+
export var DecimalPrecision;
|
|
82
|
+
(function (DecimalPrecision) {
|
|
83
|
+
DecimalPrecision[DecimalPrecision["Zero"] = 0] = "Zero";
|
|
84
|
+
DecimalPrecision[DecimalPrecision["One"] = 1] = "One";
|
|
85
|
+
DecimalPrecision[DecimalPrecision["Two"] = 2] = "Two";
|
|
86
|
+
DecimalPrecision[DecimalPrecision["Three"] = 3] = "Three";
|
|
87
|
+
DecimalPrecision[DecimalPrecision["Four"] = 4] = "Four";
|
|
88
|
+
DecimalPrecision[DecimalPrecision["Five"] = 5] = "Five";
|
|
89
|
+
DecimalPrecision[DecimalPrecision["Six"] = 6] = "Six";
|
|
90
|
+
DecimalPrecision[DecimalPrecision["Seven"] = 7] = "Seven";
|
|
91
|
+
DecimalPrecision[DecimalPrecision["Eight"] = 8] = "Eight";
|
|
92
|
+
DecimalPrecision[DecimalPrecision["Nine"] = 9] = "Nine";
|
|
93
|
+
DecimalPrecision[DecimalPrecision["Ten"] = 10] = "Ten";
|
|
94
|
+
DecimalPrecision[DecimalPrecision["Eleven"] = 11] = "Eleven";
|
|
95
|
+
DecimalPrecision[DecimalPrecision["Twelve"] = 12] = "Twelve";
|
|
96
|
+
})(DecimalPrecision || (DecimalPrecision = {}));
|
|
97
|
+
/** Supported format types
|
|
98
|
+
* @beta */
|
|
99
|
+
export var FormatType;
|
|
100
|
+
(function (FormatType) {
|
|
101
|
+
/** Decimal display (ie 2.125) */
|
|
102
|
+
FormatType[FormatType["Decimal"] = 0] = "Decimal";
|
|
103
|
+
/** Fractional display (ie 2-1/8) */
|
|
104
|
+
FormatType[FormatType["Fractional"] = 1] = "Fractional";
|
|
105
|
+
/** Scientific Notation (ie 1.04e3) */
|
|
106
|
+
FormatType[FormatType["Scientific"] = 2] = "Scientific";
|
|
107
|
+
/** Civil Engineering Stationing (ie 1+00). */
|
|
108
|
+
FormatType[FormatType["Station"] = 3] = "Station";
|
|
109
|
+
})(FormatType || (FormatType = {}));
|
|
110
|
+
/** required if type is scientific
|
|
111
|
+
* @beta */
|
|
112
|
+
export var ScientificType;
|
|
113
|
+
(function (ScientificType) {
|
|
114
|
+
/** Non-zero value left of decimal point (ie 1.2345e3) */
|
|
115
|
+
ScientificType[ScientificType["Normalized"] = 0] = "Normalized";
|
|
116
|
+
/** Zero value left of decimal point (ie 0.12345e4) */
|
|
117
|
+
ScientificType[ScientificType["ZeroNormalized"] = 1] = "ZeroNormalized";
|
|
118
|
+
})(ScientificType || (ScientificType = {}));
|
|
119
|
+
/** Determines how the sign of values are displayed
|
|
120
|
+
* @beta */
|
|
121
|
+
export var ShowSignOption;
|
|
122
|
+
(function (ShowSignOption) {
|
|
123
|
+
/** Never show a sign even if the value is negative. */
|
|
124
|
+
ShowSignOption[ShowSignOption["NoSign"] = 0] = "NoSign";
|
|
125
|
+
/** Only show a sign when the value is negative. */
|
|
126
|
+
ShowSignOption[ShowSignOption["OnlyNegative"] = 1] = "OnlyNegative";
|
|
127
|
+
/** Always show a sign whether the value is positive or negative. */
|
|
128
|
+
ShowSignOption[ShowSignOption["SignAlways"] = 2] = "SignAlways";
|
|
129
|
+
/** Only show a sign when the value is negative but use parentheses instead of a negative sign. For example, -10 is formatted as `(10)`. */
|
|
130
|
+
ShowSignOption[ShowSignOption["NegativeParentheses"] = 3] = "NegativeParentheses";
|
|
131
|
+
})(ShowSignOption || (ShowSignOption = {}));
|
|
132
|
+
// parse and toString methods
|
|
133
|
+
/** @beta */
|
|
134
|
+
export function parseScientificType(scientificType, formatName) {
|
|
135
|
+
switch (scientificType.toLowerCase()) {
|
|
136
|
+
case "normalized": return ScientificType.Normalized;
|
|
137
|
+
case "zeronormalized": return ScientificType.ZeroNormalized;
|
|
138
|
+
default:
|
|
139
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'scientificType' attribute.`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** @beta */
|
|
143
|
+
export function scientificTypeToString(scientificType) {
|
|
144
|
+
return (scientificType === ScientificType.Normalized) ? "Normalized" : "ZeroNormalized";
|
|
145
|
+
}
|
|
146
|
+
/** @beta */
|
|
147
|
+
export function parseShowSignOption(showSignOption, formatName) {
|
|
148
|
+
switch (showSignOption.toLowerCase()) {
|
|
149
|
+
case "nosign": return ShowSignOption.NoSign;
|
|
150
|
+
case "onlynegative": return ShowSignOption.OnlyNegative;
|
|
151
|
+
case "signalways": return ShowSignOption.SignAlways;
|
|
152
|
+
case "negativeparentheses": return ShowSignOption.NegativeParentheses;
|
|
153
|
+
default:
|
|
154
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'showSignOption' attribute.`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/** @beta */
|
|
158
|
+
export function showSignOptionToString(showSign) {
|
|
159
|
+
switch (showSign) {
|
|
160
|
+
case ShowSignOption.NegativeParentheses: return "NegativeParentheses";
|
|
161
|
+
case ShowSignOption.NoSign: return "NoSign";
|
|
162
|
+
case ShowSignOption.OnlyNegative: return "OnlyNegative";
|
|
163
|
+
case ShowSignOption.SignAlways: return "SignAlways";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** @beta */
|
|
167
|
+
export function parseFormatTrait(formatTraitsString, formatName) {
|
|
168
|
+
switch (formatTraitsString.toLowerCase()) {
|
|
169
|
+
case "trailzeroes": return FormatTraits.TrailZeroes;
|
|
170
|
+
case "keepsinglezero": return FormatTraits.KeepSingleZero;
|
|
171
|
+
case "zeroempty": return FormatTraits.ZeroEmpty;
|
|
172
|
+
case "keepdecimalpoint": return FormatTraits.KeepDecimalPoint;
|
|
173
|
+
case "applyrounding": return FormatTraits.ApplyRounding;
|
|
174
|
+
case "fractiondash": return FormatTraits.FractionDash;
|
|
175
|
+
case "showunitlabel": return FormatTraits.ShowUnitLabel;
|
|
176
|
+
case "prependunitlabel": return FormatTraits.PrependUnitLabel;
|
|
177
|
+
case "use1000separator": return FormatTraits.Use1000Separator;
|
|
178
|
+
case "exponentonlynegative": return FormatTraits.ExponentOnlyNegative;
|
|
179
|
+
default:
|
|
180
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'formatTraits' attribute.`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** @beta */
|
|
184
|
+
export function getTraitString(trait) {
|
|
185
|
+
switch (trait) {
|
|
186
|
+
case FormatTraits.TrailZeroes:
|
|
187
|
+
return "trailZeroes";
|
|
188
|
+
case FormatTraits.KeepSingleZero:
|
|
189
|
+
return "keepSingleZero";
|
|
190
|
+
case FormatTraits.ZeroEmpty:
|
|
191
|
+
return "zeroEmpty";
|
|
192
|
+
case FormatTraits.KeepDecimalPoint:
|
|
193
|
+
return "keepDecimalPoint";
|
|
194
|
+
case FormatTraits.ApplyRounding:
|
|
195
|
+
return "applyRounding";
|
|
196
|
+
case FormatTraits.FractionDash:
|
|
197
|
+
return "fractionDash";
|
|
198
|
+
case FormatTraits.ShowUnitLabel:
|
|
199
|
+
return "showUnitLabel";
|
|
200
|
+
case FormatTraits.PrependUnitLabel:
|
|
201
|
+
return "prependUnitLabel";
|
|
202
|
+
case FormatTraits.Use1000Separator:
|
|
203
|
+
return "use1000Separator";
|
|
204
|
+
case FormatTraits.ExponentOnlyNegative:
|
|
205
|
+
default:
|
|
206
|
+
return "exponentOnlyNegative";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** @beta */
|
|
210
|
+
export function formatTraitsToArray(currentFormatTrait) {
|
|
211
|
+
const formatTraitsArr = Array();
|
|
212
|
+
if ((currentFormatTrait & FormatTraits.TrailZeroes) === FormatTraits.TrailZeroes)
|
|
213
|
+
formatTraitsArr.push("TrailZeroes");
|
|
214
|
+
if ((currentFormatTrait & FormatTraits.KeepSingleZero) === FormatTraits.KeepSingleZero)
|
|
215
|
+
formatTraitsArr.push("KeepSingleZero");
|
|
216
|
+
if ((currentFormatTrait & FormatTraits.ZeroEmpty) === FormatTraits.ZeroEmpty)
|
|
217
|
+
formatTraitsArr.push("ZeroEmpty");
|
|
218
|
+
if ((currentFormatTrait & FormatTraits.KeepDecimalPoint) === FormatTraits.KeepDecimalPoint)
|
|
219
|
+
formatTraitsArr.push("KeepDecimalPoint");
|
|
220
|
+
if ((currentFormatTrait & FormatTraits.ApplyRounding) === FormatTraits.ApplyRounding)
|
|
221
|
+
formatTraitsArr.push("ApplyRounding");
|
|
222
|
+
if ((currentFormatTrait & FormatTraits.FractionDash) === FormatTraits.FractionDash)
|
|
223
|
+
formatTraitsArr.push("FractionDash");
|
|
224
|
+
if ((currentFormatTrait & FormatTraits.ShowUnitLabel) === FormatTraits.ShowUnitLabel)
|
|
225
|
+
formatTraitsArr.push("ShowUnitLabel");
|
|
226
|
+
if ((currentFormatTrait & FormatTraits.PrependUnitLabel) === FormatTraits.PrependUnitLabel)
|
|
227
|
+
formatTraitsArr.push("PrependUnitLabel");
|
|
228
|
+
if ((currentFormatTrait & FormatTraits.Use1000Separator) === FormatTraits.Use1000Separator)
|
|
229
|
+
formatTraitsArr.push("Use1000Separator");
|
|
230
|
+
if ((currentFormatTrait & FormatTraits.ExponentOnlyNegative) === FormatTraits.ExponentOnlyNegative)
|
|
231
|
+
formatTraitsArr.push("ExponentOnlyNegative");
|
|
232
|
+
return formatTraitsArr;
|
|
233
|
+
}
|
|
234
|
+
/** @beta */
|
|
235
|
+
export function parseFormatType(jsonObjType, formatName) {
|
|
236
|
+
switch (jsonObjType.toLowerCase()) {
|
|
237
|
+
case "decimal": return FormatType.Decimal;
|
|
238
|
+
case "scientific": return FormatType.Scientific;
|
|
239
|
+
case "station": return FormatType.Station;
|
|
240
|
+
case "fractional": return FormatType.Fractional;
|
|
241
|
+
default:
|
|
242
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'type' attribute.`);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** @beta */
|
|
246
|
+
export function formatTypeToString(type) {
|
|
247
|
+
switch (type) {
|
|
248
|
+
case FormatType.Decimal: return "Decimal";
|
|
249
|
+
case FormatType.Scientific: return "Scientific";
|
|
250
|
+
case FormatType.Station: return "Station";
|
|
251
|
+
case FormatType.Fractional: return "Fractional";
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/** @beta */
|
|
255
|
+
export function parseDecimalPrecision(jsonObjPrecision, formatName) {
|
|
256
|
+
switch (jsonObjPrecision) {
|
|
257
|
+
case 0: return DecimalPrecision.Zero;
|
|
258
|
+
case 1: return DecimalPrecision.One;
|
|
259
|
+
case 2: return DecimalPrecision.Two;
|
|
260
|
+
case 3: return DecimalPrecision.Three;
|
|
261
|
+
case 4: return DecimalPrecision.Four;
|
|
262
|
+
case 5: return DecimalPrecision.Five;
|
|
263
|
+
case 6: return DecimalPrecision.Six;
|
|
264
|
+
case 7: return DecimalPrecision.Seven;
|
|
265
|
+
case 8: return DecimalPrecision.Eight;
|
|
266
|
+
case 9: return DecimalPrecision.Nine;
|
|
267
|
+
case 10: return DecimalPrecision.Ten;
|
|
268
|
+
case 11: return DecimalPrecision.Eleven;
|
|
269
|
+
case 12: return DecimalPrecision.Twelve;
|
|
270
|
+
default:
|
|
271
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid FractionalPrecision */
|
|
275
|
+
export function parseFractionalPrecision(jsonObjPrecision, formatName) {
|
|
276
|
+
switch (jsonObjPrecision) {
|
|
277
|
+
case 1: return FractionalPrecision.One;
|
|
278
|
+
case 2: return FractionalPrecision.Two;
|
|
279
|
+
case 4: return FractionalPrecision.Four;
|
|
280
|
+
case 8: return FractionalPrecision.Eight;
|
|
281
|
+
case 16: return FractionalPrecision.Sixteen;
|
|
282
|
+
case 32: return FractionalPrecision.ThirtyTwo;
|
|
283
|
+
case 64: return FractionalPrecision.SixtyFour;
|
|
284
|
+
case 128: return FractionalPrecision.OneHundredTwentyEight;
|
|
285
|
+
case 256: return FractionalPrecision.TwoHundredFiftySix;
|
|
286
|
+
default:
|
|
287
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid DecimalPrecision or FractionalPrecision. */
|
|
291
|
+
export function parsePrecision(precision, type, formatName) {
|
|
292
|
+
switch (type) { // type must be decimal, fractional, scientific, or station
|
|
293
|
+
case FormatType.Decimal:
|
|
294
|
+
case FormatType.Scientific:
|
|
295
|
+
case FormatType.Station:
|
|
296
|
+
return parseDecimalPrecision(precision, formatName);
|
|
297
|
+
case FormatType.Fractional:
|
|
298
|
+
return parseFractionalPrecision(precision, formatName);
|
|
299
|
+
default:
|
|
300
|
+
throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
303
|
//# sourceMappingURL=FormatEnums.js.map
|