@itwin/core-quantity 5.10.0-dev.1 → 5.10.0-dev.4

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 (135) hide show
  1. package/lib/cjs/BasicUnitsProvider.d.ts +44 -0
  2. package/lib/cjs/BasicUnitsProvider.d.ts.map +1 -0
  3. package/lib/cjs/BasicUnitsProvider.js +241 -0
  4. package/lib/cjs/BasicUnitsProvider.js.map +1 -0
  5. package/lib/cjs/CompositeUnitsProvider.d.ts +45 -0
  6. package/lib/cjs/CompositeUnitsProvider.d.ts.map +1 -0
  7. package/lib/cjs/CompositeUnitsProvider.js +111 -0
  8. package/lib/cjs/CompositeUnitsProvider.js.map +1 -0
  9. package/lib/cjs/Constants.js.map +1 -1
  10. package/lib/cjs/Exception.js.map +1 -1
  11. package/lib/cjs/FormatSpecHandle.js.map +1 -1
  12. package/lib/cjs/Formatter/Format.js.map +1 -1
  13. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  14. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  15. package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
  16. package/lib/cjs/Formatter/FormatterSpec.js +14 -0
  17. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  18. package/lib/cjs/Formatter/FormattingReadyCollector.js.map +1 -1
  19. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  20. package/lib/cjs/Interfaces.d.ts +14 -0
  21. package/lib/cjs/Interfaces.d.ts.map +1 -1
  22. package/lib/cjs/Interfaces.js.map +1 -1
  23. package/lib/cjs/Parser.d.ts.map +1 -1
  24. package/lib/cjs/Parser.js +16 -1
  25. package/lib/cjs/Parser.js.map +1 -1
  26. package/lib/cjs/ParserSpec.d.ts.map +1 -1
  27. package/lib/cjs/ParserSpec.js +15 -2
  28. package/lib/cjs/ParserSpec.js.map +1 -1
  29. package/lib/cjs/Quantity.js.map +1 -1
  30. package/lib/cjs/QuantityLoggerCategory.d.ts +3 -1
  31. package/lib/cjs/QuantityLoggerCategory.d.ts.map +1 -1
  32. package/lib/cjs/QuantityLoggerCategory.js +2 -0
  33. package/lib/cjs/QuantityLoggerCategory.js.map +1 -1
  34. package/lib/cjs/SerializedUnitSchema.d.ts +98 -0
  35. package/lib/cjs/SerializedUnitSchema.d.ts.map +1 -0
  36. package/lib/cjs/SerializedUnitSchema.js +25 -0
  37. package/lib/cjs/SerializedUnitSchema.js.map +1 -0
  38. package/lib/cjs/Unit.js.map +1 -1
  39. package/lib/cjs/UnitConversion/Graph.d.ts +35 -0
  40. package/lib/cjs/UnitConversion/Graph.d.ts.map +1 -0
  41. package/lib/cjs/UnitConversion/Graph.js +87 -0
  42. package/lib/cjs/UnitConversion/Graph.js.map +1 -0
  43. package/lib/cjs/UnitConversion/Parser.d.ts +9 -0
  44. package/lib/cjs/UnitConversion/Parser.d.ts.map +1 -0
  45. package/lib/cjs/UnitConversion/Parser.js +42 -0
  46. package/lib/cjs/UnitConversion/Parser.js.map +1 -0
  47. package/lib/cjs/UnitConversion/UnitConversion.d.ts +56 -0
  48. package/lib/cjs/UnitConversion/UnitConversion.d.ts.map +1 -0
  49. package/lib/cjs/UnitConversion/UnitConversion.js +80 -0
  50. package/lib/cjs/UnitConversion/UnitConversion.js.map +1 -0
  51. package/lib/cjs/UnitConversion/UnitDefinitionResolver.d.ts +29 -0
  52. package/lib/cjs/UnitConversion/UnitDefinitionResolver.d.ts.map +1 -0
  53. package/lib/cjs/UnitConversion/UnitDefinitionResolver.js +102 -0
  54. package/lib/cjs/UnitConversion/UnitDefinitionResolver.js.map +1 -0
  55. package/lib/cjs/UnitConversion/nameUtils.d.ts +11 -0
  56. package/lib/cjs/UnitConversion/nameUtils.d.ts.map +1 -0
  57. package/lib/cjs/UnitConversion/nameUtils.js +25 -0
  58. package/lib/cjs/UnitConversion/nameUtils.js.map +1 -0
  59. package/lib/cjs/assets/Units.json +4215 -0
  60. package/lib/cjs/core-quantity.d.ts +15 -1
  61. package/lib/cjs/core-quantity.d.ts.map +1 -1
  62. package/lib/cjs/core-quantity.js +17 -1
  63. package/lib/cjs/core-quantity.js.map +1 -1
  64. package/lib/cjs/internal/cross-package.d.ts +4 -0
  65. package/lib/cjs/internal/cross-package.d.ts.map +1 -0
  66. package/lib/cjs/internal/cross-package.js +13 -0
  67. package/lib/cjs/internal/cross-package.js.map +1 -0
  68. package/lib/esm/BasicUnitsProvider.d.ts +44 -0
  69. package/lib/esm/BasicUnitsProvider.d.ts.map +1 -0
  70. package/lib/esm/BasicUnitsProvider.js +213 -0
  71. package/lib/esm/BasicUnitsProvider.js.map +1 -0
  72. package/lib/esm/CompositeUnitsProvider.d.ts +45 -0
  73. package/lib/esm/CompositeUnitsProvider.d.ts.map +1 -0
  74. package/lib/esm/CompositeUnitsProvider.js +108 -0
  75. package/lib/esm/CompositeUnitsProvider.js.map +1 -0
  76. package/lib/esm/Constants.js.map +1 -1
  77. package/lib/esm/Exception.js.map +1 -1
  78. package/lib/esm/FormatSpecHandle.js.map +1 -1
  79. package/lib/esm/Formatter/Format.js.map +1 -1
  80. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  81. package/lib/esm/Formatter/Formatter.js.map +1 -1
  82. package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
  83. package/lib/esm/Formatter/FormatterSpec.js +14 -0
  84. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  85. package/lib/esm/Formatter/FormattingReadyCollector.js.map +1 -1
  86. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  87. package/lib/esm/Interfaces.d.ts +14 -0
  88. package/lib/esm/Interfaces.d.ts.map +1 -1
  89. package/lib/esm/Interfaces.js.map +1 -1
  90. package/lib/esm/Parser.d.ts.map +1 -1
  91. package/lib/esm/Parser.js +16 -1
  92. package/lib/esm/Parser.js.map +1 -1
  93. package/lib/esm/ParserSpec.d.ts.map +1 -1
  94. package/lib/esm/ParserSpec.js +15 -2
  95. package/lib/esm/ParserSpec.js.map +1 -1
  96. package/lib/esm/Quantity.js.map +1 -1
  97. package/lib/esm/QuantityLoggerCategory.d.ts +3 -1
  98. package/lib/esm/QuantityLoggerCategory.d.ts.map +1 -1
  99. package/lib/esm/QuantityLoggerCategory.js +2 -0
  100. package/lib/esm/QuantityLoggerCategory.js.map +1 -1
  101. package/lib/esm/SerializedUnitSchema.d.ts +98 -0
  102. package/lib/esm/SerializedUnitSchema.d.ts.map +1 -0
  103. package/lib/esm/SerializedUnitSchema.js +22 -0
  104. package/lib/esm/SerializedUnitSchema.js.map +1 -0
  105. package/lib/esm/Unit.js.map +1 -1
  106. package/lib/esm/UnitConversion/Graph.d.ts +35 -0
  107. package/lib/esm/UnitConversion/Graph.d.ts.map +1 -0
  108. package/lib/esm/UnitConversion/Graph.js +83 -0
  109. package/lib/esm/UnitConversion/Graph.js.map +1 -0
  110. package/lib/esm/UnitConversion/Parser.d.ts +9 -0
  111. package/lib/esm/UnitConversion/Parser.d.ts.map +1 -0
  112. package/lib/esm/UnitConversion/Parser.js +39 -0
  113. package/lib/esm/UnitConversion/Parser.js.map +1 -0
  114. package/lib/esm/UnitConversion/UnitConversion.d.ts +56 -0
  115. package/lib/esm/UnitConversion/UnitConversion.d.ts.map +1 -0
  116. package/lib/esm/UnitConversion/UnitConversion.js +76 -0
  117. package/lib/esm/UnitConversion/UnitConversion.js.map +1 -0
  118. package/lib/esm/UnitConversion/UnitDefinitionResolver.d.ts +29 -0
  119. package/lib/esm/UnitConversion/UnitDefinitionResolver.d.ts.map +1 -0
  120. package/lib/esm/UnitConversion/UnitDefinitionResolver.js +98 -0
  121. package/lib/esm/UnitConversion/UnitDefinitionResolver.js.map +1 -0
  122. package/lib/esm/UnitConversion/nameUtils.d.ts +11 -0
  123. package/lib/esm/UnitConversion/nameUtils.d.ts.map +1 -0
  124. package/lib/esm/UnitConversion/nameUtils.js +21 -0
  125. package/lib/esm/UnitConversion/nameUtils.js.map +1 -0
  126. package/lib/esm/assets/Units.json +4215 -0
  127. package/lib/esm/core-quantity.d.ts +15 -1
  128. package/lib/esm/core-quantity.d.ts.map +1 -1
  129. package/lib/esm/core-quantity.js +15 -1
  130. package/lib/esm/core-quantity.js.map +1 -1
  131. package/lib/esm/internal/cross-package.d.ts +4 -0
  132. package/lib/esm/internal/cross-package.d.ts.map +1 -0
  133. package/lib/esm/internal/cross-package.js +8 -0
  134. package/lib/esm/internal/cross-package.js.map +1 -0
  135. package/package.json +6 -5
@@ -1 +1 @@
1
- {"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,QAAQ,CAAY;IACpB,YAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;IAC7D,OAAO,CAAS;IACd,sBAAsB,CAAuB,CAAC,iDAAiD;IAC/F,qBAAqB,CAAuB,CAAC,+CAA+C;IAEtG;;;;OAIG;IACH,YAAY,OAAkB,EAAE,MAAc,EAAE,WAAiC;QAC/E,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,wGAAwG;IACxG,IAAW,eAAe,KAA2B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAW,OAAO,KAAgB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,IAAW,qBAAqB,KAAsC,OAAO,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAC3G,IAAW,oBAAoB,KAAsC,OAAO,IAAI,CAAC,qBAAqB,CAAC,CAAC,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AAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;CACF","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 { Format } from \"./Formatter/Format\";\r\nimport { FormatType } from \"./Formatter/FormatEnums\";\r\nimport { AlternateUnitLabelsProvider, UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"./Interfaces\";\r\nimport { Parser, QuantityParseResult } from \"./Parser\";\r\n\r\n/** A ParserSpec holds information needed to parse a string into a quantity synchronously.\r\n * @beta\r\n */\r\nexport class ParserSpec {\r\n private _outUnit: UnitProps;\r\n private _conversions: UnitConversionSpec[] = []; // max four entries\r\n private _format: Format;\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 outUnit 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 */\r\n constructor(outUnit: UnitProps, format: Format, conversions: UnitConversionSpec[]) {\r\n this._outUnit = outUnit;\r\n this._format = format;\r\n this._conversions = conversions;\r\n }\r\n\r\n /** Returns an array of UnitConversionSpecs for each unit label that may be used in the input string. */\r\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\r\n public get format(): Format { return this._format; }\r\n public get outUnit(): UnitProps { return this._outUnit; }\r\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\r\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\r\n\r\n /** Build conversion specs for ratio format with 2 composite units (numerator/denominator). */\r\n private static async getRatioUnitConversions(units: ReadonlyArray<[UnitProps, string | undefined]>, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]> {\r\n const conversions: UnitConversionSpec[] = [];\r\n\r\n const [numeratorUnit, numeratorLabel] = units[0];\r\n const [denominatorUnit, denominatorLabel] = units[1];\r\n\r\n // Compute ratio scale: how many numerator units per denominator unit (e.g., IN:FT = 12)\r\n const denominatorToNumerator = await unitsProvider.getConversion(denominatorUnit, numeratorUnit);\r\n const displayRatioScale = denominatorToNumerator.factor;\r\n\r\n // Avoid double-scaling: if persistence unit already encodes the display ratio, use factor 1.\r\n // Check by name heuristic (e.g., IN_PER_FT with ratioUnits [IN, FT] → no scaling needed)\r\n const persistenceName = outUnit.name.toUpperCase();\r\n const numName = numeratorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\r\n const denName = denominatorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\r\n // Split by word boundaries (underscores, dots) and check for exact token matches\r\n const persistenceTokens = persistenceName.split(/[._]/);\r\n const isPersistenceMatchingRatio = persistenceTokens.includes(numName) && persistenceTokens.includes(denName);\r\n const ratioScaleFactor = isPersistenceMatchingRatio ? 1.0 : displayRatioScale;\r\n\r\n // First conversion spec: effective ratio unit conversion\r\n const ratioConversionSpec: UnitConversionSpec = {\r\n name: `${numeratorUnit.name}_per_${denominatorUnit.name}`,\r\n label: \"\",\r\n system: numeratorUnit.system,\r\n conversion: { factor: ratioScaleFactor, offset: 0.0 },\r\n };\r\n conversions.push(ratioConversionSpec);\r\n\r\n // Numerator unit for label lookup\r\n const numeratorSpec: UnitConversionSpec = {\r\n name: numeratorUnit.name,\r\n label: numeratorLabel?.length ? numeratorLabel : numeratorUnit.label,\r\n system: numeratorUnit.system,\r\n conversion: { factor: 1.0, offset: 0.0 },\r\n parseLabels: altUnitLabelsProvider?.getAlternateUnitLabels(numeratorUnit),\r\n };\r\n conversions.push(numeratorSpec);\r\n\r\n // Denominator unit for label lookup\r\n const denominatorSpec: UnitConversionSpec = {\r\n name: denominatorUnit.name,\r\n label: denominatorLabel?.length ? denominatorLabel : denominatorUnit.label,\r\n system: denominatorUnit.system,\r\n conversion: { factor: 1.0, offset: 0.0 },\r\n parseLabels: altUnitLabelsProvider?.getAlternateUnitLabels(denominatorUnit),\r\n };\r\n conversions.push(denominatorSpec);\r\n\r\n return conversions;\r\n }\r\n\r\n /** Static async method to create a ParserSpec given the format and unit of the quantity that will be passed to the Parser. 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 format The 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 outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.\r\n */\r\n public static async create(format: Format, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<ParserSpec> {\r\n let conversions: UnitConversionSpec[];\r\n\r\n // For ratio formats with 2 composite units, use private helper method\r\n if (format.type === FormatType.Ratio && format.units && format.units.length === 2) {\r\n conversions = await ParserSpec.getRatioUnitConversions(format.units, unitsProvider, outUnit, altUnitLabelsProvider);\r\n } else {\r\n conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);\r\n }\r\n\r\n const spec = new ParserSpec(outUnit, format, conversions);\r\n if (format.azimuthBaseUnit !== undefined) {\r\n if (outUnit !== undefined) {\r\n spec._azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, outUnit);\r\n } else {\r\n spec._azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n }\r\n if (format.revolutionUnit !== undefined) {\r\n if (outUnit !== undefined) {\r\n spec._revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, outUnit);\r\n } else {\r\n spec._revolutionConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n }\r\n return spec;\r\n }\r\n\r\n /** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */\r\n public parseToQuantityValue(inString: string): QuantityParseResult {\r\n return Parser.parseQuantityString(inString, this);\r\n }\r\n}\r\n\r\n"]}
1
+ {"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,QAAQ,CAAY;IACpB,YAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;IAC7D,OAAO,CAAS;IACd,sBAAsB,CAAuB,CAAC,iDAAiD;IAC/F,qBAAqB,CAAuB,CAAC,+CAA+C;IAEtG;;;;OAIG;IACH,YAAY,OAAkB,EAAE,MAAc,EAAE,WAAiC;QAC/E,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,wGAAwG;IACxG,IAAW,eAAe,KAA2B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAW,OAAO,KAAgB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,IAAW,qBAAqB,KAAsC,OAAO,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAC3G,IAAW,oBAAoB,KAAsC,OAAO,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAEzG,8FAA8F;IACtF,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,KAAqD,EAAE,aAA4B,EAAE,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Aa,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;gBAC3F,IAAI,gBAAgB,CAAC,KAAK,EAAE,CAAC;oBAC3B,MAAM,CAAC,UAAU,CAAC,sBAAsB,CAAC,OAAO,EAAE,yBAAyB,MAAM,CAAC,cAAc,CAAC,IAAI,SAAS,OAAO,CAAC,IAAI,0BAA0B,CAAC,CAAC;gBACxJ,CAAC;gBACD,IAAI,CAAC,qBAAqB,GAAG,gBAAgB,CAAC;YAChD,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,qBAAqB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC5D,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0HAA0H;IACnH,oBAAoB,CAAC,QAAgB;QAC1C,OAAO,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { Logger } from \"@itwin/core-bentley\";\nimport { Format } from \"./Formatter/Format\";\nimport { FormatType } from \"./Formatter/FormatEnums\";\nimport { AlternateUnitLabelsProvider, UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"./Interfaces\";\nimport { Parser, QuantityParseResult } from \"./Parser\";\nimport { QuantityLoggerCategory } from \"./QuantityLoggerCategory\";\n\n/** A ParserSpec holds information needed to parse a string into a quantity synchronously.\n * @beta\n */\nexport class ParserSpec {\n private _outUnit: UnitProps;\n private _conversions: UnitConversionSpec[] = []; // max four entries\n private _format: Format;\n protected _azimuthBaseConversion?: UnitConversionProps; // converts azimuth base unit to persistence unit\n protected _revolutionConversion?: UnitConversionProps; // converts revolution unit to persistence unit\n\n /** Constructor\n * @param outUnit The name of a format specification.\n * @param format Defines the output format for the quantity value.\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format..\n */\n constructor(outUnit: UnitProps, format: Format, conversions: UnitConversionSpec[]) {\n this._outUnit = outUnit;\n this._format = format;\n this._conversions = conversions;\n }\n\n /** Returns an array of UnitConversionSpecs for each unit label that may be used in the input string. */\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\n public get format(): Format { return this._format; }\n public get outUnit(): UnitProps { return this._outUnit; }\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\n\n /** Build conversion specs for ratio format with 2 composite units (numerator/denominator). */\n private static async getRatioUnitConversions(units: ReadonlyArray<[UnitProps, string | undefined]>, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]> {\n const conversions: UnitConversionSpec[] = [];\n\n const [numeratorUnit, numeratorLabel] = units[0];\n const [denominatorUnit, denominatorLabel] = units[1];\n\n // Compute ratio scale: how many numerator units per denominator unit (e.g., IN:FT = 12)\n const denominatorToNumerator = await unitsProvider.getConversion(denominatorUnit, numeratorUnit);\n if (denominatorToNumerator.error) {\n Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from \"${denominatorUnit.name}\" to \"${numeratorUnit.name}\" could not be resolved.`);\n }\n const displayRatioScale = denominatorToNumerator.factor;\n\n // Avoid double-scaling: if persistence unit already encodes the display ratio, use factor 1.\n // Check by name heuristic (e.g., IN_PER_FT with ratioUnits [IN, FT] → no scaling needed)\n const persistenceName = outUnit.name.toUpperCase();\n const numName = numeratorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\n const denName = denominatorUnit.name.toUpperCase().split(\".\").pop() ?? \"\";\n // Split by word boundaries (underscores, dots) and check for exact token matches\n const persistenceTokens = persistenceName.split(/[._]/);\n const isPersistenceMatchingRatio = persistenceTokens.includes(numName) && persistenceTokens.includes(denName);\n const ratioScaleFactor = isPersistenceMatchingRatio ? 1.0 : displayRatioScale;\n\n // First conversion spec: effective ratio unit conversion\n const ratioConversionSpec: UnitConversionSpec = {\n name: `${numeratorUnit.name}_per_${denominatorUnit.name}`,\n label: \"\",\n system: numeratorUnit.system,\n conversion: { factor: ratioScaleFactor, offset: 0.0 },\n };\n conversions.push(ratioConversionSpec);\n\n // Numerator unit for label lookup\n const numeratorSpec: UnitConversionSpec = {\n name: numeratorUnit.name,\n label: numeratorLabel?.length ? numeratorLabel : numeratorUnit.label,\n system: numeratorUnit.system,\n conversion: { factor: 1.0, offset: 0.0 },\n parseLabels: altUnitLabelsProvider?.getAlternateUnitLabels(numeratorUnit),\n };\n conversions.push(numeratorSpec);\n\n // Denominator unit for label lookup\n const denominatorSpec: UnitConversionSpec = {\n name: denominatorUnit.name,\n label: denominatorLabel?.length ? denominatorLabel : denominatorUnit.label,\n system: denominatorUnit.system,\n conversion: { factor: 1.0, offset: 0.0 },\n parseLabels: altUnitLabelsProvider?.getAlternateUnitLabels(denominatorUnit),\n };\n conversions.push(denominatorSpec);\n\n return conversions;\n }\n\n /** Static async method to create a ParserSpec given the format and unit of the quantity that will be passed to the Parser. The input unit will\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\n * async calls to lookup unit definitions.\n * @param format The format specification.\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\n * @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.\n */\n public static async create(format: Format, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<ParserSpec> {\n let conversions: UnitConversionSpec[];\n\n // For ratio formats with 2 composite units, use private helper method\n if (format.type === FormatType.Ratio && format.units && format.units.length === 2) {\n conversions = await ParserSpec.getRatioUnitConversions(format.units, unitsProvider, outUnit, altUnitLabelsProvider);\n } else {\n conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);\n }\n\n const spec = new ParserSpec(outUnit, format, conversions);\n if (format.azimuthBaseUnit !== undefined) {\n if (outUnit !== undefined) {\n const azimuthResult = await unitsProvider.getConversion(format.azimuthBaseUnit, outUnit);\n if (azimuthResult.error) {\n Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from \"${format.azimuthBaseUnit.name}\" to \"${outUnit.name}\" could not be resolved.`);\n }\n spec._azimuthBaseConversion = azimuthResult;\n } else {\n spec._azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n if (format.revolutionUnit !== undefined) {\n if (outUnit !== undefined) {\n const revolutionResult = await unitsProvider.getConversion(format.revolutionUnit, outUnit);\n if (revolutionResult.error) {\n Logger.logWarning(QuantityLoggerCategory.Parsing, `Unit conversion from \"${format.revolutionUnit.name}\" to \"${outUnit.name}\" could not be resolved.`);\n }\n spec._revolutionConversion = revolutionResult;\n } else {\n spec._revolutionConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n return spec;\n }\n\n /** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */\n public parseToQuantityValue(inString: string): QuantityParseResult {\n return Parser.parseQuantityString(inString, this);\n }\n}\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAiB,oBAAoB,EAAkC,MAAM,cAAc,CAAC;AAEnG;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,YAAoB,sBAAsB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,E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AM,IAAI,aAAa,CAAC,cAAc,CAAC,aAAa,EAAE,0BAA0B,CAAC,CAAC;IACpF,OAAO,CAAC,GAAG,KAAK,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,KAA0B;IACvE,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,8CAA8C;IAC9C,IAAI,KAAK,CAAC,SAAS,KAAK,oBAAoB,CAAC,mBAAmB,EAAE,CAAC;QACjE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,yCAAyC;IACzC,cAAc,GAAG,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IAEhE,+CAA+C;IAC/C,IAAI,KAAK,CAAC,SAAS,KAAK,oBAAoB,CAAC,oBAAoB,EAAE,CAAC;QAClE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,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\nimport { QuantityProps, UnitConversionInvert, UnitConversionProps, UnitProps } from \"./Interfaces\";\r\n\r\n/**\r\n * Checks if two numbers are approximately equal within given relative tolerance.\r\n * @param a - The first number to compare.\r\n * @param b - The second number to compare.\r\n * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).\r\n * @returns True if the numbers are approximately equal, false otherwise.\r\n * @internal\r\n */\r\nexport function almostEqual(a: number, b: number, tolerance: number = 2.2204460492503131e-16): boolean {\r\n const absDiff = Math.abs(a - b);\r\n const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;\r\n return absDiff <= scaledTolerance;\r\n}\r\n\r\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\r\n * returned as the result of parsing a string that represents a quantity.\r\n * @beta\r\n */\r\nexport class Quantity implements QuantityProps {\r\n protected _magnitude: number = 0.0;\r\n protected _unit: UnitProps;\r\n protected _isValid: boolean = false;\r\n\r\n public get unit(): UnitProps { return this._unit; }\r\n public get magnitude(): number { return this._magnitude; }\r\n public get isValid(): boolean { return this._isValid; }\r\n\r\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\r\n * @param unit Defines the quantity's unit.\r\n * @param magnitude Defines the magnitude of the quantity.\r\n */\r\n public constructor(unit?: UnitProps, magnitude?: number) {\r\n if (undefined !== unit) {\r\n this._unit = unit;\r\n this._isValid = true;\r\n } else {\r\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\r\n }\r\n\r\n if (undefined !== magnitude)\r\n this._magnitude = magnitude;\r\n }\r\n\r\n /** Convert a Quantity to the specified unit given the UnitConversion.\r\n * @param toUnit The new unit for the quantity.\r\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\r\n * returned from the UnitsProvider.\r\n */\r\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity {\r\n const newMagnitude = applyConversion(this.magnitude, conversion);\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n\r\nfunction invert(input: number): number {\r\n if (almostZero(input)) // mimic the behavior of native here. We don't want to invert those very small values\r\n throw new QuantityError(QuantityStatus.InvertingZero, \"Cannot invert zero value\");\r\n return 1 / input;\r\n}\r\n\r\n/** Determines if a value is almost zero. (less than 1e-16)\r\n * @param value - The value to be checked.\r\n * @returns `true` if the value is almost zero, `false` otherwise.\r\n * @internal\r\n */\r\nexport function almostZero(value: number): boolean {\r\n return almostEqual(value, 0.0);\r\n}\r\n\r\n/**\r\n * Applies a unit conversion to a given value.\r\n * @param value - The value to be converted.\r\n * @param props - The unit conversion properties.\r\n * @returns The converted value.\r\n * @internal\r\n */\r\nexport function applyConversion(value: number, props: UnitConversionProps): number {\r\n let convertedValue = value;\r\n\r\n // Apply pre-conversion inversion if specified\r\n if (props.inversion === UnitConversionInvert.InvertPreConversion) {\r\n convertedValue = invert(convertedValue);\r\n }\r\n\r\n // Apply the conversion factor and offset\r\n convertedValue = (convertedValue * props.factor) + props.offset;\r\n\r\n // Apply post-conversion inversion if specified\r\n if (props.inversion === UnitConversionInvert.InvertPostConversion) {\r\n convertedValue = invert(convertedValue);\r\n }\r\n\r\n return convertedValue;\r\n}\r\n"]}
1
+ {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAiB,oBAAoB,EAAkC,MAAM,cAAc,CAAC;AAEnG;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,YAAoB,sBAAsB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC1E,OAAO,OAAO,IAAI,eAAe,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACT,UAAU,GAAW,GAAG,CAAC;IACzB,KAAK,CAAY;IACjB,QAAQ,GAAY,KAAK,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Ae,CAAC,KAAa,EAAE,KAA0B;IACvE,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,8CAA8C;IAC9C,IAAI,KAAK,CAAC,SAAS,KAAK,oBAAoB,CAAC,mBAAmB,EAAE,CAAC;QACjE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,yCAAyC;IACzC,cAAc,GAAG,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IAEhE,+CAA+C;IAC/C,IAAI,KAAK,CAAC,SAAS,KAAK,oBAAoB,CAAC,oBAAoB,EAAE,CAAC;QAClE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { QuantityError, QuantityStatus } from \"./Exception\";\nimport { QuantityProps, UnitConversionInvert, UnitConversionProps, UnitProps } from \"./Interfaces\";\n\n/**\n * Checks if two numbers are approximately equal within given relative tolerance.\n * @param a - The first number to compare.\n * @param b - The second number to compare.\n * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).\n * @returns True if the numbers are approximately equal, false otherwise.\n * @internal\n */\nexport function almostEqual(a: number, b: number, tolerance: number = 2.2204460492503131e-16): boolean {\n const absDiff = Math.abs(a - b);\n const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;\n return absDiff <= scaledTolerance;\n}\n\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\n * returned as the result of parsing a string that represents a quantity.\n * @beta\n */\nexport class Quantity implements QuantityProps {\n protected _magnitude: number = 0.0;\n protected _unit: UnitProps;\n protected _isValid: boolean = false;\n\n public get unit(): UnitProps { return this._unit; }\n public get magnitude(): number { return this._magnitude; }\n public get isValid(): boolean { return this._isValid; }\n\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\n * @param unit Defines the quantity's unit.\n * @param magnitude Defines the magnitude of the quantity.\n */\n public constructor(unit?: UnitProps, magnitude?: number) {\n if (undefined !== unit) {\n this._unit = unit;\n this._isValid = true;\n } else {\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\n }\n\n if (undefined !== magnitude)\n this._magnitude = magnitude;\n }\n\n /** Convert a Quantity to the specified unit given the UnitConversion.\n * @param toUnit The new unit for the quantity.\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\n * returned from the UnitsProvider.\n */\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity {\n const newMagnitude = applyConversion(this.magnitude, conversion);\n return new Quantity(toUnit, newMagnitude);\n }\n}\n\nfunction invert(input: number): number {\n if (almostZero(input)) // mimic the behavior of native here. We don't want to invert those very small values\n throw new QuantityError(QuantityStatus.InvertingZero, \"Cannot invert zero value\");\n return 1 / input;\n}\n\n/** Determines if a value is almost zero. (less than 1e-16)\n * @param value - The value to be checked.\n * @returns `true` if the value is almost zero, `false` otherwise.\n * @internal\n */\nexport function almostZero(value: number): boolean {\n return almostEqual(value, 0.0);\n}\n\n/**\n * Applies a unit conversion to a given value.\n * @param value - The value to be converted.\n * @param props - The unit conversion properties.\n * @returns The converted value.\n * @internal\n */\nexport function applyConversion(value: number, props: UnitConversionProps): number {\n let convertedValue = value;\n\n // Apply pre-conversion inversion if specified\n if (props.inversion === UnitConversionInvert.InvertPreConversion) {\n convertedValue = invert(convertedValue);\n }\n\n // Apply the conversion factor and offset\n convertedValue = (convertedValue * props.factor) + props.offset;\n\n // Apply post-conversion inversion if specified\n if (props.inversion === UnitConversionInvert.InvertPostConversion) {\n convertedValue = invert(convertedValue);\n }\n\n return convertedValue;\n}\n"]}
@@ -9,6 +9,8 @@ export declare enum QuantityLoggerCategory {
9
9
  /** The root category for the core-quantity package. */
10
10
  Package = "core-quantity",
11
11
  /** Logger category for quantity formatting operations. */
12
- Formatting = "core-quantity.Formatting"
12
+ Formatting = "core-quantity.Formatting",
13
+ /** Logger category for quantity parsing operations. */
14
+ Parsing = "core-quantity.Parsing"
13
15
  }
14
16
  //# sourceMappingURL=QuantityLoggerCategory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"QuantityLoggerCategory.d.ts","sourceRoot":"","sources":["../../src/QuantityLoggerCategory.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;GAGG;AACH,oBAAY,sBAAsB;IAChC,uDAAuD;IACvD,OAAO,kBAAkB;IACzB,0DAA0D;IAC1D,UAAU,6BAA6B;CACxC"}
1
+ {"version":3,"file":"QuantityLoggerCategory.d.ts","sourceRoot":"","sources":["../../src/QuantityLoggerCategory.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;;GAGG;AACH,oBAAY,sBAAsB;IAChC,uDAAuD;IACvD,OAAO,kBAAkB;IACzB,0DAA0D;IAC1D,UAAU,6BAA6B;IACvC,uDAAuD;IACvD,OAAO,0BAA0B;CAClC"}
@@ -15,5 +15,7 @@ export var QuantityLoggerCategory;
15
15
  QuantityLoggerCategory["Package"] = "core-quantity";
16
16
  /** Logger category for quantity formatting operations. */
17
17
  QuantityLoggerCategory["Formatting"] = "core-quantity.Formatting";
18
+ /** Logger category for quantity parsing operations. */
19
+ QuantityLoggerCategory["Parsing"] = "core-quantity.Parsing";
18
20
  })(QuantityLoggerCategory || (QuantityLoggerCategory = {}));
19
21
  //# sourceMappingURL=QuantityLoggerCategory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"QuantityLoggerCategory.js","sourceRoot":"","sources":["../../src/QuantityLoggerCategory.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;;GAGG;AACH,MAAM,CAAN,IAAY,sBAKX;AALD,WAAY,sBAAsB;IAChC,uDAAuD;IACvD,mDAAyB,CAAA;IACzB,0DAA0D;IAC1D,iEAAuC,CAAA;AACzC,CAAC,EALW,sBAAsB,KAAtB,sBAAsB,QAKjC","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 Logging\r\n */\r\n\r\n/** Logger categories used by the `@itwin/core-quantity` package.\r\n * @see [Logger]($bentley)\r\n * @beta\r\n */\r\nexport enum QuantityLoggerCategory {\r\n /** The root category for the core-quantity package. */\r\n Package = \"core-quantity\",\r\n /** Logger category for quantity formatting operations. */\r\n Formatting = \"core-quantity.Formatting\",\r\n}\r\n"]}
1
+ {"version":3,"file":"QuantityLoggerCategory.js","sourceRoot":"","sources":["../../src/QuantityLoggerCategory.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH;;;GAGG;AACH,MAAM,CAAN,IAAY,sBAOX;AAPD,WAAY,sBAAsB;IAChC,uDAAuD;IACvD,mDAAyB,CAAA;IACzB,0DAA0D;IAC1D,iEAAuC,CAAA;IACvC,uDAAuD;IACvD,2DAAiC,CAAA;AACnC,CAAC,EAPW,sBAAsB,KAAtB,sBAAsB,QAOjC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Logging\n */\n\n/** Logger categories used by the `@itwin/core-quantity` package.\n * @see [Logger]($bentley)\n * @beta\n */\nexport enum QuantityLoggerCategory {\n /** The root category for the core-quantity package. */\n Package = \"core-quantity\",\n /** Logger category for quantity formatting operations. */\n Formatting = \"core-quantity.Formatting\",\n /** Logger category for quantity parsing operations. */\n Parsing = \"core-quantity.Parsing\",\n}\n"]}
@@ -0,0 +1,98 @@
1
+ /** Current version of the serialization format for `SerializedUnitSchema`.
2
+ *
3
+ * This value is written into `Units.json` as the `version` field and checked at
4
+ * parse time. Two version axes exist:
5
+ *
6
+ * - **Format version** (`SERIALIZED_UNIT_SCHEMA_VERSION` / `Units.json.version`): bump
7
+ * the major version when the shape of the `SerializedUnitSchema` interfaces changes
8
+ * incompatibly (e.g. renaming fields, removing required properties). Minor bumps for
9
+ * backward-compatible additions.
10
+ *
11
+ * - **Source provenance** (`sourceEcSchemaVersion` inside `Units.json`): records which
12
+ * version of the BIS Units EC schema the data was derived from (e.g. `"01.00.09"`).
13
+ * This is a traceability marker, not a runtime contract.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare const SERIALIZED_UNIT_SCHEMA_VERSION = "01.00.00";
18
+ /** A serialized constant definition (e.g. `PI`, `MILLI`).
19
+ * @internal
20
+ */
21
+ export interface SerializedConstant {
22
+ readonly schemaItemType: "Constant";
23
+ readonly label?: string;
24
+ readonly description?: string;
25
+ /** The phenomenon this constant belongs to. */
26
+ readonly phenomenon: string;
27
+ /** The unit definition expression (e.g. `"M*M"`). */
28
+ readonly definition: string;
29
+ /** Numerator of the conversion factor to the SI base. */
30
+ readonly numerator?: number;
31
+ /** Denominator of the conversion factor to the SI base. */
32
+ readonly denominator?: number;
33
+ }
34
+ /** A serialized unit definition (e.g. `M`, `FT`, `CELSIUS`).
35
+ * @internal
36
+ */
37
+ export interface SerializedUnit {
38
+ readonly schemaItemType: "Unit";
39
+ readonly label?: string;
40
+ readonly description?: string;
41
+ readonly phenomenon: string;
42
+ readonly unitSystem: string;
43
+ /** The unit definition expression (e.g. `"M*M"`). */
44
+ readonly definition: string;
45
+ /** Numerator of the conversion factor to the SI base. */
46
+ readonly numerator?: number;
47
+ /** Denominator of the conversion factor to the SI base. */
48
+ readonly denominator?: number;
49
+ /** Additive offset for the conversion (e.g. temperature scales). */
50
+ readonly offset?: number;
51
+ }
52
+ /** A serialized inverted unit definition (e.g. `HORIZONTAL_PER_VERTICAL`).
53
+ * @internal
54
+ */
55
+ export interface SerializedInvertedUnit {
56
+ readonly schemaItemType: "InvertedUnit";
57
+ readonly label?: string;
58
+ readonly description?: string;
59
+ readonly invertsUnit: string;
60
+ readonly unitSystem: string;
61
+ }
62
+ /** A serialized unit system definition (e.g. `SI`, `METRIC`).
63
+ * @internal
64
+ */
65
+ export interface SerializedUnitSystem {
66
+ readonly schemaItemType: "UnitSystem";
67
+ readonly label?: string;
68
+ readonly description?: string;
69
+ }
70
+ /** A serialized phenomenon definition (e.g. `LENGTH`, `TEMPERATURE`).
71
+ * @internal
72
+ */
73
+ export interface SerializedPhenomenon {
74
+ readonly schemaItemType: "Phenomenon";
75
+ readonly label?: string;
76
+ readonly description?: string;
77
+ /** The phenomenon definition expression. */
78
+ readonly definition: string;
79
+ }
80
+ /** Discriminated union of all serialized schema item types.
81
+ * @internal
82
+ */
83
+ export type SerializedUnitItem = SerializedConstant | SerializedUnit | SerializedInvertedUnit | SerializedUnitSystem | SerializedPhenomenon;
84
+ /** Versioned container for a serialized BIS unit schema. The `items` map is keyed by schema-item name (unqualified).
85
+ * @internal
86
+ */
87
+ export interface SerializedUnitSchema {
88
+ /** Serialization format version, matching `SERIALIZED_UNIT_SCHEMA_VERSION` (e.g. `"01.00.00"`). */
89
+ readonly version: string;
90
+ readonly name: string;
91
+ readonly alias: string;
92
+ /** EC schema version of the source BIS Units schema this data was derived from (e.g. `"01.00.09"`). */
93
+ readonly sourceEcSchemaVersion: string;
94
+ readonly items: {
95
+ readonly [name: string]: SerializedUnitItem;
96
+ };
97
+ }
98
+ //# sourceMappingURL=SerializedUnitSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SerializedUnitSchema.d.ts","sourceRoot":"","sources":["../../src/SerializedUnitSchema.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,8BAA8B,aAAa,CAAC;AAEzD;;GAEG;AACH,MAAM,WA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,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,kBAAkB,GAAG,cAAc,GAAG,sBAAsB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAE5I;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,mGAAmG;IACnG,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,uGAAuG;IACvG,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,kBAAkB,CAAA;KAAE,CAAC;CACjE"}
@@ -0,0 +1,22 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** Current version of the serialization format for `SerializedUnitSchema`.
6
+ *
7
+ * This value is written into `Units.json` as the `version` field and checked at
8
+ * parse time. Two version axes exist:
9
+ *
10
+ * - **Format version** (`SERIALIZED_UNIT_SCHEMA_VERSION` / `Units.json.version`): bump
11
+ * the major version when the shape of the `SerializedUnitSchema` interfaces changes
12
+ * incompatibly (e.g. renaming fields, removing required properties). Minor bumps for
13
+ * backward-compatible additions.
14
+ *
15
+ * - **Source provenance** (`sourceEcSchemaVersion` inside `Units.json`): records which
16
+ * version of the BIS Units EC schema the data was derived from (e.g. `"01.00.09"`).
17
+ * This is a traceability marker, not a runtime contract.
18
+ *
19
+ * @internal
20
+ */
21
+ export const SERIALIZED_UNIT_SCHEMA_VERSION = "01.00.00";
22
+ //# sourceMappingURL=SerializedUnitSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SerializedUnitSchema.js","sourceRoot":"","sources":["../../src/SerializedUnitSchema.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,UAAU,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** Current version of the serialization format for `SerializedUnitSchema`.\n *\n * This value is written into `Units.json` as the `version` field and checked at\n * parse time. Two version axes exist:\n *\n * - **Format version** (`SERIALIZED_UNIT_SCHEMA_VERSION` / `Units.json.version`): bump\n * the major version when the shape of the `SerializedUnitSchema` interfaces changes\n * incompatibly (e.g. renaming fields, removing required properties). Minor bumps for\n * backward-compatible additions.\n *\n * - **Source provenance** (`sourceEcSchemaVersion` inside `Units.json`): records which\n * version of the BIS Units EC schema the data was derived from (e.g. `\"01.00.09\"`).\n * This is a traceability marker, not a runtime contract.\n *\n * @internal\n */\nexport const SERIALIZED_UNIT_SCHEMA_VERSION = \"01.00.00\";\n\n/** A serialized constant definition (e.g. `PI`, `MILLI`).\n * @internal\n */\nexport interface SerializedConstant {\n readonly schemaItemType: \"Constant\";\n readonly label?: string;\n readonly description?: string;\n /** The phenomenon this constant belongs to. */\n readonly phenomenon: string;\n /** The unit definition expression (e.g. `\"M*M\"`). */\n readonly definition: string;\n /** Numerator of the conversion factor to the SI base. */\n readonly numerator?: number;\n /** Denominator of the conversion factor to the SI base. */\n readonly denominator?: number;\n}\n\n/** A serialized unit definition (e.g. `M`, `FT`, `CELSIUS`).\n * @internal\n */\nexport interface SerializedUnit {\n readonly schemaItemType: \"Unit\";\n readonly label?: string;\n readonly description?: string;\n readonly phenomenon: string;\n readonly unitSystem: string;\n /** The unit definition expression (e.g. `\"M*M\"`). */\n readonly definition: string;\n /** Numerator of the conversion factor to the SI base. */\n readonly numerator?: number;\n /** Denominator of the conversion factor to the SI base. */\n readonly denominator?: number;\n /** Additive offset for the conversion (e.g. temperature scales). */\n readonly offset?: number;\n}\n\n/** A serialized inverted unit definition (e.g. `HORIZONTAL_PER_VERTICAL`).\n * @internal\n */\nexport interface SerializedInvertedUnit {\n readonly schemaItemType: \"InvertedUnit\";\n readonly label?: string;\n readonly description?: string;\n readonly invertsUnit: string;\n readonly unitSystem: string;\n}\n\n/** A serialized unit system definition (e.g. `SI`, `METRIC`).\n * @internal\n */\nexport interface SerializedUnitSystem {\n readonly schemaItemType: \"UnitSystem\";\n readonly label?: string;\n readonly description?: string;\n}\n\n/** A serialized phenomenon definition (e.g. `LENGTH`, `TEMPERATURE`).\n * @internal\n */\nexport interface SerializedPhenomenon {\n readonly schemaItemType: \"Phenomenon\";\n readonly label?: string;\n readonly description?: string;\n /** The phenomenon definition expression. */\n readonly definition: string;\n}\n\n/** Discriminated union of all serialized schema item types.\n * @internal\n */\nexport type SerializedUnitItem = SerializedConstant | SerializedUnit | SerializedInvertedUnit | SerializedUnitSystem | SerializedPhenomenon;\n\n/** Versioned container for a serialized BIS unit schema. The `items` map is keyed by schema-item name (unqualified).\n * @internal\n */\nexport interface SerializedUnitSchema {\n /** Serialization format version, matching `SERIALIZED_UNIT_SCHEMA_VERSION` (e.g. `\"01.00.00\"`). */\n readonly version: string;\n readonly name: string;\n readonly alias: string;\n /** EC schema version of the source BIS Units schema this data was derived from (e.g. `\"01.00.09\"`). */\n readonly sourceEcSchemaVersion: string;\n readonly items: { readonly [name: string]: SerializedUnitItem };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../src/Unit.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;GAEG;AACH,MAAM,OAAO,SAAS;IACb,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAW,SAAS,CAAC;IAElC,YAAY,IAAY,EAAE,KAAa,EAAE,UAAkB,EAAE,MAAe;QAC1E,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,IAAI,MAAM;gBACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAAO;IACX,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAG,SAAS,CAAC;CAC3B","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\n\r\n/** This class provides basic implementation of UnitProps interface.\r\n * @beta\r\n */\r\nexport class BasicUnit implements UnitProps {\r\n public name = \"\";\r\n public label = \"\";\r\n public phenomenon = \"\";\r\n public isValid = false;\r\n public system: string = \"unknown\";\r\n\r\n constructor(name: string, label: string, phenomenon: string, system?: string) {\r\n if (name && name.length > 0 && label && label.length > 0 && phenomenon && phenomenon.length > 0) {\r\n this.name = name;\r\n this.label = label;\r\n this.phenomenon = phenomenon;\r\n this.isValid = true;\r\n if (system)\r\n this.system = system;\r\n }\r\n }\r\n}\r\n\r\n/** This class is a convenience class that can be returned when a valid Unit cannot be determined.\r\n * @beta\r\n */\r\nexport class BadUnit implements UnitProps {\r\n public name = \"\";\r\n public label = \"\";\r\n public phenomenon = \"\";\r\n public isValid = false;\r\n public system = \"unknown\";\r\n}\r\n"]}
1
+ {"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../src/Unit.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;GAEG;AACH,MAAM,OAAO,SAAS;IACb,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAW,SAAS,CAAC;IAElC,YAAY,IAAY,EAAE,KAAa,EAAE,UAAkB,EAAE,MAAe;QAC1E,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,IAAI,MAAM;gBACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAAO;IACX,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAG,SAAS,CAAC;CAC3B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { UnitProps } from \"./Interfaces\";\n\n/** This class provides basic implementation of UnitProps interface.\n * @beta\n */\nexport class BasicUnit implements UnitProps {\n public name = \"\";\n public label = \"\";\n public phenomenon = \"\";\n public isValid = false;\n public system: string = \"unknown\";\n\n constructor(name: string, label: string, phenomenon: string, system?: string) {\n if (name && name.length > 0 && label && label.length > 0 && phenomenon && phenomenon.length > 0) {\n this.name = name;\n this.label = label;\n this.phenomenon = phenomenon;\n this.isValid = true;\n if (system)\n this.system = system;\n }\n }\n}\n\n/** This class is a convenience class that can be returned when a valid Unit cannot be determined.\n * @beta\n */\nexport class BadUnit implements UnitProps {\n public name = \"\";\n public label = \"\";\n public phenomenon = \"\";\n public isValid = false;\n public system = \"unknown\";\n}\n"]}
@@ -0,0 +1,35 @@
1
+ /** @internal */
2
+ export declare class UnitConversionGraph<T> {
3
+ private _edgeKeyDelim;
4
+ private _label;
5
+ private _nodeCount;
6
+ private _edgeCount;
7
+ private _nodes;
8
+ private _edgeObjs;
9
+ private _edgeLabels;
10
+ private _outEdges;
11
+ constructor();
12
+ setGraph: (label: string) => UnitConversionGraph<T>;
13
+ graph: () => string;
14
+ nodeCount: () => number;
15
+ nodes: () => string[];
16
+ setNode: (nodeKey: string, nodeValue: T) => void;
17
+ node: (nodeKey: string) => T;
18
+ hasNode: (nodeKey: string) => boolean;
19
+ edgeCount: () => number;
20
+ edges: () => {
21
+ v: string;
22
+ w: string;
23
+ }[];
24
+ setEdge: (v: string, w: string, value: {
25
+ exponent: number;
26
+ }) => void;
27
+ edge: (v: string, w: string) => {
28
+ exponent: number;
29
+ };
30
+ outEdges: (v: string) => {
31
+ v: string;
32
+ w: string;
33
+ }[];
34
+ }
35
+ //# sourceMappingURL=Graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/Graph.ts"],"names":[],"mappings":"AA8CA,gBAAgB;AAChB,qBAAa,mBAAmB,CAAC,CAAC;IAChC,OAAO,CAAC,aAAa,CAAU;IAC/B,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,WAAW,CAAgB;IACnC,OAAO,CAAC,SAAS,CAAc;;IASxB,QAAQ,UAAW,MAAM,KAAG,mBAAmB,CAAC,CAAC,CAAC,CAGvD;IAEK,KAAK,eAEV;IAEK,SAAS,eAEd;IAEK,KAAK,iBAEV;IAEK,OAAO,YAAa,MAAM,aAAa,CAAC,UAQ7C;IAEK,IAAI,YAAa,MAAM,OAE5B;IAEK,OAAO,YAAa,MAAM,aAE/B;IAEK,SAAS,eAEd;IAEK,KAAK;WAnFP,MAAM;WACN,MAAM;QAoFT;IAEK,OAAO,MAAO,MAAM,KAAK,MAAM,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,UAiBjE;IAEK,IAAI,MAAO,MAAM,KAAK,MAAM;kBAhGP,MAAM;MAmGhC;IAEK,QAAQ,MAAO,MAAM;WA3FrB,MAAM;WACN,MAAM;QA8FX;CACH"}
@@ -0,0 +1,83 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ // Following https://github.com/dagrejs/graphlib/blob/master/lib/graph.js
6
+ /** @internal */
7
+ export class UnitConversionGraph {
8
+ _edgeKeyDelim = "\x01";
9
+ _label = "";
10
+ _nodeCount = 0;
11
+ _edgeCount = 0;
12
+ _nodes;
13
+ _edgeObjs;
14
+ _edgeLabels;
15
+ _outEdges;
16
+ constructor() {
17
+ this._nodes = {};
18
+ this._edgeObjs = {};
19
+ this._edgeLabels = {};
20
+ this._outEdges = {};
21
+ }
22
+ setGraph = (label) => {
23
+ this._label = label;
24
+ return this;
25
+ };
26
+ graph = () => {
27
+ return this._label;
28
+ };
29
+ nodeCount = () => {
30
+ return this._nodeCount;
31
+ };
32
+ nodes = () => {
33
+ return Object.keys(this._nodes);
34
+ };
35
+ setNode = (nodeKey, nodeValue) => {
36
+ if (nodeKey in this._nodes) {
37
+ this._nodes[nodeKey] = nodeValue;
38
+ return;
39
+ }
40
+ this._nodes[nodeKey] = nodeValue;
41
+ this._outEdges[nodeKey] = {};
42
+ ++this._nodeCount;
43
+ };
44
+ node = (nodeKey) => {
45
+ return this._nodes[nodeKey];
46
+ };
47
+ hasNode = (nodeKey) => {
48
+ return nodeKey in this._nodes;
49
+ };
50
+ edgeCount = () => {
51
+ return this._edgeCount;
52
+ };
53
+ edges = () => {
54
+ return Object.values(this._edgeObjs);
55
+ };
56
+ setEdge = (v, w, value) => {
57
+ const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;
58
+ if (edgeId in this._edgeLabels) {
59
+ // Update exponent, specific to this graph's use case
60
+ this._edgeLabels[edgeId].exponent += value.exponent;
61
+ return;
62
+ }
63
+ this._edgeLabels[edgeId] = value;
64
+ const edgeObj = {
65
+ v,
66
+ w,
67
+ };
68
+ this._edgeObjs[edgeId] = edgeObj;
69
+ // setNode should have ran first, so this.outEdges[v] shouldn't be undefined
70
+ this._outEdges[v][edgeId] = edgeObj;
71
+ this._edgeCount++;
72
+ };
73
+ edge = (v, w) => {
74
+ const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;
75
+ return this._edgeLabels[edgeId];
76
+ };
77
+ outEdges = (v) => {
78
+ const outV = this._outEdges[v];
79
+ const edges = Object.values(outV);
80
+ return edges;
81
+ };
82
+ }
83
+ //# sourceMappingURL=Graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../../src/UnitConversion/Graph.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,yEAAyE;AA0CzE,gBAAgB;AAChB,MAAM,OAAO,mBAAmB;IACtB,aAAa,GAAG,MAAM,CAAC;IACvB,MAAM,GAAG,EAAE,CAAC;IACZ,UAAU,GAAG,CAAC,CAAC;IACf,UAAU,GAAG,CAAC,CAAC;IACf,MAAM,CAAc;IACpB,SAAS,CAAc;IACvB,WAAW,CAAgB;IAC3B,SAAS,CAAc;IAE/B;QACE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAEM,QAAQ,GAAG,CAAC,KAAa,EAA0B,EAAE;QAC1D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;IAEK,KAAK,GAAG,GAAG,EAAE;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC,CAAC;IAEK,SAAS,GAAG,GAAG,EAAE;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC,CAAC;IAEK,KAAK,GAAG,GAAG,EAAE;QAClB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC;IAEK,OAAO,GAAG,CAAC,OAAe,EAAE,SAAY,EAAE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AAM,CAAC,GAAG,OAAO,CAAC;QACjC,4EAA4E;QAC5E,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC;QACpC,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC,CAAC;IAEK,IAAI,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC;QAC/D,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC;IAEK,QAAQ,GAAG,CAAC,CAAS,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;CACH","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n// Following https://github.com/dagrejs/graphlib/blob/master/lib/graph.js\n\n/**\n * Using generics for nodes - T represents Unit | Constant in our use case\n * @internal\n */\ninterface NodesMap<T> {\n [node: string]: T;\n}\n\n/**\n * Describe edges based on its node endpoints (v, w)\n * @internal\n */\ninterface EdgeObjsMap {\n [edge: string]: {\n v: string;\n w: string;\n };\n}\n\n/**\n * Describe edges based on the exponent they carry\n * @internal\n */\ninterface EdgeLabelsMap {\n [edge: string]: { exponent: number };\n}\n\n/**\n * List each node with outgoing edges in outer map; describe each node's outgoing edges in inner map\n * @internal\n */\ninterface OutEdgesMap {\n [node: string]: {\n [edges: string]: {\n v: string;\n w: string;\n };\n };\n}\n\n/** @internal */\nexport class UnitConversionGraph<T> {\n private _edgeKeyDelim = \"\\x01\";\n private _label = \"\";\n private _nodeCount = 0;\n private _edgeCount = 0;\n private _nodes: NodesMap<T>;\n private _edgeObjs: EdgeObjsMap;\n private _edgeLabels: EdgeLabelsMap;\n private _outEdges: OutEdgesMap;\n\n constructor() {\n this._nodes = {};\n this._edgeObjs = {};\n this._edgeLabels = {};\n this._outEdges = {};\n }\n\n public setGraph = (label: string): UnitConversionGraph<T> => {\n this._label = label;\n return this;\n };\n\n public graph = () => {\n return this._label;\n };\n\n public nodeCount = () => {\n return this._nodeCount;\n };\n\n public nodes = () => {\n return Object.keys(this._nodes);\n };\n\n public setNode = (nodeKey: string, nodeValue: T) => {\n if (nodeKey in this._nodes) {\n this._nodes[nodeKey] = nodeValue;\n return;\n }\n this._nodes[nodeKey] = nodeValue;\n this._outEdges[nodeKey] = {};\n ++this._nodeCount;\n };\n\n public node = (nodeKey: string) => {\n return this._nodes[nodeKey];\n };\n\n public hasNode = (nodeKey: string) => {\n return nodeKey in this._nodes;\n };\n\n public edgeCount = () => {\n return this._edgeCount;\n };\n\n public edges = () => {\n return Object.values(this._edgeObjs);\n };\n\n public setEdge = (v: string, w: string, value: { exponent: number }) => {\n const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;\n if (edgeId in this._edgeLabels) {\n // Update exponent, specific to this graph's use case\n this._edgeLabels[edgeId].exponent += value.exponent;\n return;\n }\n\n this._edgeLabels[edgeId] = value;\n const edgeObj = {\n v,\n w,\n };\n this._edgeObjs[edgeId] = edgeObj;\n // setNode should have ran first, so this.outEdges[v] shouldn't be undefined\n this._outEdges[v][edgeId] = edgeObj;\n this._edgeCount++;\n };\n\n public edge = (v: string, w: string) => {\n const edgeId = v + this._edgeKeyDelim + w + this._edgeKeyDelim;\n return this._edgeLabels[edgeId];\n };\n\n public outEdges = (v: string) => {\n const outV = this._outEdges[v];\n const edges = Object.values(outV);\n return edges;\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /** @internal */
2
+ export interface DefinitionFragment {
3
+ name: string;
4
+ exponent: number;
5
+ constant: boolean;
6
+ }
7
+ /** @internal */
8
+ export declare function parseDefinition(definition: string): Map<string, DefinitionFragment>;
9
+ //# sourceMappingURL=Parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":"AAeA,gBAAgB;AAChB,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAsBnF"}
@@ -0,0 +1,39 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ const expressionRgx = /^(([A-Z]\w*:)?([A-Z]\w*|\[([A-Z]\w*:)?[A-Z]\w*\])(\(-?\d+\))?(\*(?!$)|$))+$/i;
6
+ const tokenRgx = /(?:(\[)?((?:[A-Z]\w*:)?[A-Z]\w*)\]?)(?:\((-?\d+)\))?/i;
7
+ const sp = "*";
8
+ /** @internal */
9
+ var Tokens;
10
+ (function (Tokens) {
11
+ Tokens[Tokens["Bracket"] = 1] = "Bracket";
12
+ Tokens[Tokens["Word"] = 2] = "Word";
13
+ Tokens[Tokens["Exponent"] = 3] = "Exponent";
14
+ })(Tokens || (Tokens = {}));
15
+ /** @internal */
16
+ export function parseDefinition(definition) {
17
+ const unitMap = new Map();
18
+ if (expressionRgx.test(definition)) {
19
+ for (const unit of definition.split(sp)) {
20
+ const tokens = unit.split(tokenRgx);
21
+ const name = tokens[Tokens.Word];
22
+ const exponent = tokens[Tokens.Exponent] ? Number(tokens[Tokens.Exponent]) : 1;
23
+ const constant = tokens[Tokens.Bracket] !== undefined;
24
+ if (unitMap.has(name)) {
25
+ const currentDefinition = unitMap.get(name);
26
+ if (currentDefinition)
27
+ unitMap.set(name, { ...currentDefinition, exponent: currentDefinition.exponent + exponent });
28
+ }
29
+ else {
30
+ unitMap.set(name, { name, exponent, constant });
31
+ }
32
+ }
33
+ return unitMap;
34
+ }
35
+ else {
36
+ throw new Error("Invalid definition expression.");
37
+ }
38
+ }
39
+ //# sourceMappingURL=Parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../../src/UnitConversion/Parser.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,MAAM,aAAa,GAAG,8EAA8E,CAAC;AACrG,MAAM,QAAQ,GAAG,uDAAuD,CAAC;AACzE,MAAM,EAAE,GAAG,GAAG,CAAC;AAEf,gBAAgB;AAChB,IAAK,MAIJ;AAJD,WAAK,MAAM;IACT,yCAAW,CAAA;IACX,mCAAQ,CAAA;IACR,2CAAY,CAAA;AACd,CAAC,EAJI,MAAM,KAAN,MAAM,QAIV;AASD,gBAAgB;AAChB,MAAM,UAAU,eAAe,CAAC,UAAkB;IAChD,MAAM,OAAO,GAAoC,IAAI,GAAG,EAAE,CAAC;IAE3D,IAAI,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/E,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS,CAAC;YACtD,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACtB,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC5C,IAAI,iBAAiB;oBACnB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,iBAAiB,EAAE,QAAQ,EAAE,iBAAiB,CAAC,QAAQ,GAAG,QAAQ,EAAE,CAAC,CAAC;YACjG,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;YAClD,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nconst expressionRgx = /^(([A-Z]\\w*:)?([A-Z]\\w*|\\[([A-Z]\\w*:)?[A-Z]\\w*\\])(\\(-?\\d+\\))?(\\*(?!$)|$))+$/i;\nconst tokenRgx = /(?:(\\[)?((?:[A-Z]\\w*:)?[A-Z]\\w*)\\]?)(?:\\((-?\\d+)\\))?/i;\nconst sp = \"*\";\n\n/** @internal */\nenum Tokens {\n Bracket = 1,\n Word = 2,\n Exponent = 3,\n}\n\n/** @internal */\nexport interface DefinitionFragment {\n name: string;\n exponent: number;\n constant: boolean;\n}\n\n/** @internal */\nexport function parseDefinition(definition: string): Map<string, DefinitionFragment> {\n const unitMap: Map<string, DefinitionFragment> = new Map();\n\n if (expressionRgx.test(definition)) {\n for (const unit of definition.split(sp)) {\n const tokens = unit.split(tokenRgx);\n const name = tokens[Tokens.Word];\n const exponent = tokens[Tokens.Exponent] ? Number(tokens[Tokens.Exponent]) : 1;\n const constant = tokens[Tokens.Bracket] !== undefined;\n if (unitMap.has(name)) {\n const currentDefinition = unitMap.get(name);\n if (currentDefinition)\n unitMap.set(name, { ...currentDefinition, exponent: currentDefinition.exponent + exponent });\n } else {\n unitMap.set(name, { name, exponent, constant });\n }\n }\n\n return unitMap;\n } else {\n throw new Error(\"Invalid definition expression.\");\n }\n}\n"]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Structural interface satisfied by any object that carries a numerator/denominator
3
+ * factor and an optional offset — for example, the EC `Unit` and `Constant` classes in
4
+ * `@itwin/ecschema-metadata`.
5
+ * @internal
6
+ */
7
+ export interface UnitConversionSource {
8
+ readonly numerator: number;
9
+ readonly denominator: number;
10
+ readonly offset?: number;
11
+ }
12
+ /**
13
+ * Class used for storing calculated conversion between two Units and converting values from one Unit to another.
14
+ * @internal
15
+ */
16
+ export declare class UnitConversion {
17
+ readonly factor: number;
18
+ readonly offset: number;
19
+ constructor(factor?: number, offset?: number);
20
+ /**
21
+ * Converts x using UnitConversion
22
+ * @param x Input magnitude to be converted
23
+ * @returns Output magnitude after conversion
24
+ */
25
+ evaluate(x: number): number;
26
+ /**
27
+ * Used to invert source's UnitConversion so that it can be composed with target's UnitConversion cleanly
28
+ * @internal
29
+ */
30
+ inverse(): UnitConversion;
31
+ /**
32
+ * Combines two UnitConversions
33
+ * Used to combine source's UnitConversion and target's UnitConversion for a final UnitConversion that can be evaluated
34
+ * @internal
35
+ */
36
+ compose(conversion: UnitConversion): UnitConversion;
37
+ /**
38
+ * Multiples two UnitConversions together to calculate factor during reducing
39
+ * @internal
40
+ */
41
+ multiply(conversion: UnitConversion): UnitConversion;
42
+ /**
43
+ * Raise UnitConversion's factor with power exponent to calculate factor during reducing
44
+ * @internal
45
+ */
46
+ raise(power: number): UnitConversion;
47
+ /** @internal */
48
+ static identity: UnitConversion;
49
+ /**
50
+ * Returns UnitConversion with source's numerator and denominator in factor and source's offset in offset for reducing.
51
+ * Accepts any object that structurally satisfies `UnitConversionSource` (e.g. EC `Unit` or `Constant`).
52
+ * @internal
53
+ */
54
+ static from(source: UnitConversionSource): UnitConversion;
55
+ }
56
+ //# sourceMappingURL=UnitConversion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UnitConversion.d.ts","sourceRoot":"","sources":["../../../src/UnitConversion/UnitConversion.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,qBAAa,cAAc;aACG,MAAM,EAAE,MAAM;aAAwB,MAAM,EAAE,MAAM;gBAApD,MAAM,GAAE,MAAY,EAAkB,MAAM,GAAE,MAAY;IAEtF;;;;OAIG;IACI,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAIlC;;;OAGG;IACI,OAAO,IAAI,cAAc;IAKhC;;;;OAIG;IACI,OAAO,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc;IAO1D;;;OAGG;IACI,QAAQ,CAAC,UAAU,EAAE,cAAc,GAAG,cAAc;IAO3D;;;OAGG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc;IAY3C,gBAAgB;IAChB,OAAc,QAAQ,iBAAwB;IAE9C;;;;OAIG;WACW,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc;CAKjE"}
@@ -0,0 +1,76 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { almostEqual } from "../Quantity";
6
+ /**
7
+ * Class used for storing calculated conversion between two Units and converting values from one Unit to another.
8
+ * @internal
9
+ */
10
+ export class UnitConversion {
11
+ factor;
12
+ offset;
13
+ constructor(factor = 1.0, offset = 0.0) {
14
+ this.factor = factor;
15
+ this.offset = offset;
16
+ }
17
+ /**
18
+ * Converts x using UnitConversion
19
+ * @param x Input magnitude to be converted
20
+ * @returns Output magnitude after conversion
21
+ */
22
+ evaluate(x) {
23
+ return this.factor * x + this.offset;
24
+ }
25
+ /**
26
+ * Used to invert source's UnitConversion so that it can be composed with target's UnitConversion cleanly
27
+ * @internal
28
+ */
29
+ inverse() {
30
+ const inverseFactor = 1.0 / this.factor;
31
+ return new UnitConversion(inverseFactor, -this.offset * inverseFactor);
32
+ }
33
+ /**
34
+ * Combines two UnitConversions
35
+ * Used to combine source's UnitConversion and target's UnitConversion for a final UnitConversion that can be evaluated
36
+ * @internal
37
+ */
38
+ compose(conversion) {
39
+ return new UnitConversion(this.factor * conversion.factor, conversion.factor * this.offset + conversion.offset);
40
+ }
41
+ /**
42
+ * Multiples two UnitConversions together to calculate factor during reducing
43
+ * @internal
44
+ */
45
+ multiply(conversion) {
46
+ if (almostEqual(conversion.offset, 0.0) && almostEqual(this.offset, 0.0))
47
+ return new UnitConversion(this.factor * conversion.factor, 0.0);
48
+ throw new Error("Cannot multiply two maps with non-zero offsets");
49
+ }
50
+ /**
51
+ * Raise UnitConversion's factor with power exponent to calculate factor during reducing
52
+ * @internal
53
+ */
54
+ raise(power) {
55
+ if (almostEqual(power, 1.0))
56
+ return new UnitConversion(this.factor, this.offset);
57
+ else if (almostEqual(power, 0.0))
58
+ return new UnitConversion(1.0, 0.0);
59
+ if (almostEqual(this.offset, 0.0))
60
+ return new UnitConversion(this.factor ** power, 0.0);
61
+ throw new Error("Cannot raise map with non-zero offset");
62
+ }
63
+ /** @internal */
64
+ static identity = new UnitConversion();
65
+ /**
66
+ * Returns UnitConversion with source's numerator and denominator in factor and source's offset in offset for reducing.
67
+ * Accepts any object that structurally satisfies `UnitConversionSource` (e.g. EC `Unit` or `Constant`).
68
+ * @internal
69
+ */
70
+ static from(source) {
71
+ const offset = source.offset ?? 0;
72
+ const hasOffset = !almostEqual(offset, 0.0);
73
+ return new UnitConversion(source.denominator / source.numerator, hasOffset ? -offset : 0.0);
74
+ }
75
+ }
76
+ //# sourceMappingURL=UnitConversion.js.map