@itwin/core-quantity 4.10.0-dev.2 → 4.10.0-dev.20

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 (74) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/lib/cjs/Constants.js.map +1 -1
  3. package/lib/cjs/Exception.d.ts +2 -1
  4. package/lib/cjs/Exception.d.ts.map +1 -1
  5. package/lib/cjs/Exception.js +1 -0
  6. package/lib/cjs/Exception.js.map +1 -1
  7. package/lib/cjs/Formatter/Format.d.ts +5 -2
  8. package/lib/cjs/Formatter/Format.d.ts.map +1 -1
  9. package/lib/cjs/Formatter/Format.js +18 -24
  10. package/lib/cjs/Formatter/Format.js.map +1 -1
  11. package/lib/cjs/Formatter/FormatEnums.d.ts +17 -1
  12. package/lib/cjs/Formatter/FormatEnums.d.ts.map +1 -1
  13. package/lib/cjs/Formatter/FormatEnums.js +33 -1
  14. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  15. package/lib/cjs/Formatter/Formatter.d.ts +1 -0
  16. package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
  17. package/lib/cjs/Formatter/Formatter.js +70 -22
  18. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  19. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  20. package/lib/cjs/Formatter/Interfaces.d.ts +2 -0
  21. package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
  22. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  23. package/lib/cjs/Interfaces.d.ts +13 -0
  24. package/lib/cjs/Interfaces.d.ts.map +1 -1
  25. package/lib/cjs/Interfaces.js +11 -0
  26. package/lib/cjs/Interfaces.js.map +1 -1
  27. package/lib/cjs/Parser.d.ts +2 -0
  28. package/lib/cjs/Parser.d.ts.map +1 -1
  29. package/lib/cjs/Parser.js +65 -16
  30. package/lib/cjs/Parser.js.map +1 -1
  31. package/lib/cjs/ParserSpec.js.map +1 -1
  32. package/lib/cjs/Quantity.d.ts +14 -0
  33. package/lib/cjs/Quantity.d.ts.map +1 -1
  34. package/lib/cjs/Quantity.js +40 -2
  35. package/lib/cjs/Quantity.js.map +1 -1
  36. package/lib/cjs/Unit.js.map +1 -1
  37. package/lib/cjs/core-quantity.js.map +1 -1
  38. package/lib/esm/Constants.js.map +1 -1
  39. package/lib/esm/Exception.d.ts +2 -1
  40. package/lib/esm/Exception.d.ts.map +1 -1
  41. package/lib/esm/Exception.js +1 -0
  42. package/lib/esm/Exception.js.map +1 -1
  43. package/lib/esm/Formatter/Format.d.ts +5 -2
  44. package/lib/esm/Formatter/Format.d.ts.map +1 -1
  45. package/lib/esm/Formatter/Format.js +19 -25
  46. package/lib/esm/Formatter/Format.js.map +1 -1
  47. package/lib/esm/Formatter/FormatEnums.d.ts +17 -1
  48. package/lib/esm/Formatter/FormatEnums.d.ts.map +1 -1
  49. package/lib/esm/Formatter/FormatEnums.js +31 -0
  50. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  51. package/lib/esm/Formatter/Formatter.d.ts +1 -0
  52. package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
  53. package/lib/esm/Formatter/Formatter.js +72 -24
  54. package/lib/esm/Formatter/Formatter.js.map +1 -1
  55. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  56. package/lib/esm/Formatter/Interfaces.d.ts +2 -0
  57. package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
  58. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  59. package/lib/esm/Interfaces.d.ts +13 -0
  60. package/lib/esm/Interfaces.d.ts.map +1 -1
  61. package/lib/esm/Interfaces.js +10 -1
  62. package/lib/esm/Interfaces.js.map +1 -1
  63. package/lib/esm/Parser.d.ts +2 -0
  64. package/lib/esm/Parser.d.ts.map +1 -1
  65. package/lib/esm/Parser.js +66 -17
  66. package/lib/esm/Parser.js.map +1 -1
  67. package/lib/esm/ParserSpec.js.map +1 -1
  68. package/lib/esm/Quantity.d.ts +14 -0
  69. package/lib/esm/Quantity.d.ts.map +1 -1
  70. package/lib/esm/Quantity.js +37 -1
  71. package/lib/esm/Quantity.js.map +1 -1
  72. package/lib/esm/Unit.js.map +1 -1
  73. package/lib/esm/core-quantity.js.map +1 -1
  74. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAyDH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { UnitProps } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n readonly type: string;\r\n readonly precision?: number;\r\n readonly roundFactor?: number;\r\n readonly minWidth?: number;\r\n readonly showSignOption?: string;\r\n readonly formatTraits?: string | string[];\r\n readonly decimalSeparator?: string;\r\n readonly thousandSeparator?: string;\r\n readonly uomSeparator?: string;\r\n\r\n /** conditionally required. */\r\n readonly scientificType?: string;\r\n\r\n /** conditionally required. */\r\n readonly stationOffsetSize?: number;\r\n readonly stationSeparator?: string;\r\n\r\n /** The base value for azimuth, specified from east counter-clockwise. */\r\n readonly azimuthBase?: number;\r\n\r\n /** The name of the unit for the azimuth base value. */\r\n readonly azimuthBaseUnit?: string;\r\n\r\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\r\n readonly azimuthCounterClockwise?: boolean;\r\n\r\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\r\n readonly revolutionUnit?: string;\r\n\r\n readonly allowMathematicOperations?: boolean;\r\n readonly composite?: {\r\n /** separates values when formatting composite strings */\r\n readonly spacer?: string;\r\n readonly includeZero?: boolean;\r\n readonly units: Array<{\r\n readonly name: string;\r\n readonly label?: string;\r\n }>;\r\n };\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AA4DH;;GAEG;AACI,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,CAAC;AAFW,QAAA,mBAAmB,uBAE9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\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\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\n\n/** This interface defines the persistence format for describing the formatting of quantity values.\n * @beta\n */\nexport interface FormatProps {\n readonly type: string;\n readonly precision?: number;\n readonly roundFactor?: number;\n readonly minWidth?: number;\n readonly showSignOption?: string;\n readonly formatTraits?: string | string[];\n readonly decimalSeparator?: string;\n readonly thousandSeparator?: string;\n readonly uomSeparator?: string;\n\n /** conditionally required. */\n readonly scientificType?: string;\n\n /** conditionally required. */\n readonly ratioType?: string;\n\n /** conditionally required. */\n readonly stationOffsetSize?: number;\n readonly stationSeparator?: string;\n\n /** The base value for azimuth, specified from east counter-clockwise. */\n readonly azimuthBase?: number;\n\n /** The name of the unit for the azimuth base value. */\n readonly azimuthBaseUnit?: string;\n\n /** If set to true, azimuth values are returned counter-clockwise from the base. */\n readonly azimuthCounterClockwise?: boolean;\n\n /** The name of the unit that represents a revolution/perigon. Required for bearing or azimuth types. */\n readonly revolutionUnit?: string;\n\n readonly allowMathematicOperations?: boolean;\n readonly composite?: {\n /** separates values when formatting composite strings */\n readonly spacer?: string;\n readonly includeZero?: boolean;\n readonly units: Array<{\n readonly name: string;\n readonly label?: string;\n }>;\n };\n}\n\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\n * @beta\n */\nexport interface CustomFormatProps extends FormatProps {\n readonly custom: any;\n}\n\n/** CustomFormatProps type guard.\n * @beta\n */\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\n return (item as CustomFormatProps).custom !== undefined;\n};\n\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\n * @beta\n */\nexport interface CloneUnit {\n unit?: UnitProps;\n label?: string;\n}\n\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\n * @beta\n */\nexport interface CloneOptions {\n /** allows composite formats to be converted to only show primary unit */\n showOnlyPrimaryUnit?: boolean;\n /** allow format traits to be set */\n traits?: FormatTraits;\n /** allows new FormatType to be specified */\n type?: FormatType;\n /** allows precision to be set, this will throw if value is not valid for FormatType */\n precision?: DecimalPrecision | FractionalPrecision;\n /** allows primary unit and label to be specified */\n primaryUnit?: CloneUnit;\n}\n"]}
@@ -46,13 +46,26 @@ export interface UnitConversionSpec {
46
46
  /** Labels that may be used to represent the unit in a string that is to be parsed. */
47
47
  parseLabels?: string[];
48
48
  }
49
+ /** Indicates the way in which unit values are inverted during conversion
50
+ * @beta
51
+ */
52
+ export declare enum UnitConversionInvert {
53
+ /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */
54
+ InvertPreConversion = "InvertPreConversion",
55
+ /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */
56
+ InvertPostConversion = "InvertPostConversion"
57
+ }
49
58
  /** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet
50
59
  * or from Celsius to Fahrenheit.
51
60
  * @beta
52
61
  */
53
62
  export interface UnitConversionProps {
63
+ /** The factor to multiply the input value by to convert to the output value. */
54
64
  factor: number;
65
+ /** The offset to add to the input value to convert to the output value. */
55
66
  offset: number;
67
+ /** If set, inverts the unit value (1/x) before or after conversion. */
68
+ inversion?: UnitConversionInvert;
56
69
  }
57
70
  /** Interface that defines potential parse units that may be found in user's string input of a quantity value.
58
71
  * @beta
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,sBAAsB,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,MAAM,EAAE,GAAG,SAAS,CAAC;CACnE;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,4BAA4B;IAC5B,QAAQ,CAA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AAG,QAAQ,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC"}
@@ -7,4 +7,15 @@
7
7
  * @module Quantity
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.UnitConversionInvert = void 0;
11
+ /** Indicates the way in which unit values are inverted during conversion
12
+ * @beta
13
+ */
14
+ var UnitConversionInvert;
15
+ (function (UnitConversionInvert) {
16
+ /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */
17
+ UnitConversionInvert["InvertPreConversion"] = "InvertPreConversion";
18
+ /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */
19
+ UnitConversionInvert["InvertPostConversion"] = "InvertPostConversion";
20
+ })(UnitConversionInvert || (exports.UnitConversionInvert = UnitConversionInvert = {}));
10
21
  //# sourceMappingURL=Interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG","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\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\r\n * @beta\r\n */\r\nexport interface AlternateUnitLabelsProvider {\r\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\r\n}\r\n\r\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\r\n * uniquely identifies a unit by its name.\r\n * @beta\r\n */\r\nexport interface UnitProps {\r\n /** Unique name for unit. */\r\n readonly name: string;\r\n /** Default label for unit. */\r\n readonly label: string;\r\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\r\n readonly phenomenon: string;\r\n /** This is set to true if the Unit is known by the UnitsProvider. */\r\n readonly isValid: boolean;\r\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\r\n readonly system: string;\r\n}\r\n\r\n/** This interface defines the required properties of a Quantity.\r\n * @beta\r\n */\r\nexport interface QuantityProps {\r\n readonly magnitude: number;\r\n readonly unit: UnitProps;\r\n readonly isValid: boolean;\r\n}\r\n\r\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\r\n * @beta\r\n */\r\nexport interface UnitConversionSpec {\r\n /** Unit name that was used to locate the unit by the Unit Provider */\r\n name: string;\r\n /** The default label that is used to display unit */\r\n label: string;\r\n /** Unit system name, used to when finding preferred parse unit */\r\n system: string;\r\n /** the information necessary to convert the unit to a specific display unit */\r\n conversion: UnitConversionProps;\r\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\r\n parseLabels?: string[];\r\n}\r\n\r\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\r\n * or from Celsius to Fahrenheit.\r\n * @beta\r\n */\r\nexport interface UnitConversionProps {\r\n factor: number;\r\n offset: number;\r\n}\r\n\r\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\r\n * @beta\r\n */\r\nexport interface PotentialParseUnit {\r\n unitName: string;\r\n altLabels?: string[];\r\n}\r\n\r\n/**\r\n * This interface defines extra properties to be associated with Units from Units Schema by name\r\n * @alpha\r\n */\r\nexport interface UnitExtraData {\r\n readonly name: string;\r\n readonly altDisplayLabels: string[];\r\n}\r\n\r\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\r\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\r\n * @beta\r\n */\r\nexport interface UnitsProvider {\r\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\r\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\r\n findUnitByName(unitName: string): Promise<UnitProps>;\r\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\r\n}\r\n\r\n/**\r\n * Used to uniquely identify a unit system.\r\n * @beta\r\n */\r\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\r\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAmDH;;GAEG;AACH,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,oCAApB,oBAAoB,QAK/B","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\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\n * @beta\n */\nexport interface AlternateUnitLabelsProvider {\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\n}\n\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\n * uniquely identifies a unit by its name.\n * @beta\n */\nexport interface UnitProps {\n /** Unique name for unit. */\n readonly name: string;\n /** Default label for unit. */\n readonly label: string;\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\n readonly phenomenon: string;\n /** This is set to true if the Unit is known by the UnitsProvider. */\n readonly isValid: boolean;\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\n readonly system: string;\n}\n\n/** This interface defines the required properties of a Quantity.\n * @beta\n */\nexport interface QuantityProps {\n readonly magnitude: number;\n readonly unit: UnitProps;\n readonly isValid: boolean;\n}\n\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\n * @beta\n */\nexport interface UnitConversionSpec {\n /** Unit name that was used to locate the unit by the Unit Provider */\n name: string;\n /** The default label that is used to display unit */\n label: string;\n /** Unit system name, used to when finding preferred parse unit */\n system: string;\n /** the information necessary to convert the unit to a specific display unit */\n conversion: UnitConversionProps;\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\n parseLabels?: string[];\n}\n\n/** Indicates the way in which unit values are inverted during conversion\n * @beta\n */\nexport enum UnitConversionInvert {\n /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */\n InvertPreConversion = \"InvertPreConversion\",\n /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */\n InvertPostConversion = \"InvertPostConversion\"\n}\n\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\n * or from Celsius to Fahrenheit.\n * @beta\n */\nexport interface UnitConversionProps {\n /** The factor to multiply the input value by to convert to the output value. */\n factor: number;\n /** The offset to add to the input value to convert to the output value. */\n offset: number;\n /** If set, inverts the unit value (1/x) before or after conversion. */\n inversion?: UnitConversionInvert;\n}\n\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\n * @beta\n */\nexport interface PotentialParseUnit {\n unitName: string;\n altLabels?: string[];\n}\n\n/**\n * This interface defines extra properties to be associated with Units from Units Schema by name\n * @alpha\n */\nexport interface UnitExtraData {\n readonly name: string;\n readonly altDisplayLabels: string[];\n}\n\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\n * @beta\n */\nexport interface UnitsProvider {\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\n findUnitByName(unitName: string): Promise<UnitProps>;\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversionProps>;\n}\n\n/**\n * Used to uniquely identify a unit system.\n * @beta\n */\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\n"]}
@@ -105,10 +105,12 @@ export declare class Parser {
105
105
  * @param inString A string that contains text represent a quantity.
106
106
  * @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
107
107
  * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
108
+ * @deprecated in 4.10. Check [[Parser.parseQuantityString]] for replacements.
108
109
  */
109
110
  static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
110
111
  private static parseBearingFormat;
111
112
  private static parseAzimuthFormat;
113
+ private static parseRatioFormat;
112
114
  private static normalizeAngle;
113
115
  private static getRevolution;
114
116
  private static parseAndProcessTokens;
@@ -1 +1 @@
1
- {"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../src/Parser.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,aAAa,EAAuB,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjK,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;GAEG;AACH,oBAAY,UAAU;IACpB,2BAA2B,IAAI;IAC/B,0BAA0B,IAAA;IAC1B,8BAA8B,IAAA;IAC9B,WAAW,IAAA;IACX,oCAAoC,IAAA;IACpC,iBAAiB,IAAA;IACjB,4BAA4B,IAAA;IAC5B,uCAAuC,IAAA;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,EAAE,EAAE,KAAK,CAAC;IACV,uDAAuD;IACvD,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,uDAAuD;IACvD,EAAE,EAAE,IAAI,CAAC;IACT,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,aAAK,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,qBAAqB,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAgDhO"}
package/lib/cjs/Parser.js CHANGED
@@ -33,7 +33,7 @@ var Operator;
33
33
  })(Operator || (Operator = {}));
34
34
  function isOperator(char) {
35
35
  if (typeof char === "number") {
36
- // Convert the charcode to string.
36
+ // Convert the CharCode to string.
37
37
  char = String.fromCharCode(char);
38
38
  }
39
39
  return Object.values(Operator).includes(char);
@@ -280,7 +280,7 @@ class Parser {
280
280
  continue;
281
281
  }
282
282
  if (wipToken.length === 0 && charCode === Constants_1.QuantityConstants.CHAR_SPACE) {
283
- // Dont add space when the wip token is empty.
283
+ // Don't add space when the wip token is empty.
284
284
  continue;
285
285
  }
286
286
  wipToken = wipToken.concat(str[i]);
@@ -530,7 +530,7 @@ class Parser {
530
530
  }
531
531
  }
532
532
  if (conversion) {
533
- value = (value * conversion.factor) + conversion.offset;
533
+ value = (0, Quantity_1.applyConversion)(value, conversion);
534
534
  }
535
535
  mag = mag + value;
536
536
  compositeUnitIndex++;
@@ -569,12 +569,16 @@ class Parser {
569
569
  if (parserSpec.format.type === FormatEnums_1.FormatType.Azimuth) {
570
570
  return this.parseAzimuthFormat(inString, parserSpec);
571
571
  }
572
+ if (parserSpec.format.type === FormatEnums_1.FormatType.Ratio) {
573
+ return this.parseRatioFormat(inString, parserSpec);
574
+ }
572
575
  return this.parseAndProcessTokens(inString, parserSpec.format, parserSpec.unitConversions);
573
576
  }
574
577
  /** Method to generate a Quantity given a string that represents a quantity value and likely a unit label.
575
578
  * @param inString A string that contains text represent a quantity.
576
579
  * @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
577
580
  * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
581
+ * @deprecated in 4.10. Check [[Parser.parseQuantityString]] for replacements.
578
582
  */
579
583
  static parseToQuantityValue(inString, format, unitsConversions) {
580
584
  // TODO: This method is not able to do bearing and azimuth formatting and is overlapping with parseQuantityString.
@@ -591,9 +595,9 @@ class Parser {
591
595
  }
592
596
  });
593
597
  }
594
- if (format.type === FormatEnums_1.FormatType.Bearing || format.type === FormatEnums_1.FormatType.Azimuth) {
598
+ if (format.type === FormatEnums_1.FormatType.Bearing || format.type === FormatEnums_1.FormatType.Azimuth || format.type === FormatEnums_1.FormatType.Ratio) {
595
599
  // throw error indicating to call parseQuantityString instead
596
- throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Bearing and Azimuth format must be parsed using a ParserSpec. Call parseQuantityString instead.`);
600
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Bearing, Azimuth or Ratio format must be parsed using a ParserSpec. Call parseQuantityString instead.`);
597
601
  }
598
602
  return this.parseAndProcessTokens(inString, format, unitsConversions);
599
603
  }
@@ -640,18 +644,15 @@ class Parser {
640
644
  // we have to turn the value into an east base and counter clockwise (NW and SE are already counter clockwise)
641
645
  if (matchedPrefix === DirectionLabel.North) {
642
646
  if (matchedSuffix === DirectionLabel.West) {
643
- magnitude = quarterRevolution + magnitude;
644
- }
645
- else if (matchedSuffix === DirectionLabel.East) {
646
- magnitude = quarterRevolution - magnitude;
647
+ magnitude = revolution - magnitude;
647
648
  }
648
649
  }
649
650
  else if (matchedPrefix === DirectionLabel.South) {
650
651
  if (matchedSuffix === DirectionLabel.West) {
651
- magnitude = (3 * quarterRevolution) - magnitude;
652
+ magnitude = (2 * quarterRevolution) + magnitude;
652
653
  }
653
654
  else if (matchedSuffix === DirectionLabel.East) {
654
- magnitude = (3 * quarterRevolution) + magnitude;
655
+ magnitude = (2 * quarterRevolution) - magnitude;
655
656
  }
656
657
  }
657
658
  return { ok: true, value: magnitude };
@@ -664,8 +665,7 @@ class Parser {
664
665
  let magnitude = parsedResult.value;
665
666
  const revolution = this.getRevolution(spec);
666
667
  magnitude = this.normalizeAngle(magnitude, revolution);
667
- const quarterRevolution = revolution / 4;
668
- let azimuthBase = quarterRevolution;
668
+ let azimuthBase = 0.0;
669
669
  if (spec.format.azimuthBase !== undefined) {
670
670
  if (spec.azimuthBaseConversion === undefined) {
671
671
  throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.format.name}'s azimuth base.`);
@@ -677,18 +677,67 @@ class Parser {
677
677
  }
678
678
  azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);
679
679
  }
680
- const azimuthCounterClockwise = spec.format.azimuthCounterClockwiseOrDefault;
681
- if (azimuthCounterClockwise && azimuthBase === 0) {
680
+ const inputIsClockwise = spec.format.azimuthClockwiseOrDefault;
681
+ if (inputIsClockwise && azimuthBase === 0) {
682
682
  // parsed result already has the same base and orientation as our desired output
683
683
  return parsedResult;
684
684
  }
685
- if (azimuthCounterClockwise)
685
+ if (inputIsClockwise)
686
686
  magnitude = azimuthBase + magnitude;
687
687
  else
688
688
  magnitude = azimuthBase - magnitude;
689
689
  magnitude = this.normalizeAngle(magnitude, revolution);
690
690
  return { ok: true, value: magnitude };
691
691
  }
692
+ static parseRatioFormat(inString, spec) {
693
+ if (!inString)
694
+ return { ok: false, error: ParseError.NoValueOrUnitFoundInString };
695
+ const parts = inString.split(":");
696
+ if (parts.length > 2)
697
+ return { ok: false, error: ParseError.UnableToConvertParseTokensToQuantity };
698
+ const numerator = parseFloat(parts[0]);
699
+ let denominator;
700
+ if (parts.length === 1) {
701
+ denominator = 1.0;
702
+ }
703
+ else {
704
+ denominator = parseFloat(parts[1]);
705
+ }
706
+ if (isNaN(numerator) || isNaN(denominator))
707
+ return { ok: false, error: ParseError.NoValueOrUnitFoundInString };
708
+ const defaultUnit = spec.format.units && spec.format.units.length > 0 ? spec.format.units[0][0] : undefined;
709
+ const unitConversion = defaultUnit ? Parser.tryFindUnitConversion(defaultUnit.label, spec.unitConversions, defaultUnit) : undefined;
710
+ if (!unitConversion) {
711
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing input unit or unit conversion for interpreting ${spec.format.name}.`);
712
+ }
713
+ if (denominator === 0) {
714
+ if (unitConversion.inversion && numerator === 1)
715
+ return { ok: true, value: 0.0 };
716
+ else
717
+ return { ok: false, error: ParseError.MathematicOperationFoundButIsNotAllowed };
718
+ }
719
+ let quantity;
720
+ if (spec.format.units && spec.outUnit) {
721
+ quantity = new Quantity_1.Quantity(spec.format.units[0][0], numerator / denominator);
722
+ }
723
+ else {
724
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, "Missing presentation unit or persistence unit for ratio format.");
725
+ }
726
+ let converted;
727
+ try {
728
+ converted = quantity.convertTo(spec.outUnit, unitConversion);
729
+ }
730
+ catch (err) {
731
+ // for input of "0:N" with reversed unit
732
+ if (err instanceof Exception_1.QuantityError && err.errorNumber === Exception_1.QuantityStatus.InvertingZero) {
733
+ return { ok: false, error: ParseError.MathematicOperationFoundButIsNotAllowed };
734
+ }
735
+ }
736
+ if (converted === undefined || !converted.isValid) {
737
+ throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Failed to convert from ${spec.format.units[0][0].name} to ${spec.outUnit.name} On format ${spec.format.name}.`);
738
+ }
739
+ return { ok: true, value: converted.magnitude };
740
+ }
692
741
  // TODO: The following two methods are redundant with Formatter. We should consider consolidating them.
693
742
  static normalizeAngle(magnitude, revolution) {
694
743
  magnitude = magnitude % revolution; // Strip anything that goes around more than once