@itwin/core-quantity 4.9.0-dev.9 → 4.9.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 (72) hide show
  1. package/CHANGELOG.md +33 -1
  2. package/lib/cjs/Exception.d.ts +3 -1
  3. package/lib/cjs/Exception.d.ts.map +1 -1
  4. package/lib/cjs/Exception.js +2 -0
  5. package/lib/cjs/Exception.js.map +1 -1
  6. package/lib/cjs/Formatter/Format.d.ts +14 -0
  7. package/lib/cjs/Formatter/Format.d.ts.map +1 -1
  8. package/lib/cjs/Formatter/Format.js +58 -0
  9. package/lib/cjs/Formatter/Format.js.map +1 -1
  10. package/lib/cjs/Formatter/FormatEnums.d.ts +5 -1
  11. package/lib/cjs/Formatter/FormatEnums.d.ts.map +1 -1
  12. package/lib/cjs/Formatter/FormatEnums.js +10 -0
  13. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  14. package/lib/cjs/Formatter/Formatter.d.ts +4 -0
  15. package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
  16. package/lib/cjs/Formatter/Formatter.js +114 -13
  17. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  18. package/lib/cjs/Formatter/FormatterSpec.d.ts +8 -2
  19. package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
  20. package/lib/cjs/Formatter/FormatterSpec.js +26 -2
  21. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  22. package/lib/cjs/Formatter/Interfaces.d.ts +11 -0
  23. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  24. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  25. package/lib/cjs/Parser.d.ts +7 -1
  26. package/lib/cjs/Parser.d.ts.map +1 -1
  27. package/lib/cjs/Parser.js +158 -4
  28. package/lib/cjs/Parser.js.map +1 -1
  29. package/lib/cjs/ParserSpec.d.ts +5 -1
  30. package/lib/cjs/ParserSpec.d.ts.map +1 -1
  31. package/lib/cjs/ParserSpec.js +20 -1
  32. package/lib/cjs/ParserSpec.js.map +1 -1
  33. package/lib/cjs/Quantity.d.ts +9 -0
  34. package/lib/cjs/Quantity.d.ts.map +1 -1
  35. package/lib/cjs/Quantity.js +15 -1
  36. package/lib/cjs/Quantity.js.map +1 -1
  37. package/lib/esm/Exception.d.ts +3 -1
  38. package/lib/esm/Exception.d.ts.map +1 -1
  39. package/lib/esm/Exception.js +2 -0
  40. package/lib/esm/Exception.js.map +1 -1
  41. package/lib/esm/Formatter/Format.d.ts +14 -0
  42. package/lib/esm/Formatter/Format.d.ts.map +1 -1
  43. package/lib/esm/Formatter/Format.js +59 -1
  44. package/lib/esm/Formatter/Format.js.map +1 -1
  45. package/lib/esm/Formatter/FormatEnums.d.ts +5 -1
  46. package/lib/esm/Formatter/FormatEnums.d.ts.map +1 -1
  47. package/lib/esm/Formatter/FormatEnums.js +10 -0
  48. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  49. package/lib/esm/Formatter/Formatter.d.ts +4 -0
  50. package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
  51. package/lib/esm/Formatter/Formatter.js +114 -13
  52. package/lib/esm/Formatter/Formatter.js.map +1 -1
  53. package/lib/esm/Formatter/FormatterSpec.d.ts +8 -2
  54. package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
  55. package/lib/esm/Formatter/FormatterSpec.js +26 -2
  56. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  57. package/lib/esm/Formatter/Interfaces.d.ts +11 -0
  58. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  59. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  60. package/lib/esm/Parser.d.ts +7 -1
  61. package/lib/esm/Parser.d.ts.map +1 -1
  62. package/lib/esm/Parser.js +158 -4
  63. package/lib/esm/Parser.js.map +1 -1
  64. package/lib/esm/ParserSpec.d.ts +5 -1
  65. package/lib/esm/ParserSpec.d.ts.map +1 -1
  66. package/lib/esm/ParserSpec.js +20 -1
  67. package/lib/esm/ParserSpec.js.map +1 -1
  68. package/lib/esm/Quantity.d.ts +9 -0
  69. package/lib/esm/Quantity.d.ts.map +1 -1
  70. package/lib/esm/Quantity.js +13 -0
  71. package/lib/esm/Quantity.js.map +1 -1
  72. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"FormatterSpec.js","sourceRoot":"","sources":["../../../src/Formatter/FormatterSpec.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,2CAAwC;AAExC,sFAAsF;AACtF,6JAA6J;AAE7J;;;GAGG;AACH,MAAa,aAAa;IAMxB;;;;;OAKG;IACH,YAAY,IAAY,EAAE,MAAc,EAAE,WAAkC,EAAE,eAA2B;QAV/F,iBAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;QAWrE,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAChC,eAAe,GAAG,KAAK,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,WAAW;YACb,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IACpC,CAAC;IAED,IAAW,IAAI,KAAa,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAChD,uHAAuH;IACvH,IAAW,eAAe,KAA2B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAW,eAAe,KAAgB,OAAO,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AS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAuB,CAAC;gBAElI,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACvB,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;aAAM,CAAC;YACN,0GAA0G;YAC1G,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,IAAI,GAAuB,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC;gBACtJ,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,MAAc,EAAE,aAA4B,EAAE,SAAqB;QAC1G,MAAM,WAAW,GAAyB,MAAM,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;QACnH,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACjE,CAAC;IAED,+BAA+B;IACxB,eAAe,CAAC,SAAiB;QACtC,OAAO,qBAAS,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;CACF;AA1FD,sCA0FC","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 { UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"../Interfaces\";\r\nimport { Format } from \"./Format\";\r\nimport { Formatter } from \"./Formatter\";\r\n\r\n// cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses\r\n// cSpell:ignore trailzeroes, keepsinglezero, zeroempty, keepdecimalpoint, applyrounding, fractiondash, showunitlabel, prependunitlabel, exponentonlynegative\r\n\r\n/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format.\r\n * Once created the FormatterSpec will be able to format quantity values with synchronous calls.\r\n * @beta\r\n */\r\nexport class FormatterSpec {\r\n protected _name: string;\r\n protected _conversions: UnitConversionSpec[] = []; // max four entries\r\n protected _format: Format;\r\n protected _persistenceUnit: UnitProps;\r\n\r\n /** Constructor\r\n * @param name The name of a format specification.\r\n * @param format Defines the output format for the quantity value.\r\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format.\r\n * @param persistenceUnit The unit the magnitude value is input.\r\n */\r\n constructor(name: string, format: Format, conversions?: UnitConversionSpec[], persistenceUnit?: UnitProps) {\r\n if (!persistenceUnit) {\r\n if (format.units) {\r\n const [props] = format.units[0];\r\n persistenceUnit = props;\r\n } else {\r\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\r\n }\r\n }\r\n\r\n this._name = name;\r\n this._format = format;\r\n this._persistenceUnit = persistenceUnit;\r\n if (conversions)\r\n this._conversions = conversions;\r\n }\r\n\r\n public get name(): string { return this._name; }\r\n /** Returns an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\r\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\r\n public get format(): Format { return this._format; }\r\n public get persistenceUnit(): UnitProps { return this._persistenceUnit; }\r\n\r\n /** Get an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\r\n public static async getUnitConversions(format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<UnitConversionSpec[]> {\r\n const conversions: UnitConversionSpec[] = [];\r\n let persistenceUnit = inputUnit;\r\n if (!persistenceUnit) {\r\n if (format.units) {\r\n const [props] = format.units[0];\r\n persistenceUnit = props;\r\n } else {\r\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\r\n }\r\n }\r\n\r\n if (format.units) {\r\n let convertFromUnit = inputUnit;\r\n for (const unit of format.units) {\r\n let unitConversion: UnitConversionProps;\r\n if (convertFromUnit) {\r\n unitConversion = await unitsProvider.getConversion(convertFromUnit, unit[0]);\r\n } else {\r\n unitConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n const unitLabel = (unit[1] && unit[1].length > 0) ? unit[1] : unit[0].label;\r\n const spec = ({ name: unit[0].name, label: unitLabel, conversion: unitConversion, system: unit[0].system }) as UnitConversionSpec;\r\n\r\n conversions.push(spec);\r\n convertFromUnit = unit[0];\r\n }\r\n } else {\r\n // if format is only numeric and a input unit is defined set spec to use the input unit as the format unit\r\n if (inputUnit) {\r\n const spec: UnitConversionSpec = { name: inputUnit.name, label: inputUnit.label, system: inputUnit.system, conversion: { factor: 1.0, offset: 0.0 } };\r\n conversions.push(spec);\r\n }\r\n }\r\n\r\n return conversions;\r\n }\r\n\r\n /** Static async method to create a FormatSpec given the format and unit of the quantity that will be passed to the Formatter. The input unit will\r\n * be used to generate conversion information for each unit specified in the Format. This method is async due to the fact that the units provider must make\r\n * async calls to lookup unit definitions.\r\n * @param name The name of a format specification.\r\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\r\n * @param inputUnit The unit the value to be formatted. This unit is often referred to as persistence unit.\r\n */\r\n public static async create(name: string, format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<FormatterSpec> {\r\n const conversions: UnitConversionSpec[] = await FormatterSpec.getUnitConversions(format, unitsProvider, inputUnit);\r\n return new FormatterSpec(name, format, conversions, inputUnit);\r\n }\r\n\r\n /** Format a quantity value. */\r\n public applyFormatting(magnitude: number): string {\r\n return Formatter.formatQuantity(magnitude, this);\r\n }\r\n}\r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vD,CAAC;QACH,CAAC;QACD,IAAI,oBAAqD,CAAC;QAC1D,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC5B,oBAAoB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;YAC7F,CAAC;iBAAM,CAAC;gBACN,oBAAoB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YACtD,CAAC;QACH,CAAC;QAED,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,qBAAqB,EAAE,oBAAoB,CAAC,CAAC;IAC9G,CAAC;IAED,+BAA+B;IACxB,eAAe,CAAC,SAAiB;QACtC,OAAO,qBAAS,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;CACF;AAnHD,sCAmHC","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 { UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"../Interfaces\";\r\nimport { Format } from \"./Format\";\r\nimport { Formatter } from \"./Formatter\";\r\n\r\n// cSpell:ignore ZERONORMALIZED, nosign, onlynegative, signalways, negativeparentheses\r\n// cSpell:ignore trailzeroes, keepsinglezero, zeroempty, keepdecimalpoint, applyrounding, fractiondash, showunitlabel, prependunitlabel, exponentonlynegative\r\n\r\n/** A class that contains both formatting information and the conversion factors necessary to convert from an input unit to the units specified in the format.\r\n * Once created the FormatterSpec will be able to format quantity values with synchronous calls.\r\n * @beta\r\n */\r\nexport class FormatterSpec {\r\n protected _name: string;\r\n protected _conversions: UnitConversionSpec[] = []; // max four entries\r\n protected _format: Format;\r\n protected _persistenceUnit: UnitProps;\r\n protected _azimuthBaseConversion?: UnitConversionProps; // converts azimuth base unit to persistence unit\r\n protected _revolutionConversion?: UnitConversionProps; // converts revolution unit to persistence unit\r\n\r\n /** Constructor\r\n * @param name The name of a format specification.\r\n * @param format Defines the output format for the quantity value.\r\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format.\r\n * @param persistenceUnit The unit the magnitude value is input.\r\n * @param azimuthBaseConversion The conversion used to interpret azimuth base values.\r\n * @param revolutionConversion The conversion used to determine a revolution value (used for bearing and azimuth).\r\n */\r\n constructor(name: string, format: Format, conversions?: UnitConversionSpec[], persistenceUnit?: UnitProps, azimuthBaseConversion?: UnitConversionProps, revolutionConversion?: UnitConversionProps) {\r\n if (!persistenceUnit) {\r\n if (format.units) {\r\n const [props] = format.units[0];\r\n persistenceUnit = props;\r\n } else {\r\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\r\n }\r\n }\r\n\r\n this._name = name;\r\n this._format = format;\r\n this._persistenceUnit = persistenceUnit;\r\n if (conversions)\r\n this._conversions = conversions;\r\n this._azimuthBaseConversion = azimuthBaseConversion;\r\n this._revolutionConversion = revolutionConversion;\r\n }\r\n\r\n public get name(): string { return this._name; }\r\n /** Returns an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\r\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\r\n public get format(): Format { return this._format; }\r\n public get persistenceUnit(): UnitProps { return this._persistenceUnit; }\r\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\r\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\r\n\r\n /** Get an array of UnitConversionSpecs, one for each unit that is to be shown in the formatted quantity string. */\r\n public static async getUnitConversions(format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<UnitConversionSpec[]> {\r\n const conversions: UnitConversionSpec[] = [];\r\n let persistenceUnit = inputUnit;\r\n if (!persistenceUnit) {\r\n if (format.units) {\r\n const [props] = format.units[0];\r\n persistenceUnit = props;\r\n } else {\r\n throw new Error(\"Formatter Spec needs persistence unit to be specified\");\r\n }\r\n }\r\n\r\n if (format.units) {\r\n let convertFromUnit = inputUnit;\r\n for (const unit of format.units) {\r\n let unitConversion: UnitConversionProps;\r\n if (convertFromUnit) {\r\n unitConversion = await unitsProvider.getConversion(convertFromUnit, unit[0]);\r\n } else {\r\n unitConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n const unitLabel = (unit[1] && unit[1].length > 0) ? unit[1] : unit[0].label;\r\n const spec = ({ name: unit[0].name, label: unitLabel, conversion: unitConversion, system: unit[0].system }) as UnitConversionSpec;\r\n\r\n conversions.push(spec);\r\n convertFromUnit = unit[0];\r\n }\r\n } else {\r\n // if format is only numeric and a input unit is defined set spec to use the input unit as the format unit\r\n if (inputUnit) {\r\n const spec: UnitConversionSpec = { name: inputUnit.name, label: inputUnit.label, system: inputUnit.system, conversion: { factor: 1.0, offset: 0.0 } };\r\n conversions.push(spec);\r\n }\r\n }\r\n\r\n return conversions;\r\n }\r\n\r\n /** Static async method to create a FormatSpec given the format and unit of the quantity that will be passed to the Formatter. The input unit will\r\n * be used to generate conversion information for each unit specified in the Format. This method is async due to the fact that the units provider must make\r\n * async calls to lookup unit definitions.\r\n * @param name The name of a format specification.\r\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\r\n * @param inputUnit The unit the value to be formatted. This unit is often referred to as persistence unit.\r\n */\r\n public static async create(name: string, format: Format, unitsProvider: UnitsProvider, inputUnit?: UnitProps): Promise<FormatterSpec> {\r\n const conversions: UnitConversionSpec[] = await FormatterSpec.getUnitConversions(format, unitsProvider, inputUnit);\r\n let azimuthBaseConversion: UnitConversionProps | undefined;\r\n if (format.azimuthBaseUnit !== undefined) {\r\n if (inputUnit !== undefined) {\r\n azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, inputUnit);\r\n } else {\r\n azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n }\r\n let revolutionConversion: UnitConversionProps | undefined;\r\n if (format.revolutionUnit !== undefined) {\r\n if (inputUnit !== undefined) {\r\n revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, inputUnit);\r\n } else {\r\n revolutionConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n }\r\n\r\n return new FormatterSpec(name, format, conversions, inputUnit, azimuthBaseConversion, revolutionConversion);\r\n }\r\n\r\n /** Format a quantity value. */\r\n public applyFormatting(magnitude: number): string {\r\n return Formatter.formatQuantity(magnitude, this);\r\n }\r\n}\r\n"]}
@@ -16,11 +16,22 @@ export interface FormatProps {
16
16
  readonly decimalSeparator?: string;
17
17
  readonly thousandSeparator?: string;
18
18
  readonly uomSeparator?: string;
19
+ /** conditionally required. */
19
20
  readonly scientificType?: string;
21
+ /** conditionally required. */
20
22
  readonly stationOffsetSize?: number;
21
23
  readonly stationSeparator?: string;
24
+ /** The base value for azimuth, specified from east counter-clockwise. */
25
+ readonly azimuthBase?: number;
26
+ /** The name of the unit for the azimuth base value. */
27
+ readonly azimuthBaseUnit?: string;
28
+ /** If set to true, azimuth values are returned counter-clockwise from the base. */
29
+ readonly azimuthCounterClockwise?: boolean;
30
+ /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */
31
+ readonly revolutionUnit?: string;
22
32
  readonly allowMathematicOperations?: boolean;
23
33
  readonly composite?: {
34
+ /** separates values when formatting composite strings */
24
35
  readonly spacer?: string;
25
36
  readonly includeZero?: boolean;
26
37
  readonly units: Array<{
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,eAAe,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gBAAgB,GAAG,mBAAmB,CAAC;IACnD,oDAAoD;IACpD,WAAW,CAAC,EAAE,SAAS,CAAC;CACzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAuCH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","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 { UnitProps } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n readonly type: string;\r\n readonly precision?: number;\r\n readonly roundFactor?: number;\r\n readonly minWidth?: number;\r\n readonly showSignOption?: string;\r\n readonly formatTraits?: string | string[];\r\n readonly decimalSeparator?: string;\r\n readonly thousandSeparator?: string;\r\n readonly uomSeparator?: string;\r\n readonly scientificType?: string; // conditionally required\r\n readonly stationOffsetSize?: number; // conditionally required\r\n readonly stationSeparator?: string;\r\n readonly allowMathematicOperations?: boolean;\r\n readonly composite?: {\r\n readonly spacer?: string;\r\n readonly includeZero?: boolean; // not currently used in Native formatter\r\n readonly units: Array<{\r\n readonly name: string;\r\n readonly label?: string;\r\n }>;\r\n };\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAyDH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","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 { UnitProps } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n readonly type: string;\r\n readonly precision?: number;\r\n readonly roundFactor?: number;\r\n readonly minWidth?: number;\r\n readonly showSignOption?: string;\r\n readonly formatTraits?: string | string[];\r\n readonly decimalSeparator?: string;\r\n readonly thousandSeparator?: string;\r\n readonly uomSeparator?: string;\r\n\r\n /** conditionally required. */\r\n readonly scientificType?: string;\r\n\r\n /** conditionally required. */\r\n readonly stationOffsetSize?: number;\r\n readonly stationSeparator?: string;\r\n\r\n /** The base value for azimuth, specified from east counter-clockwise. */\r\n readonly azimuthBase?: number;\r\n\r\n /** The name of the unit for the azimuth base value. */\r\n readonly azimuthBaseUnit?: string;\r\n\r\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\r\n readonly azimuthCounterClockwise?: boolean;\r\n\r\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\r\n readonly revolutionUnit?: string;\r\n\r\n readonly allowMathematicOperations?: boolean;\r\n readonly composite?: {\r\n /** separates values when formatting composite strings */\r\n readonly spacer?: string;\r\n readonly includeZero?: boolean;\r\n readonly units: Array<{\r\n readonly name: string;\r\n readonly label?: string;\r\n }>;\r\n };\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n"]}
@@ -14,7 +14,8 @@ export declare enum ParseError {
14
14
  UnknownUnit = 4,
15
15
  UnableToConvertParseTokensToQuantity = 5,
16
16
  InvalidParserSpec = 6,
17
- MathematicOperationFoundButIsNotAllowed = 7
17
+ BearingPrefixOrSuffixMissing = 7,
18
+ MathematicOperationFoundButIsNotAllowed = 8
18
19
  }
19
20
  /** Parse error result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]].
20
21
  * @beta
@@ -106,6 +107,11 @@ export declare class Parser {
106
107
  * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
107
108
  */
108
109
  static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
110
+ private static parseBearingFormat;
111
+ private static parseAzimuthFormat;
112
+ private static normalizeAngle;
113
+ private static getRevolution;
114
+ private static parseAndProcessTokens;
109
115
  /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
110
116
  static createUnitConversionSpecsForUnit(unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]>;
111
117
  /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../src/Parser.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,aAAa,EAAuB,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjK,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,oBAAY,UAAU;IACpB,2BAA2B,IAAI;IAC/B,0BAA0B,IA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,kBAAkB,EAAE,CAAC;IA4B1L,+HAA+H;WAC3G,yBAAyB,CAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,EAAE,qBAAqB,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAgDhO"}
package/lib/cjs/Parser.js CHANGED
@@ -9,6 +9,7 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.Parser = exports.ParseError = void 0;
11
11
  const Constants_1 = require("./Constants");
12
+ const Exception_1 = require("./Exception");
12
13
  const FormatEnums_1 = require("./Formatter/FormatEnums");
13
14
  const Quantity_1 = require("./Quantity");
14
15
  /** Possible parser errors
@@ -22,7 +23,8 @@ var ParseError;
22
23
  ParseError[ParseError["UnknownUnit"] = 4] = "UnknownUnit";
23
24
  ParseError[ParseError["UnableToConvertParseTokensToQuantity"] = 5] = "UnableToConvertParseTokensToQuantity";
24
25
  ParseError[ParseError["InvalidParserSpec"] = 6] = "InvalidParserSpec";
25
- ParseError[ParseError["MathematicOperationFoundButIsNotAllowed"] = 7] = "MathematicOperationFoundButIsNotAllowed";
26
+ ParseError[ParseError["BearingPrefixOrSuffixMissing"] = 7] = "BearingPrefixOrSuffixMissing";
27
+ ParseError[ParseError["MathematicOperationFoundButIsNotAllowed"] = 8] = "MathematicOperationFoundButIsNotAllowed";
26
28
  })(ParseError || (exports.ParseError = ParseError = {}));
27
29
  var Operator;
28
30
  (function (Operator) {
@@ -490,6 +492,7 @@ class Parser {
490
492
  let mag = 0.0;
491
493
  // The sign is saved outside from the loop for cases like this. '-1m 50cm 10mm + 2m 30cm 40mm' => -1.51m + 2.34m
492
494
  let sign = 1;
495
+ let compositeUnitIndex = 0;
493
496
  for (let i = 0; i < tokens.length; i = i + increment) {
494
497
  tokenPair = this.getNextTokenPair(i, tokens);
495
498
  if (!tokenPair || tokenPair.length === 0) {
@@ -500,6 +503,7 @@ class Parser {
500
503
  if (tokenPair[0].isOperator) {
501
504
  sign = tokenPair[0].value === Operator.addition ? 1 : -1;
502
505
  tokenPair.shift();
506
+ compositeUnitIndex = 0; // Reset the composite unit index, the following tokens begin from start.
503
507
  }
504
508
  // unit specification comes before value (like currency)
505
509
  if (tokenPair.length === 2 && tokenPair[0].isString) {
@@ -510,13 +514,26 @@ class Parser {
510
514
  let value = sign * tokenPair[0].value;
511
515
  let conversion;
512
516
  if (tokenPair.length === 2 && tokenPair[1].isString) {
513
- conversion = Parser.tryFindUnitConversion(tokenPair[1].value, unitsConversions, defaultUnit);
517
+ const spacer = format.spacerOrDefault;
518
+ if (tokenPair[1].value !== spacer) { // ignore spacer
519
+ conversion = Parser.tryFindUnitConversion(tokenPair[1].value, unitsConversions, defaultUnit);
520
+ }
521
+ }
522
+ if (!conversion) {
523
+ if (compositeUnitIndex > 0 && format.units && format.units.length > compositeUnitIndex) {
524
+ // if this is not the first token, and we have a composite spec, look up the unit from the current index
525
+ const presUnitAtIndex = format.units[compositeUnitIndex][0];
526
+ conversion = Parser.tryFindUnitConversion(presUnitAtIndex.label, unitsConversions, presUnitAtIndex);
527
+ }
528
+ else if (defaultUnitConversion) {
529
+ conversion = defaultUnitConversion;
530
+ }
514
531
  }
515
- conversion = conversion ? conversion : defaultUnitConversion;
516
532
  if (conversion) {
517
533
  value = (value * conversion.factor) + conversion.offset;
518
534
  }
519
535
  mag = mag + value;
536
+ compositeUnitIndex++;
520
537
  }
521
538
  else {
522
539
  // only the unit label was specified so assume magnitude of 0
@@ -534,7 +551,25 @@ class Parser {
534
551
  * @param parserSpec unit label if not explicitly defined by user. Must have matching entry in supplied array of unitsConversions.
535
552
  */
536
553
  static parseQuantityString(inString, parserSpec) {
537
- return Parser.parseToQuantityValue(inString, parserSpec.format, parserSpec.unitConversions);
554
+ // ensure any labels defined in composite unit definition are specified in unitConversions
555
+ if (parserSpec.format.units) {
556
+ parserSpec.format.units.forEach(([unit, label]) => {
557
+ if (label) {
558
+ if (unit.label !== label) { // if default unit label does not match composite label ensure the label is in the list of parse labels for the conversion
559
+ const unitConversion = parserSpec.unitConversions.find((conversion) => conversion.name === unit.name);
560
+ if (unitConversion && unitConversion.parseLabels && !unitConversion.parseLabels.find((entry) => entry === label))
561
+ unitConversion.parseLabels.push(label);
562
+ }
563
+ }
564
+ });
565
+ }
566
+ if (parserSpec.format.type === FormatEnums_1.FormatType.Bearing) {
567
+ return this.parseBearingFormat(inString, parserSpec);
568
+ }
569
+ if (parserSpec.format.type === FormatEnums_1.FormatType.Azimuth) {
570
+ return this.parseAzimuthFormat(inString, parserSpec);
571
+ }
572
+ return this.parseAndProcessTokens(inString, parserSpec.format, parserSpec.unitConversions);
538
573
  }
539
574
  /** Method to generate a Quantity given a string that represents a quantity value and likely a unit label.
540
575
  * @param inString A string that contains text represent a quantity.
@@ -542,6 +577,8 @@ class Parser {
542
577
  * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
543
578
  */
544
579
  static parseToQuantityValue(inString, format, unitsConversions) {
580
+ // TODO: This method is not able to do bearing and azimuth formatting and is overlapping with parseQuantityString.
581
+ // We should consider deprecating and removing it, there do not seem to be any upstream callers at this moment
545
582
  // ensure any labels defined in composite unit definition are specified in unitConversions
546
583
  if (format.units) {
547
584
  format.units.forEach(([unit, label]) => {
@@ -554,6 +591,123 @@ class Parser {
554
591
  }
555
592
  });
556
593
  }
594
+ if (format.type === FormatEnums_1.FormatType.Bearing || format.type === FormatEnums_1.FormatType.Azimuth) {
595
+ // throw error indicating to call parseQuantityString instead
596
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Bearing and Azimuth format must be parsed using a ParserSpec. Call parseQuantityString instead.`);
597
+ }
598
+ return this.parseAndProcessTokens(inString, format, unitsConversions);
599
+ }
600
+ static parseBearingFormat(inString, spec) {
601
+ // TODO: at some point we will want to open this for localization, in the first release it's going to be hard coded
602
+ let DirectionLabel;
603
+ (function (DirectionLabel) {
604
+ DirectionLabel["North"] = "N";
605
+ DirectionLabel["South"] = "S";
606
+ DirectionLabel["East"] = "E";
607
+ DirectionLabel["West"] = "W";
608
+ })(DirectionLabel || (DirectionLabel = {}));
609
+ let matchedPrefix = null;
610
+ let matchedSuffix = null;
611
+ // check if input string begins with northLabel or southLabel and strip it off
612
+ if (inString.startsWith(DirectionLabel.North)) {
613
+ inString = inString.substring(DirectionLabel.North.length);
614
+ matchedPrefix = DirectionLabel.North;
615
+ }
616
+ else if (inString.startsWith(DirectionLabel.South)) {
617
+ inString = inString.substring(DirectionLabel.South.length);
618
+ matchedPrefix = DirectionLabel.South;
619
+ }
620
+ // check if input string ends with eastLabel or westLabel and strip it off
621
+ if (inString.endsWith(DirectionLabel.East)) {
622
+ inString = inString.substring(0, inString.length - DirectionLabel.East.length);
623
+ matchedSuffix = DirectionLabel.East;
624
+ }
625
+ else if (inString.endsWith(DirectionLabel.West)) {
626
+ inString = inString.substring(0, inString.length - DirectionLabel.West.length);
627
+ matchedSuffix = DirectionLabel.West;
628
+ }
629
+ if (matchedPrefix === null && matchedSuffix === null) {
630
+ return { ok: false, error: ParseError.BearingPrefixOrSuffixMissing };
631
+ }
632
+ const parsedResult = this.parseAndProcessTokens(inString, spec.format, spec.unitConversions);
633
+ if (this.isParseError(parsedResult) || !parsedResult.ok) {
634
+ return parsedResult;
635
+ }
636
+ let magnitude = parsedResult.value;
637
+ const revolution = this.getRevolution(spec);
638
+ magnitude = this.normalizeAngle(magnitude, revolution);
639
+ const quarterRevolution = revolution / 4;
640
+ // we have to turn the value into an east base and counter clockwise (NW and SE are already counter clockwise)
641
+ if (matchedPrefix === DirectionLabel.North) {
642
+ if (matchedSuffix === DirectionLabel.West) {
643
+ magnitude = quarterRevolution + magnitude;
644
+ }
645
+ else if (matchedSuffix === DirectionLabel.East) {
646
+ magnitude = quarterRevolution - magnitude;
647
+ }
648
+ }
649
+ else if (matchedPrefix === DirectionLabel.South) {
650
+ if (matchedSuffix === DirectionLabel.West) {
651
+ magnitude = (3 * quarterRevolution) - magnitude;
652
+ }
653
+ else if (matchedSuffix === DirectionLabel.East) {
654
+ magnitude = (3 * quarterRevolution) + magnitude;
655
+ }
656
+ }
657
+ return { ok: true, value: magnitude };
658
+ }
659
+ static parseAzimuthFormat(inString, spec) {
660
+ const parsedResult = this.parseAndProcessTokens(inString, spec.format, spec.unitConversions);
661
+ if (this.isParseError(parsedResult) || !parsedResult.ok) {
662
+ return parsedResult;
663
+ }
664
+ let magnitude = parsedResult.value;
665
+ const revolution = this.getRevolution(spec);
666
+ magnitude = this.normalizeAngle(magnitude, revolution);
667
+ const quarterRevolution = revolution / 4;
668
+ let azimuthBase = quarterRevolution;
669
+ if (spec.format.azimuthBase !== undefined) {
670
+ if (spec.azimuthBaseConversion === undefined) {
671
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.format.name}'s azimuth base.`);
672
+ }
673
+ const azBaseQuantity = new Quantity_1.Quantity(spec.format.azimuthBaseUnit, spec.format.azimuthBase);
674
+ const azBaseConverted = azBaseQuantity.convertTo(spec.outUnit, spec.azimuthBaseConversion);
675
+ if (azBaseConverted === undefined || !azBaseConverted.isValid) {
676
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Failed to convert azimuth base unit to ${spec.outUnit.name}.`);
677
+ }
678
+ azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);
679
+ }
680
+ const azimuthCounterClockwise = spec.format.azimuthCounterClockwiseOrDefault;
681
+ if (azimuthCounterClockwise && azimuthBase === 0) {
682
+ // parsed result already has the same base and orientation as our desired output
683
+ return parsedResult;
684
+ }
685
+ if (azimuthCounterClockwise)
686
+ magnitude = azimuthBase + magnitude;
687
+ else
688
+ magnitude = azimuthBase - magnitude;
689
+ magnitude = this.normalizeAngle(magnitude, revolution);
690
+ return { ok: true, value: magnitude };
691
+ }
692
+ // TODO: The following two methods are redundant with Formatter. We should consider consolidating them.
693
+ static normalizeAngle(magnitude, revolution) {
694
+ magnitude = magnitude % revolution; // Strip anything that goes around more than once
695
+ if (magnitude < 0) // If the value is negative, we want to normalize it to a positive angle
696
+ magnitude += revolution;
697
+ return magnitude;
698
+ }
699
+ static getRevolution(spec) {
700
+ if (spec.revolutionConversion === undefined) {
701
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing revolution unit conversion for calculating ${spec.format.name}'s revolution.`);
702
+ }
703
+ const revolution = new Quantity_1.Quantity(spec.format.revolutionUnit, 1.0);
704
+ const converted = revolution.convertTo(spec.outUnit, spec.revolutionConversion);
705
+ if (converted === undefined || !converted.isValid) {
706
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Failed to convert revolution unit to ${spec.outUnit.name} On format ${spec.format.name}.`);
707
+ }
708
+ return converted.magnitude;
709
+ }
710
+ static parseAndProcessTokens(inString, format, unitsConversions) {
557
711
  const tokens = Parser.parseQuantitySpecification(inString, format);
558
712
  if (tokens.length === 0)
559
713
  return { ok: false, error: ParseError.UnableToGenerateParseTokens };