@itwin/core-quantity 4.10.0-dev.8 → 5.0.0-dev.0

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/lib/cjs/Exception.d.ts +2 -1
  3. package/lib/cjs/Exception.d.ts.map +1 -1
  4. package/lib/cjs/Exception.js +1 -0
  5. package/lib/cjs/Exception.js.map +1 -1
  6. package/lib/cjs/Formatter/Format.d.ts +5 -2
  7. package/lib/cjs/Formatter/Format.d.ts.map +1 -1
  8. package/lib/cjs/Formatter/Format.js +20 -26
  9. package/lib/cjs/Formatter/Format.js.map +1 -1
  10. package/lib/cjs/Formatter/FormatEnums.d.ts +42 -16
  11. package/lib/cjs/Formatter/FormatEnums.d.ts.map +1 -1
  12. package/lib/cjs/Formatter/FormatEnums.js +73 -31
  13. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  14. package/lib/cjs/Formatter/Formatter.d.ts +1 -0
  15. package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
  16. package/lib/cjs/Formatter/Formatter.js +70 -24
  17. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  18. package/lib/cjs/Formatter/Interfaces.d.ts +2 -0
  19. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  20. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  21. package/lib/cjs/Interfaces.d.ts +13 -0
  22. package/lib/cjs/Interfaces.d.ts.map +1 -1
  23. package/lib/cjs/Interfaces.js +11 -0
  24. package/lib/cjs/Interfaces.js.map +1 -1
  25. package/lib/cjs/Parser.d.ts +2 -0
  26. package/lib/cjs/Parser.d.ts.map +1 -1
  27. package/lib/cjs/Parser.js +66 -18
  28. package/lib/cjs/Parser.js.map +1 -1
  29. package/lib/cjs/Quantity.d.ts +14 -0
  30. package/lib/cjs/Quantity.d.ts.map +1 -1
  31. package/lib/cjs/Quantity.js +41 -3
  32. package/lib/cjs/Quantity.js.map +1 -1
  33. package/lib/esm/Exception.d.ts +2 -1
  34. package/lib/esm/Exception.d.ts.map +1 -1
  35. package/lib/esm/Exception.js +1 -0
  36. package/lib/esm/Exception.js.map +1 -1
  37. package/lib/esm/Formatter/Format.d.ts +5 -2
  38. package/lib/esm/Formatter/Format.d.ts.map +1 -1
  39. package/lib/esm/Formatter/Format.js +21 -27
  40. package/lib/esm/Formatter/Format.js.map +1 -1
  41. package/lib/esm/Formatter/FormatEnums.d.ts +42 -16
  42. package/lib/esm/Formatter/FormatEnums.d.ts.map +1 -1
  43. package/lib/esm/Formatter/FormatEnums.js +58 -17
  44. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  45. package/lib/esm/Formatter/Formatter.d.ts +1 -0
  46. package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
  47. package/lib/esm/Formatter/Formatter.js +72 -26
  48. package/lib/esm/Formatter/Formatter.js.map +1 -1
  49. package/lib/esm/Formatter/Interfaces.d.ts +2 -0
  50. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  51. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  52. package/lib/esm/Interfaces.d.ts +13 -0
  53. package/lib/esm/Interfaces.d.ts.map +1 -1
  54. package/lib/esm/Interfaces.js +10 -1
  55. package/lib/esm/Interfaces.js.map +1 -1
  56. package/lib/esm/Parser.d.ts +2 -0
  57. package/lib/esm/Parser.d.ts.map +1 -1
  58. package/lib/esm/Parser.js +67 -19
  59. package/lib/esm/Parser.js.map +1 -1
  60. package/lib/esm/Quantity.d.ts +14 -0
  61. package/lib/esm/Quantity.d.ts.map +1 -1
  62. package/lib/esm/Quantity.js +37 -1
  63. package/lib/esm/Quantity.js.map +1 -1
  64. package/package.json +8 -8
@@ -7,7 +7,21 @@
7
7
  * @module Quantity
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.parsePrecision = exports.parseFractionalPrecision = exports.parseDecimalPrecision = exports.formatTypeToString = exports.parseFormatType = exports.formatTraitsToArray = exports.getTraitString = exports.parseFormatTrait = exports.showSignOptionToString = exports.parseShowSignOption = exports.scientificTypeToString = exports.parseScientificType = exports.ShowSignOption = exports.ScientificType = exports.FormatType = exports.DecimalPrecision = exports.FractionalPrecision = exports.FormatTraits = exports.getItemNamesFromFormatString = exports.formatStringRgx = void 0;
10
+ exports.ShowSignOption = exports.RatioType = exports.ScientificType = exports.FormatType = exports.DecimalPrecision = exports.FractionalPrecision = exports.FormatTraits = exports.formatStringRgx = void 0;
11
+ exports.getItemNamesFromFormatString = getItemNamesFromFormatString;
12
+ exports.scientificTypeToString = scientificTypeToString;
13
+ exports.parseScientificType = parseScientificType;
14
+ exports.parseRatioType = parseRatioType;
15
+ exports.parseShowSignOption = parseShowSignOption;
16
+ exports.showSignOptionToString = showSignOptionToString;
17
+ exports.parseFormatTrait = parseFormatTrait;
18
+ exports.getTraitString = getTraitString;
19
+ exports.formatTraitsToArray = formatTraitsToArray;
20
+ exports.parseFormatType = parseFormatType;
21
+ exports.formatTypeToString = formatTypeToString;
22
+ exports.parseDecimalPrecision = parseDecimalPrecision;
23
+ exports.parseFractionalPrecision = parseFractionalPrecision;
24
+ exports.parsePrecision = parsePrecision;
11
25
  const Exception_1 = require("../Exception");
12
26
  /** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)
13
27
  * provided in serialized formats as well as the full name of an [[OverrideFormat]].
@@ -40,7 +54,6 @@ function* getItemNamesFromFormatString(formatString) {
40
54
  index += 4;
41
55
  }
42
56
  }
43
- exports.getItemNamesFromFormatString = getItemNamesFromFormatString;
44
57
  /** @beta */
45
58
  var FormatTraits;
46
59
  (function (FormatTraits) {
@@ -103,42 +116,66 @@ var DecimalPrecision;
103
116
  var FormatType;
104
117
  (function (FormatType) {
105
118
  /** Decimal display (ie 2.125) */
106
- FormatType[FormatType["Decimal"] = 0] = "Decimal";
119
+ FormatType["Decimal"] = "Decimal";
107
120
  /** Fractional display (ie 2-1/8) */
108
- FormatType[FormatType["Fractional"] = 1] = "Fractional";
121
+ FormatType["Fractional"] = "Fractional";
109
122
  /** Scientific Notation (ie 1.04e3) */
110
- FormatType[FormatType["Scientific"] = 2] = "Scientific";
123
+ FormatType["Scientific"] = "Scientific";
111
124
  /** Civil Engineering Stationing (ie 1+00). */
112
- FormatType[FormatType["Station"] = 3] = "Station";
125
+ FormatType["Station"] = "Station";
113
126
  /** Bearing angle e.g. N05:00:00E. Requires provided quantities to be of the angle phenomenon */
114
- FormatType[FormatType["Bearing"] = 4] = "Bearing";
127
+ FormatType["Bearing"] = "Bearing";
115
128
  /** Azimuth angle e.g. 45°30'00". Requires provided quantities to be of the angle phenomenon */
116
- FormatType[FormatType["Azimuth"] = 5] = "Azimuth";
129
+ FormatType["Azimuth"] = "Azimuth";
130
+ /** Ratio display e,g. 1:2 or 0.3:1. */
131
+ FormatType["Ratio"] = "Ratio";
117
132
  })(FormatType || (exports.FormatType = FormatType = {}));
118
133
  /** required if type is scientific
119
134
  * @beta */
120
135
  var ScientificType;
121
136
  (function (ScientificType) {
122
137
  /** Non-zero value left of decimal point (ie 1.2345e3) */
123
- ScientificType[ScientificType["Normalized"] = 0] = "Normalized";
138
+ ScientificType["Normalized"] = "Normalized";
124
139
  /** Zero value left of decimal point (ie 0.12345e4) */
125
- ScientificType[ScientificType["ZeroNormalized"] = 1] = "ZeroNormalized";
140
+ ScientificType["ZeroNormalized"] = "ZeroNormalized";
126
141
  })(ScientificType || (exports.ScientificType = ScientificType = {}));
142
+ /** required if type is ratio
143
+ * @beta */
144
+ var RatioType;
145
+ (function (RatioType) {
146
+ /** One to N ratio (ie 1:N) */
147
+ RatioType["OneToN"] = "OneToN";
148
+ /** N to One ratio (ie N:1) */
149
+ RatioType["NToOne"] = "NToOne";
150
+ /** the lesser value scales to 1. e.g. input 0.5 turns into 2:1 | input 2 turns into 1:2 */
151
+ RatioType["ValueBased"] = "ValueBased";
152
+ /** scales the input ratio to its simplest integer form using the greatest common divisor (GCD) of the values. e.g. 0.3 turns into 3:10 */
153
+ RatioType["UseGreatestCommonDivisor"] = "UseGreatestCommonDivisor";
154
+ })(RatioType || (exports.RatioType = RatioType = {}));
127
155
  /** Determines how the sign of values are displayed
128
156
  * @beta */
129
157
  var ShowSignOption;
130
158
  (function (ShowSignOption) {
131
159
  /** Never show a sign even if the value is negative. */
132
- ShowSignOption[ShowSignOption["NoSign"] = 0] = "NoSign";
160
+ ShowSignOption["NoSign"] = "NoSign";
133
161
  /** Only show a sign when the value is negative. */
134
- ShowSignOption[ShowSignOption["OnlyNegative"] = 1] = "OnlyNegative";
162
+ ShowSignOption["OnlyNegative"] = "OnlyNegative";
135
163
  /** Always show a sign whether the value is positive or negative. */
136
- ShowSignOption[ShowSignOption["SignAlways"] = 2] = "SignAlways";
164
+ ShowSignOption["SignAlways"] = "SignAlways";
137
165
  /** Only show a sign when the value is negative but use parentheses instead of a negative sign. For example, -10 is formatted as `(10)`. */
138
- ShowSignOption[ShowSignOption["NegativeParentheses"] = 3] = "NegativeParentheses";
166
+ ShowSignOption["NegativeParentheses"] = "NegativeParentheses";
139
167
  })(ShowSignOption || (exports.ShowSignOption = ShowSignOption = {}));
140
168
  // parse and toString methods
141
- /** @beta */
169
+ /**
170
+ * @beta
171
+ * @deprecated in 4.10. ScientificType is now a string enum and doesn't need a serialization method. You can access the enum directly.
172
+ */
173
+ function scientificTypeToString(scientificType) {
174
+ return (scientificType === ScientificType.Normalized) ? "Normalized" : "ZeroNormalized";
175
+ }
176
+ /**
177
+ * @beta
178
+ */
142
179
  function parseScientificType(scientificType, formatName) {
143
180
  switch (scientificType.toLowerCase()) {
144
181
  case "normalized": return ScientificType.Normalized;
@@ -147,12 +184,19 @@ function parseScientificType(scientificType, formatName) {
147
184
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'scientificType' attribute.`);
148
185
  }
149
186
  }
150
- exports.parseScientificType = parseScientificType;
151
187
  /** @beta */
152
- function scientificTypeToString(scientificType) {
153
- return (scientificType === ScientificType.Normalized) ? "Normalized" : "ZeroNormalized";
188
+ function parseRatioType(ratioType, formatName) {
189
+ const normalizedValue = ratioType.toLowerCase();
190
+ for (const key in RatioType) {
191
+ if (RatioType.hasOwnProperty(key)) {
192
+ const enumValue = RatioType[key];
193
+ if (enumValue.toLowerCase() === normalizedValue) {
194
+ return enumValue;
195
+ }
196
+ }
197
+ }
198
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'ratioType' attribute.`);
154
199
  }
155
- exports.scientificTypeToString = scientificTypeToString;
156
200
  /** @beta */
157
201
  function parseShowSignOption(showSignOption, formatName) {
158
202
  switch (showSignOption.toLowerCase()) {
@@ -164,8 +208,10 @@ function parseShowSignOption(showSignOption, formatName) {
164
208
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'showSignOption' attribute.`);
165
209
  }
166
210
  }
167
- exports.parseShowSignOption = parseShowSignOption;
168
- /** @beta */
211
+ /**
212
+ * @beta
213
+ * @deprecated in 4.10. ShowSignOption is now a string enum and doesn't need a serialization method. You can access the enum directly.
214
+ */
169
215
  function showSignOptionToString(showSign) {
170
216
  switch (showSign) {
171
217
  case ShowSignOption.NegativeParentheses: return "NegativeParentheses";
@@ -174,7 +220,6 @@ function showSignOptionToString(showSign) {
174
220
  case ShowSignOption.SignAlways: return "SignAlways";
175
221
  }
176
222
  }
177
- exports.showSignOptionToString = showSignOptionToString;
178
223
  /** @beta */
179
224
  function parseFormatTrait(formatTraitsString, formatName) {
180
225
  switch (formatTraitsString.toLowerCase()) {
@@ -192,7 +237,6 @@ function parseFormatTrait(formatTraitsString, formatName) {
192
237
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'formatTraits' attribute.`);
193
238
  }
194
239
  }
195
- exports.parseFormatTrait = parseFormatTrait;
196
240
  /** @beta */
197
241
  function getTraitString(trait) {
198
242
  switch (trait) {
@@ -219,7 +263,6 @@ function getTraitString(trait) {
219
263
  return "exponentOnlyNegative";
220
264
  }
221
265
  }
222
- exports.getTraitString = getTraitString;
223
266
  /** @beta */
224
267
  function formatTraitsToArray(currentFormatTrait) {
225
268
  const formatTraitsArr = Array();
@@ -245,7 +288,6 @@ function formatTraitsToArray(currentFormatTrait) {
245
288
  formatTraitsArr.push("ExponentOnlyNegative");
246
289
  return formatTraitsArr;
247
290
  }
248
- exports.formatTraitsToArray = formatTraitsToArray;
249
291
  /** @beta */
250
292
  function parseFormatType(jsonObjType, formatName) {
251
293
  switch (jsonObjType.toLowerCase()) {
@@ -255,12 +297,14 @@ function parseFormatType(jsonObjType, formatName) {
255
297
  case "fractional": return FormatType.Fractional;
256
298
  case "bearing": return FormatType.Bearing;
257
299
  case "azimuth": return FormatType.Azimuth;
300
+ case "ratio": return FormatType.Ratio;
258
301
  default:
259
302
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'type' attribute.`);
260
303
  }
261
304
  }
262
- exports.parseFormatType = parseFormatType;
263
- /** @beta */
305
+ /** @beta
306
+ * @deprecated in 4.10. FormatType is now a string enum and doesn't need a serialization method. You can access the enum directly.
307
+ */
264
308
  function formatTypeToString(type) {
265
309
  switch (type) {
266
310
  case FormatType.Decimal: return "Decimal";
@@ -269,9 +313,9 @@ function formatTypeToString(type) {
269
313
  case FormatType.Fractional: return "Fractional";
270
314
  case FormatType.Bearing: return "Bearing";
271
315
  case FormatType.Azimuth: return "Azimuth";
316
+ case FormatType.Ratio: return "Ratio";
272
317
  }
273
318
  }
274
- exports.formatTypeToString = formatTypeToString;
275
319
  /** @beta */
276
320
  function parseDecimalPrecision(jsonObjPrecision, formatName) {
277
321
  switch (jsonObjPrecision) {
@@ -292,7 +336,6 @@ function parseDecimalPrecision(jsonObjPrecision, formatName) {
292
336
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
293
337
  }
294
338
  }
295
- exports.parseDecimalPrecision = parseDecimalPrecision;
296
339
  /** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid FractionalPrecision */
297
340
  function parseFractionalPrecision(jsonObjPrecision, formatName) {
298
341
  switch (jsonObjPrecision) {
@@ -309,13 +352,13 @@ function parseFractionalPrecision(jsonObjPrecision, formatName) {
309
352
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
310
353
  }
311
354
  }
312
- exports.parseFractionalPrecision = parseFractionalPrecision;
313
355
  /** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid DecimalPrecision or FractionalPrecision. */
314
356
  function parsePrecision(precision, type, formatName) {
315
357
  switch (type) { // type must be decimal, fractional, scientific, or station
316
358
  case FormatType.Decimal:
317
359
  case FormatType.Scientific:
318
360
  case FormatType.Station:
361
+ case FormatType.Ratio:
319
362
  case FormatType.Bearing:
320
363
  case FormatType.Azimuth:
321
364
  return parseDecimalPrecision(precision, formatName);
@@ -325,5 +368,4 @@ function parsePrecision(precision, type, formatName) {
325
368
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);
326
369
  }
327
370
  }
328
- exports.parsePrecision = parsePrecision;
329
371
  //# sourceMappingURL=FormatEnums.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FormatEnums.js","sourceRoot":"","sources":["../../../src/Formatter/FormatEnums.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,4CAA6D;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,eAAe,GAAG,8JAA8J,CAAC;AAE9L,gBAAgB;AAChB,QAAe,CAAC,CAAC,4BAA4B,CAAC,YAAoB;IAChE,MAAM,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,uBAAe,CAAC,CAAC;IAClD,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAk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AC;QACzD;YACE,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,WAAW,EAAE,cAAc,UAAU,wCAAwC,CAAC,CAAC;IAC1H,CAAC;AACH,CAAC;AAbD,wCAaC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityError, QuantityStatus } from \"../Exception\";\r\n\r\n/** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)\r\n * provided in serialized formats as well as the full name of an [[OverrideFormat]].\r\n *\r\n * `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`\r\n *\r\n * Explanation of the regex:\r\n * - ([\\w.:]+)\r\n * - Grabs the format full name\r\n * - (\\(([^\\)]+)\\))?\r\n * - Grabs the precision part with and without the `()`.\r\n * - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)\r\n * - (\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?\r\n * - 4 of these make up the rest of the regex, none of them are required so each end in `?`\r\n * - Grabs the unit name and label including the `[]`\r\n * - Grabs the unit name, `|` and label separately\r\n * @internal\r\n */\r\nexport const formatStringRgx = /([\\w.:]+)(\\(([^\\)]+)\\))?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?/;\r\n\r\n/** @internal */\r\nexport function* getItemNamesFromFormatString(formatString: string): Iterable<string> {\r\n const match = formatString.split(formatStringRgx);\r\n yield match[1]; // the Format Name\r\n let index = 4;\r\n while (index < match.length - 1) { // index 0 and 21 are empty strings\r\n if (match[index] !== undefined)\r\n yield match[index + 1]; // Unit Name\r\n else\r\n break;\r\n index += 4;\r\n }\r\n}\r\n/** @beta */\r\nexport enum FormatTraits {\r\n Uninitialized = 0,\r\n /** Show trailing zeroes to requested precision. */\r\n TrailZeroes = 1 << 0,\r\n /** Indicates that the fractional part of the number is required when the fraction is zero */\r\n KeepSingleZero = 1 << 1,\r\n /** Zero magnitude returns blank display value */\r\n ZeroEmpty = 1 << 2,\r\n /** Show decimal point when value to right of decimal is empty */\r\n KeepDecimalPoint = 1 << 3,\r\n /** Use the rounding factor. Not yet supported */\r\n ApplyRounding = 1 << 4,\r\n /** Show a dash between whole value and fractional value */\r\n FractionDash = 1 << 5,\r\n /** Append the quantity's unit label */\r\n ShowUnitLabel = 1 << 6,\r\n /** Prepend unit label. Not yet supported */\r\n PrependUnitLabel = 1 << 7,\r\n /** show a grouping in each group of 1000. */\r\n Use1000Separator = 1 << 8,\r\n /** Indicates that if an exponent value is positive to not include a `+`. By default a sign, `+` or `-`, is always shown. Not yet supported */\r\n ExponentOnlyNegative = 1 << 9,\r\n}\r\n\r\n/** Precision for Fractional formatted value types. Range from Whole (1/1) through 1/256.\r\n * @beta */\r\nexport enum FractionalPrecision {\r\n One = 1,\r\n Two = 2,\r\n Four = 4,\r\n Eight = 8,\r\n Sixteen = 16,\r\n ThirtyTwo = 32,\r\n SixtyFour = 64,\r\n OneHundredTwentyEight = 128,\r\n TwoHundredFiftySix = 256,\r\n}\r\n\r\n/** Precision for Decimal, Scientific, and Station formatted value types. Range from 1/(10^0) through 1/(10^12).\r\n * @beta */\r\nexport enum DecimalPrecision {\r\n Zero = 0,\r\n One = 1,\r\n Two = 2,\r\n Three = 3,\r\n Four = 4,\r\n Five = 5,\r\n Six = 6,\r\n Seven = 7,\r\n Eight = 8,\r\n Nine = 9,\r\n Ten = 10,\r\n Eleven = 11,\r\n Twelve = 12,\r\n}\r\n\r\n/** Supported format types\r\n * @beta */\r\nexport enum FormatType {\r\n /** Decimal display (ie 2.125) */\r\n Decimal,\r\n /** Fractional display (ie 2-1/8) */\r\n Fractional,\r\n /** Scientific Notation (ie 1.04e3) */\r\n Scientific,\r\n /** Civil Engineering Stationing (ie 1+00). */\r\n Station,\r\n /** Bearing angle e.g. N05:00:00E. Requires provided quantities to be of the angle phenomenon */\r\n Bearing,\r\n /** Azimuth angle e.g. 45°30'00\". Requires provided quantities to be of the angle phenomenon */\r\n Azimuth,\r\n}\r\n\r\n/** required if type is scientific\r\n * @beta */\r\nexport enum ScientificType {\r\n /** Non-zero value left of decimal point (ie 1.2345e3) */\r\n Normalized,\r\n /** Zero value left of decimal point (ie 0.12345e4) */\r\n ZeroNormalized,\r\n}\r\n\r\n/** Determines how the sign of values are displayed\r\n * @beta */\r\nexport enum ShowSignOption {\r\n /** Never show a sign even if the value is negative. */\r\n NoSign,\r\n /** Only show a sign when the value is negative. */\r\n OnlyNegative,\r\n /** Always show a sign whether the value is positive or negative. */\r\n SignAlways,\r\n /** Only show a sign when the value is negative but use parentheses instead of a negative sign. For example, -10 is formatted as `(10)`. */\r\n NegativeParentheses,\r\n}\r\n\r\n// parse and toString methods\r\n\r\n/** @beta */\r\n\r\nexport function parseScientificType(scientificType: string, formatName: string): ScientificType {\r\n switch (scientificType.toLowerCase()) {\r\n case \"normalized\": return ScientificType.Normalized;\r\n case \"zeronormalized\": return ScientificType.ZeroNormalized;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'scientificType' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function scientificTypeToString(scientificType: ScientificType): string {\r\n return (scientificType === ScientificType.Normalized) ? \"Normalized\" : \"ZeroNormalized\";\r\n}\r\n\r\n/** @beta */\r\nexport function parseShowSignOption(showSignOption: string, formatName: string): ShowSignOption {\r\n switch (showSignOption.toLowerCase()) {\r\n case \"nosign\": return ShowSignOption.NoSign;\r\n case \"onlynegative\": return ShowSignOption.OnlyNegative;\r\n case \"signalways\": return ShowSignOption.SignAlways;\r\n case \"negativeparentheses\": return ShowSignOption.NegativeParentheses;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'showSignOption' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function showSignOptionToString(showSign: ShowSignOption): string {\r\n switch (showSign) {\r\n case ShowSignOption.NegativeParentheses: return \"NegativeParentheses\";\r\n case ShowSignOption.NoSign: return \"NoSign\";\r\n case ShowSignOption.OnlyNegative: return \"OnlyNegative\";\r\n case ShowSignOption.SignAlways: return \"SignAlways\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function parseFormatTrait(formatTraitsString: string, formatName: string): FormatTraits {\r\n switch (formatTraitsString.toLowerCase()) {\r\n case \"trailzeroes\": return FormatTraits.TrailZeroes;\r\n case \"keepsinglezero\": return FormatTraits.KeepSingleZero;\r\n case \"zeroempty\": return FormatTraits.ZeroEmpty;\r\n case \"keepdecimalpoint\": return FormatTraits.KeepDecimalPoint;\r\n case \"applyrounding\": return FormatTraits.ApplyRounding;\r\n case \"fractiondash\": return FormatTraits.FractionDash;\r\n case \"showunitlabel\": return FormatTraits.ShowUnitLabel;\r\n case \"prependunitlabel\": return FormatTraits.PrependUnitLabel;\r\n case \"use1000separator\": return FormatTraits.Use1000Separator;\r\n case \"exponentonlynegative\": return FormatTraits.ExponentOnlyNegative;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'formatTraits' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function getTraitString(trait: FormatTraits) {\r\n switch (trait) {\r\n case FormatTraits.TrailZeroes:\r\n return \"trailZeroes\";\r\n case FormatTraits.KeepSingleZero:\r\n return \"keepSingleZero\";\r\n case FormatTraits.ZeroEmpty:\r\n return \"zeroEmpty\";\r\n case FormatTraits.KeepDecimalPoint:\r\n return \"keepDecimalPoint\";\r\n case FormatTraits.ApplyRounding:\r\n return \"applyRounding\";\r\n case FormatTraits.FractionDash:\r\n return \"fractionDash\";\r\n case FormatTraits.ShowUnitLabel:\r\n return \"showUnitLabel\";\r\n case FormatTraits.PrependUnitLabel:\r\n return \"prependUnitLabel\";\r\n case FormatTraits.Use1000Separator:\r\n return \"use1000Separator\";\r\n case FormatTraits.ExponentOnlyNegative:\r\n default:\r\n return \"exponentOnlyNegative\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function formatTraitsToArray(currentFormatTrait: FormatTraits): string[] {\r\n const formatTraitsArr = Array<string>();\r\n if ((currentFormatTrait & FormatTraits.TrailZeroes) === FormatTraits.TrailZeroes)\r\n formatTraitsArr.push(\"TrailZeroes\");\r\n if ((currentFormatTrait & FormatTraits.KeepSingleZero) === FormatTraits.KeepSingleZero)\r\n formatTraitsArr.push(\"KeepSingleZero\");\r\n if ((currentFormatTrait & FormatTraits.ZeroEmpty) === FormatTraits.ZeroEmpty)\r\n formatTraitsArr.push(\"ZeroEmpty\");\r\n if ((currentFormatTrait & FormatTraits.KeepDecimalPoint) === FormatTraits.KeepDecimalPoint)\r\n formatTraitsArr.push(\"KeepDecimalPoint\");\r\n if ((currentFormatTrait & FormatTraits.ApplyRounding) === FormatTraits.ApplyRounding)\r\n formatTraitsArr.push(\"ApplyRounding\");\r\n if ((currentFormatTrait & FormatTraits.FractionDash) === FormatTraits.FractionDash)\r\n formatTraitsArr.push(\"FractionDash\");\r\n if ((currentFormatTrait & FormatTraits.ShowUnitLabel) === FormatTraits.ShowUnitLabel)\r\n formatTraitsArr.push(\"ShowUnitLabel\");\r\n if ((currentFormatTrait & FormatTraits.PrependUnitLabel) === FormatTraits.PrependUnitLabel)\r\n formatTraitsArr.push(\"PrependUnitLabel\");\r\n if ((currentFormatTrait & FormatTraits.Use1000Separator) === FormatTraits.Use1000Separator)\r\n formatTraitsArr.push(\"Use1000Separator\");\r\n if ((currentFormatTrait & FormatTraits.ExponentOnlyNegative) === FormatTraits.ExponentOnlyNegative)\r\n formatTraitsArr.push(\"ExponentOnlyNegative\");\r\n return formatTraitsArr;\r\n}\r\n\r\n/** @beta */\r\nexport function parseFormatType(jsonObjType: string, formatName: string): FormatType {\r\n switch (jsonObjType.toLowerCase()) {\r\n case \"decimal\": return FormatType.Decimal;\r\n case \"scientific\": return FormatType.Scientific;\r\n case \"station\": return FormatType.Station;\r\n case \"fractional\": return FormatType.Fractional;\r\n case \"bearing\": return FormatType.Bearing;\r\n case \"azimuth\": return FormatType.Azimuth;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'type' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function formatTypeToString(type: FormatType): string {\r\n switch (type) {\r\n case FormatType.Decimal: return \"Decimal\";\r\n case FormatType.Scientific: return \"Scientific\";\r\n case FormatType.Station: return \"Station\";\r\n case FormatType.Fractional: return \"Fractional\";\r\n case FormatType.Bearing: return \"Bearing\";\r\n case FormatType.Azimuth: return \"Azimuth\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function parseDecimalPrecision(jsonObjPrecision: number, formatName: string): DecimalPrecision {\r\n switch (jsonObjPrecision) {\r\n case 0: return DecimalPrecision.Zero;\r\n case 1: return DecimalPrecision.One;\r\n case 2: return DecimalPrecision.Two;\r\n case 3: return DecimalPrecision.Three;\r\n case 4: return DecimalPrecision.Four;\r\n case 5: return DecimalPrecision.Five;\r\n case 6: return DecimalPrecision.Six;\r\n case 7: return DecimalPrecision.Seven;\r\n case 8: return DecimalPrecision.Eight;\r\n case 9: return DecimalPrecision.Nine;\r\n case 10: return DecimalPrecision.Ten;\r\n case 11: return DecimalPrecision.Eleven;\r\n case 12: return DecimalPrecision.Twelve;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid FractionalPrecision */\r\nexport function parseFractionalPrecision(jsonObjPrecision: number, formatName: string): FractionalPrecision {\r\n switch (jsonObjPrecision) {\r\n case 1: return FractionalPrecision.One;\r\n case 2: return FractionalPrecision.Two;\r\n case 4: return FractionalPrecision.Four;\r\n case 8: return FractionalPrecision.Eight;\r\n case 16: return FractionalPrecision.Sixteen;\r\n case 32: return FractionalPrecision.ThirtyTwo;\r\n case 64: return FractionalPrecision.SixtyFour;\r\n case 128: return FractionalPrecision.OneHundredTwentyEight;\r\n case 256: return FractionalPrecision.TwoHundredFiftySix;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid DecimalPrecision or FractionalPrecision. */\r\nexport function parsePrecision(precision: number, type: FormatType, formatName: string): DecimalPrecision | FractionalPrecision {\r\n switch (type) { // type must be decimal, fractional, scientific, or station\r\n case FormatType.Decimal:\r\n case FormatType.Scientific:\r\n case FormatType.Station:\r\n case FormatType.Bearing:\r\n case FormatType.Azimuth:\r\n return parseDecimalPrecision(precision, formatName);\r\n case FormatType.Fractional:\r\n return parseFractionalPrecision(precision, formatName);\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"FormatEnums.js","sourceRoot":"","sources":["../../../src/Formatter/FormatEnums.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAwBH,oEAWC;AAsHD,wDAEC;AAKD,kDAOC;AAGD,wCAWC;AAGD,kDASC;AAMD,wDAOC;AAGD,4CAeC;AAGD,wCAwBC;AAGD,kDAuBC;AAGD,0CAYC;AAKD,gDAUC;AAGD,sDAkBC;AAGD,4DAcC;AAGD,wCAcC;AAxWD,4CAA6D;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,eAAe,GAAG,8JAA8J,CAAC;AAE9L,gBAAgB;AAChB,QAAe,CAAC,CAAC,4BAA4B,CAAC,YAAoB;IAChE,MAAM,KAAK,GAAG,YAAY,CAAC,K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B,CAAC,OAAO,CAAC;QAC5C,KAAK,EAAE,CAAC,CAAC,OAAO,mBAAmB,CAAC,SAAS,CAAC;QAC9C,KAAK,EAAE,CAAC,CAAC,OAAO,mBAAmB,CAAC,SAAS,CAAC;QAC9C,KAAK,GAAG,CAAC,CAAC,OAAO,mBAAmB,CAAC,qBAAqB,CAAC;QAC3D,KAAK,GAAG,CAAC,CAAC,OAAO,mBAAmB,CAAC,kBAAkB,CAAC;QACxD;YACE,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,WAAW,EAAE,cAAc,UAAU,wCAAwC,CAAC,CAAC;IAC1H,CAAC;AACH,CAAC;AAED,iJAAiJ;AACjJ,SAAgB,cAAc,CAAC,SAAiB,EAAE,IAAgB,EAAE,UAAkB;IACpF,QAAQ,IAAI,EAAE,CAAC,CAAC,2DAA2D;QACzE,KAAK,UAAU,CAAC,OAAO,CAAC;QACxB,KAAK,UAAU,CAAC,UAAU,CAAC;QAC3B,KAAK,UAAU,CAAC,OAAO,CAAC;QACxB,KAAK,UAAU,CAAC,KAAK,CAAC;QACtB,KAAK,UAAU,CAAC,OAAO,CAAC;QACxB,KAAK,UAAU,CAAC,OAAO;YACrB,OAAO,qBAAqB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACtD,KAAK,UAAU,CAAC,UAAU;YACxB,OAAO,wBAAwB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACzD;YACE,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,WAAW,EAAE,cAAc,UAAU,wCAAwC,CAAC,CAAC;IAC1H,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityError, QuantityStatus } from \"../Exception\";\r\n\r\n/** The regular expression to parse [format strings]($docs/bis/ec/kindofquantity.md#format-string)\r\n * provided in serialized formats as well as the full name of an [[OverrideFormat]].\r\n *\r\n * `formatName(precision)[unitName|unitLabel][unitName|unitLabel][unitName|unitLabel][unitName|unitLabel]`\r\n *\r\n * Explanation of the regex:\r\n * - ([\\w.:]+)\r\n * - Grabs the format full name\r\n * - (\\(([^\\)]+)\\))?\r\n * - Grabs the precision part with and without the `()`.\r\n * - The parentheses are needed to validate the entire string. (TODO: Need to check if this is true)\r\n * - (\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?\r\n * - 4 of these make up the rest of the regex, none of them are required so each end in `?`\r\n * - Grabs the unit name and label including the `[]`\r\n * - Grabs the unit name, `|` and label separately\r\n * @internal\r\n */\r\nexport const formatStringRgx = /([\\w.:]+)(\\(([^\\)]+)\\))?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?(\\[([^\\|\\]]+)([\\|])?([^\\]]+)?\\])?/;\r\n\r\n/** @internal */\r\nexport function* getItemNamesFromFormatString(formatString: string): Iterable<string> {\r\n const match = formatString.split(formatStringRgx);\r\n yield match[1]; // the Format Name\r\n let index = 4;\r\n while (index < match.length - 1) { // index 0 and 21 are empty strings\r\n if (match[index] !== undefined)\r\n yield match[index + 1]; // Unit Name\r\n else\r\n break;\r\n index += 4;\r\n }\r\n}\r\n/** @beta */\r\nexport enum FormatTraits {\r\n Uninitialized = 0,\r\n /** Show trailing zeroes to requested precision. */\r\n TrailZeroes = 1 << 0,\r\n /** Indicates that the fractional part of the number is required when the fraction is zero */\r\n KeepSingleZero = 1 << 1,\r\n /** Zero magnitude returns blank display value */\r\n ZeroEmpty = 1 << 2,\r\n /** Show decimal point when value to right of decimal is empty */\r\n KeepDecimalPoint = 1 << 3,\r\n /** Use the rounding factor. Not yet supported */\r\n ApplyRounding = 1 << 4,\r\n /** Show a dash between whole value and fractional value */\r\n FractionDash = 1 << 5,\r\n /** Append the quantity's unit label */\r\n ShowUnitLabel = 1 << 6,\r\n /** Prepend unit label. Not yet supported */\r\n PrependUnitLabel = 1 << 7,\r\n /** show a grouping in each group of 1000. */\r\n Use1000Separator = 1 << 8,\r\n /** Indicates that if an exponent value is positive to not include a `+`. By default a sign, `+` or `-`, is always shown. Not yet supported */\r\n ExponentOnlyNegative = 1 << 9,\r\n}\r\n\r\n/** Precision for Fractional formatted value types. Range from Whole (1/1) through 1/256.\r\n * @beta */\r\nexport enum FractionalPrecision {\r\n One = 1,\r\n Two = 2,\r\n Four = 4,\r\n Eight = 8,\r\n Sixteen = 16,\r\n ThirtyTwo = 32,\r\n SixtyFour = 64,\r\n OneHundredTwentyEight = 128,\r\n TwoHundredFiftySix = 256,\r\n}\r\n\r\n/** Precision for Decimal, Scientific, and Station formatted value types. Range from 1/(10^0) through 1/(10^12).\r\n * @beta */\r\nexport enum DecimalPrecision {\r\n Zero = 0,\r\n One = 1,\r\n Two = 2,\r\n Three = 3,\r\n Four = 4,\r\n Five = 5,\r\n Six = 6,\r\n Seven = 7,\r\n Eight = 8,\r\n Nine = 9,\r\n Ten = 10,\r\n Eleven = 11,\r\n Twelve = 12,\r\n}\r\n\r\n/** Supported format types\r\n * @beta */\r\nexport enum FormatType {\r\n /** Decimal display (ie 2.125) */\r\n Decimal = \"Decimal\",\r\n /** Fractional display (ie 2-1/8) */\r\n Fractional = \"Fractional\",\r\n /** Scientific Notation (ie 1.04e3) */\r\n Scientific = \"Scientific\",\r\n /** Civil Engineering Stationing (ie 1+00). */\r\n Station = \"Station\",\r\n /** Bearing angle e.g. N05:00:00E. Requires provided quantities to be of the angle phenomenon */\r\n Bearing = \"Bearing\",\r\n /** Azimuth angle e.g. 45°30'00\". Requires provided quantities to be of the angle phenomenon */\r\n Azimuth = \"Azimuth\",\r\n /** Ratio display e,g. 1:2 or 0.3:1. */\r\n Ratio = \"Ratio\",\r\n}\r\n\r\n/** required if type is scientific\r\n * @beta */\r\nexport enum ScientificType {\r\n /** Non-zero value left of decimal point (ie 1.2345e3) */\r\n Normalized = \"Normalized\",\r\n /** Zero value left of decimal point (ie 0.12345e4) */\r\n ZeroNormalized = \"ZeroNormalized\",\r\n}\r\n\r\n/** required if type is ratio\r\n * @beta */\r\nexport enum RatioType {\r\n /** One to N ratio (ie 1:N) */\r\n OneToN = \"OneToN\",\r\n /** N to One ratio (ie N:1) */\r\n NToOne = \"NToOne\",\r\n /** the lesser value scales to 1. e.g. input 0.5 turns into 2:1 | input 2 turns into 1:2 */\r\n ValueBased = \"ValueBased\",\r\n /** scales the input ratio to its simplest integer form using the greatest common divisor (GCD) of the values. e.g. 0.3 turns into 3:10 */\r\n UseGreatestCommonDivisor = \"UseGreatestCommonDivisor\",\r\n}\r\n\r\n/** Determines how the sign of values are displayed\r\n * @beta */\r\nexport enum ShowSignOption {\r\n /** Never show a sign even if the value is negative. */\r\n NoSign = \"NoSign\",\r\n /** Only show a sign when the value is negative. */\r\n OnlyNegative = \"OnlyNegative\",\r\n /** Always show a sign whether the value is positive or negative. */\r\n SignAlways = \"SignAlways\",\r\n /** Only show a sign when the value is negative but use parentheses instead of a negative sign. For example, -10 is formatted as `(10)`. */\r\n NegativeParentheses = \"NegativeParentheses\",\r\n}\r\n\r\n// parse and toString methods\r\n\r\n/**\r\n * @beta\r\n * @deprecated in 4.10. ScientificType is now a string enum and doesn't need a serialization method. You can access the enum directly.\r\n*/\r\nexport function scientificTypeToString(scientificType: ScientificType): string {\r\n return (scientificType === ScientificType.Normalized) ? \"Normalized\" : \"ZeroNormalized\";\r\n}\r\n\r\n/**\r\n * @beta\r\n*/\r\nexport function parseScientificType(scientificType: string, formatName: string): ScientificType {\r\n switch (scientificType.toLowerCase()) {\r\n case \"normalized\": return ScientificType.Normalized;\r\n case \"zeronormalized\": return ScientificType.ZeroNormalized;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'scientificType' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function parseRatioType(ratioType: string, formatName: string): RatioType {\r\n const normalizedValue = ratioType.toLowerCase();\r\n for (const key in RatioType) {\r\n if (RatioType.hasOwnProperty(key)) {\r\n const enumValue = RatioType[key as keyof typeof RatioType];\r\n if (enumValue.toLowerCase() === normalizedValue) {\r\n return enumValue as RatioType;\r\n }\r\n }\r\n }\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'ratioType' attribute.`);\r\n}\r\n\r\n/** @beta */\r\nexport function parseShowSignOption(showSignOption: string, formatName: string): ShowSignOption {\r\n switch (showSignOption.toLowerCase()) {\r\n case \"nosign\": return ShowSignOption.NoSign;\r\n case \"onlynegative\": return ShowSignOption.OnlyNegative;\r\n case \"signalways\": return ShowSignOption.SignAlways;\r\n case \"negativeparentheses\": return ShowSignOption.NegativeParentheses;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'showSignOption' attribute.`);\r\n }\r\n}\r\n\r\n/**\r\n * @beta\r\n * @deprecated in 4.10. ShowSignOption is now a string enum and doesn't need a serialization method. You can access the enum directly.\r\n*/\r\nexport function showSignOptionToString(showSign: ShowSignOption): string {\r\n switch (showSign) {\r\n case ShowSignOption.NegativeParentheses: return \"NegativeParentheses\";\r\n case ShowSignOption.NoSign: return \"NoSign\";\r\n case ShowSignOption.OnlyNegative: return \"OnlyNegative\";\r\n case ShowSignOption.SignAlways: return \"SignAlways\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function parseFormatTrait(formatTraitsString: string, formatName: string): FormatTraits {\r\n switch (formatTraitsString.toLowerCase()) {\r\n case \"trailzeroes\": return FormatTraits.TrailZeroes;\r\n case \"keepsinglezero\": return FormatTraits.KeepSingleZero;\r\n case \"zeroempty\": return FormatTraits.ZeroEmpty;\r\n case \"keepdecimalpoint\": return FormatTraits.KeepDecimalPoint;\r\n case \"applyrounding\": return FormatTraits.ApplyRounding;\r\n case \"fractiondash\": return FormatTraits.FractionDash;\r\n case \"showunitlabel\": return FormatTraits.ShowUnitLabel;\r\n case \"prependunitlabel\": return FormatTraits.PrependUnitLabel;\r\n case \"use1000separator\": return FormatTraits.Use1000Separator;\r\n case \"exponentonlynegative\": return FormatTraits.ExponentOnlyNegative;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'formatTraits' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function getTraitString(trait: FormatTraits) {\r\n switch (trait) {\r\n case FormatTraits.TrailZeroes:\r\n return \"trailZeroes\";\r\n case FormatTraits.KeepSingleZero:\r\n return \"keepSingleZero\";\r\n case FormatTraits.ZeroEmpty:\r\n return \"zeroEmpty\";\r\n case FormatTraits.KeepDecimalPoint:\r\n return \"keepDecimalPoint\";\r\n case FormatTraits.ApplyRounding:\r\n return \"applyRounding\";\r\n case FormatTraits.FractionDash:\r\n return \"fractionDash\";\r\n case FormatTraits.ShowUnitLabel:\r\n return \"showUnitLabel\";\r\n case FormatTraits.PrependUnitLabel:\r\n return \"prependUnitLabel\";\r\n case FormatTraits.Use1000Separator:\r\n return \"use1000Separator\";\r\n case FormatTraits.ExponentOnlyNegative:\r\n default:\r\n return \"exponentOnlyNegative\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function formatTraitsToArray(currentFormatTrait: FormatTraits): string[] {\r\n const formatTraitsArr = Array<string>();\r\n if ((currentFormatTrait & FormatTraits.TrailZeroes) === FormatTraits.TrailZeroes)\r\n formatTraitsArr.push(\"TrailZeroes\");\r\n if ((currentFormatTrait & FormatTraits.KeepSingleZero) === FormatTraits.KeepSingleZero)\r\n formatTraitsArr.push(\"KeepSingleZero\");\r\n if ((currentFormatTrait & FormatTraits.ZeroEmpty) === FormatTraits.ZeroEmpty)\r\n formatTraitsArr.push(\"ZeroEmpty\");\r\n if ((currentFormatTrait & FormatTraits.KeepDecimalPoint) === FormatTraits.KeepDecimalPoint)\r\n formatTraitsArr.push(\"KeepDecimalPoint\");\r\n if ((currentFormatTrait & FormatTraits.ApplyRounding) === FormatTraits.ApplyRounding)\r\n formatTraitsArr.push(\"ApplyRounding\");\r\n if ((currentFormatTrait & FormatTraits.FractionDash) === FormatTraits.FractionDash)\r\n formatTraitsArr.push(\"FractionDash\");\r\n if ((currentFormatTrait & FormatTraits.ShowUnitLabel) === FormatTraits.ShowUnitLabel)\r\n formatTraitsArr.push(\"ShowUnitLabel\");\r\n if ((currentFormatTrait & FormatTraits.PrependUnitLabel) === FormatTraits.PrependUnitLabel)\r\n formatTraitsArr.push(\"PrependUnitLabel\");\r\n if ((currentFormatTrait & FormatTraits.Use1000Separator) === FormatTraits.Use1000Separator)\r\n formatTraitsArr.push(\"Use1000Separator\");\r\n if ((currentFormatTrait & FormatTraits.ExponentOnlyNegative) === FormatTraits.ExponentOnlyNegative)\r\n formatTraitsArr.push(\"ExponentOnlyNegative\");\r\n return formatTraitsArr;\r\n}\r\n\r\n/** @beta */\r\nexport function parseFormatType(jsonObjType: string, formatName: string): FormatType {\r\n switch (jsonObjType.toLowerCase()) {\r\n case \"decimal\": return FormatType.Decimal;\r\n case \"scientific\": return FormatType.Scientific;\r\n case \"station\": return FormatType.Station;\r\n case \"fractional\": return FormatType.Fractional;\r\n case \"bearing\": return FormatType.Bearing;\r\n case \"azimuth\": return FormatType.Azimuth;\r\n case \"ratio\": return FormatType.Ratio;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'type' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta\r\n * @deprecated in 4.10. FormatType is now a string enum and doesn't need a serialization method. You can access the enum directly.\r\n*/\r\nexport function formatTypeToString(type: FormatType): string {\r\n switch (type) {\r\n case FormatType.Decimal: return \"Decimal\";\r\n case FormatType.Scientific: return \"Scientific\";\r\n case FormatType.Station: return \"Station\";\r\n case FormatType.Fractional: return \"Fractional\";\r\n case FormatType.Bearing: return \"Bearing\";\r\n case FormatType.Azimuth: return \"Azimuth\";\r\n case FormatType.Ratio: return \"Ratio\";\r\n }\r\n}\r\n\r\n/** @beta */\r\nexport function parseDecimalPrecision(jsonObjPrecision: number, formatName: string): DecimalPrecision {\r\n switch (jsonObjPrecision) {\r\n case 0: return DecimalPrecision.Zero;\r\n case 1: return DecimalPrecision.One;\r\n case 2: return DecimalPrecision.Two;\r\n case 3: return DecimalPrecision.Three;\r\n case 4: return DecimalPrecision.Four;\r\n case 5: return DecimalPrecision.Five;\r\n case 6: return DecimalPrecision.Six;\r\n case 7: return DecimalPrecision.Seven;\r\n case 8: return DecimalPrecision.Eight;\r\n case 9: return DecimalPrecision.Nine;\r\n case 10: return DecimalPrecision.Ten;\r\n case 11: return DecimalPrecision.Eleven;\r\n case 12: return DecimalPrecision.Twelve;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid FractionalPrecision */\r\nexport function parseFractionalPrecision(jsonObjPrecision: number, formatName: string): FractionalPrecision {\r\n switch (jsonObjPrecision) {\r\n case 1: return FractionalPrecision.One;\r\n case 2: return FractionalPrecision.Two;\r\n case 4: return FractionalPrecision.Four;\r\n case 8: return FractionalPrecision.Eight;\r\n case 16: return FractionalPrecision.Sixteen;\r\n case 32: return FractionalPrecision.ThirtyTwo;\r\n case 64: return FractionalPrecision.SixtyFour;\r\n case 128: return FractionalPrecision.OneHundredTwentyEight;\r\n case 256: return FractionalPrecision.TwoHundredFiftySix;\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);\r\n }\r\n}\r\n\r\n/** @beta validates the input value, that is typically extracted for persisted JSON data, is a valid DecimalPrecision or FractionalPrecision. */\r\nexport function parsePrecision(precision: number, type: FormatType, formatName: string): DecimalPrecision | FractionalPrecision {\r\n switch (type) { // type must be decimal, fractional, scientific, or station\r\n case FormatType.Decimal:\r\n case FormatType.Scientific:\r\n case FormatType.Station:\r\n case FormatType.Ratio:\r\n case FormatType.Bearing:\r\n case FormatType.Azimuth:\r\n return parseDecimalPrecision(precision, formatName);\r\n case FormatType.Fractional:\r\n return parseFractionalPrecision(precision, formatName);\r\n default:\r\n throw new QuantityError(QuantityStatus.InvalidJson, `The Format ${formatName} has an invalid 'precision' attribute.`);\r\n }\r\n}\r\n"]}
@@ -45,5 +45,6 @@ export declare class Formatter {
45
45
  private static processBearingAndAzimuth;
46
46
  private static normalizeAngle;
47
47
  private static getRevolution;
48
+ private static formatRatio;
48
49
  }
49
50
  //# sourceMappingURL=Formatter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Formatter.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Formatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA8FhD;;GAEG;AACH,qBAAa,SAAS;IAEpB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAW;IAE1C,OAAO,CAAC,MAAM,CAAC,YAAY;IAE3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAW1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA0BhC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAajC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkBlC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAsC9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IA6H9B,OAAO,CAAC,MAAM,CAAC,WAAW;IAU1B;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM;IA8D5E,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAoFvC,OAAO,CAAC,MAAM,CAAC,cAAc;IAS7B,OAAO,CAAC,MAAM,CAAC,aAAa;CAa7B"}
1
+ {"version":3,"file":"Formatter.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Formatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA8FhD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAW;IAE1C,OAAO,CAAC,MAAM,CAAC,YAAY;IAE3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAW1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA0BhC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAajC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkBlC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAyD9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IA6H9B,OAAO,CAAC,MAAM,CAAC,WAAW;IAU1B;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM;IA8D5E,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAoFvC,OAAO,CAAC,MAAM,CAAC,cAAc;IAS7B,OAAO,CAAC,MAAM,CAAC,aAAa;IAc5B,OAAO,CAAC,MAAM,CAAC,WAAW;CAqC3B"}
@@ -40,13 +40,13 @@ class FractionalNumeric {
40
40
  this._integral += 1;
41
41
  }
42
42
  else {
43
- this._greatestCommonFactor = this.getGreatestCommonFactor(this._numerator, this._denominator);
43
+ this._greatestCommonFactor = FractionalNumeric.getGreatestCommonFactor(this._numerator, this._denominator);
44
44
  }
45
45
  }
46
46
  /** Determine the GCD given two values. This value can be used to reduce a fraction.
47
47
  * See algorithm description http://en.wikipedia.org/wiki/Euclidean_algorithm
48
48
  */
49
- getGreatestCommonFactor(numerator, denominator) {
49
+ static getGreatestCommonFactor(numerator, denominator) {
50
50
  let r;
51
51
  while (denominator !== 0) {
52
52
  r = numerator % denominator;
@@ -171,15 +171,31 @@ class Formatter {
171
171
  const compositeStrings = [];
172
172
  // Caller will deal with appending +||-||() value sign as specified by formatting options so just format positive value
173
173
  let posMagnitude = Math.abs(magnitude);
174
- // eslint-disable-next-line @typescript-eslint/prefer-for-of
175
174
  for (let i = 0; i < spec.unitConversions.length; i++) {
176
175
  const currentLabel = spec.unitConversions[i].label;
177
176
  const unitConversion = spec.unitConversions[i].conversion;
178
177
  if (i > 0 && unitConversion.factor < 1.0)
179
178
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification..`);
180
- if (i > 0 && unitConversion.offset !== 0)
179
+ if (i > 0 && unitConversion.offset !== 0) // offset should only ever be defined for major unit
181
180
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification..`);
182
- let unitValue = (posMagnitude * unitConversion.factor) + unitConversion.offset + Formatter.FPV_MINTHRESHOLD; // offset should only ever be defined for major unit
181
+ let unitValue = 0.0;
182
+ if (spec.format.type === FormatEnums_1.FormatType.Ratio) {
183
+ if (1 !== spec.format.units.length)
184
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has an invalid unit specification, we require single presentation unit when using format type 'ratio'`);
185
+ try {
186
+ unitValue = (0, Quantity_1.applyConversion)(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;
187
+ }
188
+ catch (e) {
189
+ // The "InvertingZero" error is thrown when the value is zero and the conversion factor is inverted.
190
+ // For ratio, we actually want to support this corner case and return "1:0" as the formatted value.
191
+ if (e instanceof Exception_1.QuantityError && e.errorNumber === Exception_1.QuantityStatus.InvertingZero) {
192
+ return "1:0";
193
+ }
194
+ }
195
+ compositeStrings.push(this.formatRatio(unitValue, spec));
196
+ continue;
197
+ }
198
+ unitValue = (0, Quantity_1.applyConversion)(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;
183
199
  if (0 === i) {
184
200
  const precisionScale = Math.pow(10, 8); // use a fixed round off precision of 8 to avoid loss of precision in actual magnitude
185
201
  unitValue = Math.floor(unitValue * precisionScale + FPV_ROUNDFACTOR) / precisionScale;
@@ -209,7 +225,7 @@ class Formatter {
209
225
  if (spec.format.hasFormatTraitSet(FormatEnums_1.FormatTraits.ApplyRounding))
210
226
  posMagnitude = Math.abs(Formatter.roundDouble(magnitude, spec.format.roundFactor));
211
227
  const isSci = ((posMagnitude > 1.0e12) || spec.format.type === FormatEnums_1.FormatType.Scientific);
212
- const isDecimal = (isSci || spec.format.type === FormatEnums_1.FormatType.Decimal || spec.format.type === FormatEnums_1.FormatType.Bearing || spec.format.type === FormatEnums_1.FormatType.Azimuth);
228
+ const isDecimal = (isSci || spec.format.type === FormatEnums_1.FormatType.Decimal || spec.format.type === FormatEnums_1.FormatType.Bearing || spec.format.type === FormatEnums_1.FormatType.Azimuth) || spec.format.type === FormatEnums_1.FormatType.Ratio;
213
229
  const isFractional = (!isDecimal && spec.format.type === FormatEnums_1.FormatType.Fractional);
214
230
  /* const usesStops = spec.format.type === FormatType.Station; */
215
231
  const isPrecisionZero = spec.format.precision === FormatEnums_1.DecimalPrecision.Zero;
@@ -396,35 +412,35 @@ class Formatter {
396
412
  }
397
413
  let prefix, suffix;
398
414
  // Quadrants are
399
- // 1 0
400
- // 2 3
401
- // For quadrants 0 and 2 we have to subtract the angle from quarterRevolution degrees because they go clockwise
402
- if (quadrant === 0 || quadrant === 2)
415
+ // 3 0
416
+ // 2 1
417
+ // For quadrants 1 and 3 we have to subtract the angle from quarterRevolution degrees because they go counter-clockwise
418
+ if (quadrant === 1 || quadrant === 3)
403
419
  magnitude = quarterRevolution - magnitude;
404
420
  // TODO: at some point we will want to open this for localization, in the first release it's going to be hard coded
405
- if (quadrant === 0 || quadrant === 1)
421
+ if (quadrant === 0 || quadrant === 3)
406
422
  prefix = "N";
407
- if (quadrant === 2 || quadrant === 3)
423
+ if (quadrant === 2 || quadrant === 1)
408
424
  prefix = "S";
409
- if (quadrant === 0 || quadrant === 3)
425
+ if (quadrant === 0 || quadrant === 1)
410
426
  suffix = "E";
411
- if (quadrant === 1 || quadrant === 2)
427
+ if (quadrant === 3 || quadrant === 2)
412
428
  suffix = "W";
413
- // special case, if in quadrant 2 and value is very small, turn suffix to E because S00:00:00E is preferred over S00:00:00W
429
+ // special case, if in quadrant 2 and value is very close to quarter revolution (90°), turn prefix to N because N90:00:00W is preferred over S90:00:00W
414
430
  if (quadrant === 2 && spec.unitConversions.length > 0) {
415
431
  // To determine if value is small, we need to convert it to the smallest unit presented and use the provided precision on it
416
432
  const unitConversion = spec.unitConversions[spec.unitConversions.length - 1].conversion;
417
- const smallestFormattedValue = (magnitude * unitConversion.factor) + unitConversion.offset + Formatter.FPV_MINTHRESHOLD;
433
+ const smallestFormattedDelta = (0, Quantity_1.applyConversion)((quarterRevolution - magnitude), unitConversion) + this.FPV_MINTHRESHOLD;
418
434
  const precisionScale = Math.pow(10.0, spec.format.precision);
419
- const floor = Math.floor((smallestFormattedValue) * precisionScale + FPV_ROUNDFACTOR) / precisionScale;
435
+ const floor = Math.floor((smallestFormattedDelta) * precisionScale + FPV_ROUNDFACTOR) / precisionScale;
420
436
  if (floor === 0) {
421
- suffix = "E";
437
+ prefix = "N";
422
438
  }
423
439
  }
424
440
  return { magnitude, prefix, suffix: suffix };
425
441
  }
426
442
  if (type === FormatEnums_1.FormatType.Azimuth) {
427
- let azimuthBase = quarterRevolution; // default base is North
443
+ let azimuthBase = 0; // default base is North
428
444
  if (spec.format.azimuthBase !== undefined) {
429
445
  if (spec.azimuthBaseConversion === undefined) {
430
446
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.name}'s azimuth base.`);
@@ -436,13 +452,13 @@ class Formatter {
436
452
  }
437
453
  azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);
438
454
  }
439
- if (azimuthBase === quarterRevolution && spec.format.azimuthCounterClockwiseOrDefault)
440
- return { magnitude }; // no conversion necessary, the input is already using the result parameters (east base and counter clockwise)
455
+ if (azimuthBase === 0.0 && spec.format.azimuthClockwiseOrDefault)
456
+ return { magnitude }; // no conversion necessary, the input is already using the result parameters (north base and clockwise)
441
457
  // subtract the base from the actual value
442
458
  magnitude -= azimuthBase;
443
- if (spec.format.azimuthCounterClockwiseOrDefault)
459
+ if (spec.format.azimuthClockwiseOrDefault)
444
460
  return { magnitude: this.normalizeAngle(magnitude, revolution) };
445
- // turn it into a clockwise angle
461
+ // turn it into a counter-clockwise angle
446
462
  magnitude = revolution - magnitude;
447
463
  // normalize the result as it may have become negative or exceed the revolution
448
464
  magnitude = this.normalizeAngle(magnitude, revolution);
@@ -466,8 +482,38 @@ class Formatter {
466
482
  }
467
483
  return converted.magnitude;
468
484
  }
485
+ static formatRatio(magnitude, spec) {
486
+ if (null === spec.format.ratioType)
487
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} must have a ratio type specified.`);
488
+ const precisionScale = Math.pow(10.0, spec.format.precision);
489
+ let reciprocal = 0;
490
+ if (magnitude === 0.0)
491
+ return "0:1";
492
+ else
493
+ reciprocal = 1.0 / magnitude;
494
+ switch (spec.format.ratioType) {
495
+ case FormatEnums_1.RatioType.OneToN:
496
+ return `1:${this.formatMagnitude(reciprocal, spec)}`;
497
+ case FormatEnums_1.RatioType.NToOne:
498
+ return `${this.formatMagnitude(magnitude, spec)}:1`;
499
+ case FormatEnums_1.RatioType.ValueBased:
500
+ if (magnitude > 1.0)
501
+ return `${this.formatMagnitude(magnitude, spec)}:1`;
502
+ else
503
+ return `1:${this.formatMagnitude(reciprocal, spec)}`;
504
+ case FormatEnums_1.RatioType.UseGreatestCommonDivisor:
505
+ magnitude = Math.round(magnitude * precisionScale) / precisionScale;
506
+ let numerator = magnitude * precisionScale;
507
+ let denominator = precisionScale;
508
+ const gcd = FractionalNumeric.getGreatestCommonFactor(numerator, denominator);
509
+ numerator /= gcd;
510
+ denominator /= gcd;
511
+ return `${this.formatMagnitude(numerator, spec)}:${this.formatMagnitude(denominator, spec)}`;
512
+ default:
513
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has an invalid ratio type specified.`);
514
+ }
515
+ }
469
516
  }
470
517
  exports.Formatter = Formatter;
471
- // eslint-disable-next-line @typescript-eslint/naming-convention
472
518
  Formatter.FPV_MINTHRESHOLD = 1.0e-14;
473
519
  //# sourceMappingURL=Formatter.js.map