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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/lib/cjs/Constants.js.map +1 -1
  3. package/lib/cjs/Exception.d.ts +3 -1
  4. package/lib/cjs/Exception.d.ts.map +1 -1
  5. package/lib/cjs/Exception.js +2 -0
  6. package/lib/cjs/Exception.js.map +1 -1
  7. package/lib/cjs/Formatter/Format.d.ts +14 -0
  8. package/lib/cjs/Formatter/Format.d.ts.map +1 -1
  9. package/lib/cjs/Formatter/Format.js +58 -0
  10. package/lib/cjs/Formatter/Format.js.map +1 -1
  11. package/lib/cjs/Formatter/FormatEnums.d.ts +5 -1
  12. package/lib/cjs/Formatter/FormatEnums.d.ts.map +1 -1
  13. package/lib/cjs/Formatter/FormatEnums.js +10 -0
  14. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  15. package/lib/cjs/Formatter/Formatter.d.ts +4 -0
  16. package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
  17. package/lib/cjs/Formatter/Formatter.js +114 -13
  18. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  19. package/lib/cjs/Formatter/FormatterSpec.d.ts +8 -2
  20. package/lib/cjs/Formatter/FormatterSpec.d.ts.map +1 -1
  21. package/lib/cjs/Formatter/FormatterSpec.js +26 -2
  22. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  23. package/lib/cjs/Formatter/Interfaces.d.ts +11 -0
  24. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  25. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  26. package/lib/cjs/Interfaces.js.map +1 -1
  27. package/lib/cjs/Parser.d.ts +7 -1
  28. package/lib/cjs/Parser.d.ts.map +1 -1
  29. package/lib/cjs/Parser.js +158 -4
  30. package/lib/cjs/Parser.js.map +1 -1
  31. package/lib/cjs/ParserSpec.d.ts +5 -1
  32. package/lib/cjs/ParserSpec.d.ts.map +1 -1
  33. package/lib/cjs/ParserSpec.js +20 -1
  34. package/lib/cjs/ParserSpec.js.map +1 -1
  35. package/lib/cjs/Quantity.d.ts +9 -0
  36. package/lib/cjs/Quantity.d.ts.map +1 -1
  37. package/lib/cjs/Quantity.js +15 -1
  38. package/lib/cjs/Quantity.js.map +1 -1
  39. package/lib/cjs/Unit.js.map +1 -1
  40. package/lib/cjs/core-quantity.js.map +1 -1
  41. package/lib/esm/Constants.js.map +1 -1
  42. package/lib/esm/Exception.d.ts +3 -1
  43. package/lib/esm/Exception.d.ts.map +1 -1
  44. package/lib/esm/Exception.js +2 -0
  45. package/lib/esm/Exception.js.map +1 -1
  46. package/lib/esm/Formatter/Format.d.ts +14 -0
  47. package/lib/esm/Formatter/Format.d.ts.map +1 -1
  48. package/lib/esm/Formatter/Format.js +59 -1
  49. package/lib/esm/Formatter/Format.js.map +1 -1
  50. package/lib/esm/Formatter/FormatEnums.d.ts +5 -1
  51. package/lib/esm/Formatter/FormatEnums.d.ts.map +1 -1
  52. package/lib/esm/Formatter/FormatEnums.js +10 -0
  53. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  54. package/lib/esm/Formatter/Formatter.d.ts +4 -0
  55. package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
  56. package/lib/esm/Formatter/Formatter.js +114 -13
  57. package/lib/esm/Formatter/Formatter.js.map +1 -1
  58. package/lib/esm/Formatter/FormatterSpec.d.ts +8 -2
  59. package/lib/esm/Formatter/FormatterSpec.d.ts.map +1 -1
  60. package/lib/esm/Formatter/FormatterSpec.js +26 -2
  61. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  62. package/lib/esm/Formatter/Interfaces.d.ts +11 -0
  63. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  64. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  65. package/lib/esm/Interfaces.js.map +1 -1
  66. package/lib/esm/Parser.d.ts +7 -1
  67. package/lib/esm/Parser.d.ts.map +1 -1
  68. package/lib/esm/Parser.js +158 -4
  69. package/lib/esm/Parser.js.map +1 -1
  70. package/lib/esm/ParserSpec.d.ts +5 -1
  71. package/lib/esm/ParserSpec.d.ts.map +1 -1
  72. package/lib/esm/ParserSpec.js +20 -1
  73. package/lib/esm/ParserSpec.js.map +1 -1
  74. package/lib/esm/Quantity.d.ts +9 -0
  75. package/lib/esm/Quantity.d.ts.map +1 -1
  76. package/lib/esm/Quantity.js +13 -0
  77. package/lib/esm/Quantity.js.map +1 -1
  78. package/lib/esm/Unit.js.map +1 -1
  79. package/lib/esm/core-quantity.js.map +1 -1
  80. package/package.json +5 -5
@@ -25,6 +25,8 @@ export class ParserSpec {
25
25
  get unitConversions() { return this._conversions; }
26
26
  get format() { return this._format; }
27
27
  get outUnit() { return this._outUnit; }
28
+ get azimuthBaseConversion() { return this._azimuthBaseConversion; }
29
+ get revolutionConversion() { return this._revolutionConversion; }
28
30
  /** 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
29
31
  * 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
30
32
  * async calls to lookup unit definitions.
@@ -34,7 +36,24 @@ export class ParserSpec {
34
36
  */
35
37
  static async create(format, unitsProvider, outUnit, altUnitLabelsProvider) {
36
38
  const conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);
37
- return new ParserSpec(outUnit, format, conversions);
39
+ const spec = new ParserSpec(outUnit, format, conversions);
40
+ if (format.azimuthBaseUnit !== undefined) {
41
+ if (outUnit !== undefined) {
42
+ spec._azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, outUnit);
43
+ }
44
+ else {
45
+ spec._azimuthBaseConversion = { factor: 1.0, offset: 0.0 };
46
+ }
47
+ }
48
+ if (format.revolutionUnit !== undefined) {
49
+ if (outUnit !== undefined) {
50
+ spec._revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, outUnit);
51
+ }
52
+ else {
53
+ spec._revolutionConversion = { factor: 1.0, offset: 0.0 };
54
+ }
55
+ }
56
+ return spec;
38
57
  }
39
58
  /** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */
40
59
  parseToQuantityValue(inString) {
@@ -1 +1 @@
1
- {"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,UAAU;IAKrB;;;;OAIG;IACH,YAAY,OAAkB,EAAE,MAAc,EAAE,WAAiC;QARzE,iBAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;QASnE,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;IAEzD;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,aAA4B,EAAE,OAAkB,EAAE,qBAAmD;QAC9I,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,aAAa,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC;QACjH,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;IACtD,CAAC;IAED,0HAA0H;IACnH,oBAAoB,CAAC,QAAgB;QAC1C,OAAO,MAAM,CAAC,mBAAmB,CAAC,QAAQ,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 { AlternateUnitLabelsProvider, 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\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\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 the value to be formatted. 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 const conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);\r\n return new ParserSpec(outUnit, format, conversions);\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;AAIH,OAAO,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,UAAU;IAOrB;;;;OAIG;IACH,YAAY,OAAkB,EAAE,MAAc,EAAE,WAAiC;QAVzE,iBAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;QAWnE,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;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,aAA4B,EAAE,OAAkB,EAAE,qBAAmD;QAC9I,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,aAAa,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC;QACjH,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,sBAAsB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACnG,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,sBAAsB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,qBAAqB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YACjG,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 { Format } from \"./Formatter/Format\";\nimport { AlternateUnitLabelsProvider, UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"./Interfaces\";\nimport { Parser, QuantityParseResult } from \"./Parser\";\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 /** 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 the value to be formatted. 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 const conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);\n const spec = new ParserSpec(outUnit, format, conversions);\n if (format.azimuthBaseUnit !== undefined) {\n if (outUnit !== undefined) {\n spec._azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, outUnit);\n } else {\n spec._azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n if (format.revolutionUnit !== undefined) {\n if (outUnit !== undefined) {\n spec._revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, outUnit);\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"]}
@@ -2,6 +2,15 @@
2
2
  * @module Quantity
3
3
  */
4
4
  import { QuantityProps, UnitConversionProps, UnitProps } from "./Interfaces";
5
+ /**
6
+ * Checks if two numbers are approximately equal within given relative tolerance.
7
+ * @param a - The first number to compare.
8
+ * @param b - The second number to compare.
9
+ * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).
10
+ * @returns True if the numbers are approximately equal, false otherwise.
11
+ * @internal
12
+ */
13
+ export declare function almostEqual(a: number, b: number, tolerance?: number): boolean;
5
14
  /** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly
6
15
  * returned as the result of parsing a string that represents a quantity.
7
16
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.d.ts","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7E;;;GAGG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAO;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEpC,IAAW,IAAI,IAAI,SAAS,CAAuB;IACnD,IAAW,SAAS,IAAI,MAAM,CAA4B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IAEvD;;;OAGG;gBACgB,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAYvD;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,GAAG,QAAQ,GAAG,SAAS;CAI3F"}
1
+ {"version":3,"file":"Quantity.d.ts","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE7E;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,SAAS,GAAE,MAA+B,GAAG,OAAO,CAIrG;AAED;;;GAGG;AACH,qBAAa,QAAS,YAAW,aAAa;IAC5C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAO;IACnC,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC;IAC3B,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAS;IAEpC,IAAW,IAAI,IAAI,SAAS,CAAuB;IACnD,IAAW,SAAS,IAAI,MAAM,CAA4B;IAC1D,IAAW,OAAO,IAAI,OAAO,CAA0B;IAEvD;;;OAGG;gBACgB,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM;IAYvD;;;;OAIG;IACI,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,mBAAmB,GAAG,QAAQ,GAAG,SAAS;CAI3F"}
@@ -5,6 +5,19 @@
5
5
  /** @packageDocumentation
6
6
  * @module Quantity
7
7
  */
8
+ /**
9
+ * Checks if two numbers are approximately equal within given relative tolerance.
10
+ * @param a - The first number to compare.
11
+ * @param b - The second number to compare.
12
+ * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).
13
+ * @returns True if the numbers are approximately equal, false otherwise.
14
+ * @internal
15
+ */
16
+ export function almostEqual(a, b, tolerance = 2.2204460492503131e-16) {
17
+ const absDiff = Math.abs(a - b);
18
+ const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;
19
+ return absDiff <= scaledTolerance;
20
+ }
8
21
  /** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly
9
22
  * returned as the result of parsing a string that represents a quantity.
10
23
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAKnB,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QAZ7C,eAAU,GAAW,GAAG,CAAC;QAEzB,aAAQ,GAAY,KAAK,CAAC;QAWlC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAiB,EAAE,UAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;QAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,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 { QuantityProps, UnitConversionProps, UnitProps } from \"./Interfaces\";\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 | undefined {\r\n const newMagnitude = (this.magnitude * conversion.factor) + conversion.offset;\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;;;;;;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;IAKnB,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QAZ7C,eAAU,GAAW,GAAG,CAAC;QAEzB,aAAQ,GAAY,KAAK,CAAC;QAWlC,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAC/G,CAAC;QAED,IAAI,SAAS,KAAK,SAAS;YACzB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,MAAiB,EAAE,UAA+B;QACjE,MAAM,YAAY,GAAG,CAAC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,MAAM,CAAC;QAC9E,OAAO,IAAI,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC5C,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 { QuantityProps, 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 | undefined {\n const newMagnitude = (this.magnitude * conversion.factor) + conversion.offset;\n return new Quantity(toUnit, newMagnitude);\n }\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;IAOpB,YAAY,IAAY,EAAE,KAAa,EAAE,UAAkB,EAAE,MAAe;QANrE,SAAI,GAAG,EAAE,CAAC;QACV,UAAK,GAAG,EAAE,CAAC;QACX,eAAU,GAAG,EAAE,CAAC;QAChB,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAAW,SAAS,CAAC;QAGhC,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;IAApB;QACS,SAAI,GAAG,EAAE,CAAC;QACV,UAAK,GAAG,EAAE,CAAC;QACX,eAAU,GAAG,EAAE,CAAC;QAChB,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAAG,SAAS,CAAC;IAC5B,CAAC;CAAA","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;IAOpB,YAAY,IAAY,EAAE,KAAa,EAAE,UAAkB,EAAE,MAAe;QANrE,SAAI,GAAG,EAAE,CAAC;QACV,UAAK,GAAG,EAAE,CAAC;QACX,eAAU,GAAG,EAAE,CAAC;QAChB,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAAW,SAAS,CAAC;QAGhC,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;IAApB;QACS,SAAI,GAAG,EAAE,CAAC;QACV,UAAK,GAAG,EAAE,CAAC;QACX,eAAU,GAAG,EAAE,CAAC;QAChB,YAAO,GAAG,KAAK,CAAC;QAChB,WAAM,GAAG,SAAS,CAAC;IAC5B,CAAC;CAAA","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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"core-quantity.js","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AAEvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC;;GAEG;AAEH;;;GAGG","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\nexport * from \"./Constants\";\r\nexport * from \"./Exception\";\r\nexport * from \"./Interfaces\";\r\nexport * from \"./Parser\";\r\nexport * from \"./ParserSpec\";\r\nexport * from \"./Quantity\";\r\nexport * from \"./Unit\";\r\n\r\nexport * from \"./Formatter/Format\";\r\nexport * from \"./Formatter/FormatterSpec\";\r\nexport * from \"./Formatter/FormatEnums\";\r\nexport * from \"./Formatter/Formatter\";\r\nexport * from \"./Formatter/Interfaces\";\r\n\r\n/** @docs-package-description\r\n * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.\r\n */\r\n\r\n/**\r\n * @docs-group-description Quantity\r\n * Classes, Interfaces, and definitions used to format and parse quantity values.\r\n */\r\n"]}
1
+ {"version":3,"file":"core-quantity.js","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AAEvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC;;GAEG;AAEH;;;GAGG","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*--------------------------------------------------------------------------------------------*/\nexport * from \"./Constants\";\nexport * from \"./Exception\";\nexport * from \"./Interfaces\";\nexport * from \"./Parser\";\nexport * from \"./ParserSpec\";\nexport * from \"./Quantity\";\nexport * from \"./Unit\";\n\nexport * from \"./Formatter/Format\";\nexport * from \"./Formatter/FormatterSpec\";\nexport * from \"./Formatter/FormatEnums\";\nexport * from \"./Formatter/Formatter\";\nexport * from \"./Formatter/Interfaces\";\n\n/** @docs-package-description\n * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.\n */\n\n/**\n * @docs-group-description Quantity\n * Classes, Interfaces, and definitions used to format and parse quantity values.\n */\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-quantity",
3
- "version": "4.9.0-dev.8",
3
+ "version": "4.10.0-dev.0",
4
4
  "description": "Quantity parsing, formatting and conversions for iModel.js",
5
5
  "main": "lib/cjs/core-quantity.js",
6
6
  "module": "lib/esm/core-quantity.js",
@@ -33,13 +33,13 @@
33
33
  "mocha": "^10.2.0",
34
34
  "nyc": "^15.1.0",
35
35
  "rimraf": "^3.0.2",
36
- "sinon": "^17.0.1",
36
+ "sinon": "^17.0.2",
37
37
  "typescript": "~5.3.3",
38
- "@itwin/build-tools": "4.9.0-dev.8",
39
- "@itwin/core-bentley": "4.9.0-dev.8"
38
+ "@itwin/build-tools": "4.10.0-dev.0",
39
+ "@itwin/core-bentley": "4.10.0-dev.0"
40
40
  },
41
41
  "peerDependencies": {
42
- "@itwin/core-bentley": "^4.9.0-dev.8"
42
+ "@itwin/core-bentley": "^4.10.0-dev.0"
43
43
  },
44
44
  "nyc": {
45
45
  "extends": "./node_modules/@itwin/build-tools/.nycrc"