@itwin/core-quantity 4.10.0-dev.9 → 5.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -1
- package/lib/cjs/Exception.d.ts +2 -1
- package/lib/cjs/Exception.d.ts.map +1 -1
- package/lib/cjs/Exception.js +1 -0
- package/lib/cjs/Exception.js.map +1 -1
- package/lib/cjs/Formatter/Format.d.ts +5 -2
- package/lib/cjs/Formatter/Format.d.ts.map +1 -1
- package/lib/cjs/Formatter/Format.js +20 -26
- package/lib/cjs/Formatter/Format.js.map +1 -1
- package/lib/cjs/Formatter/FormatEnums.d.ts +42 -16
- package/lib/cjs/Formatter/FormatEnums.d.ts.map +1 -1
- package/lib/cjs/Formatter/FormatEnums.js +73 -31
- package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
- package/lib/cjs/Formatter/Formatter.d.ts +1 -0
- package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
- package/lib/cjs/Formatter/Formatter.js +70 -24
- package/lib/cjs/Formatter/Formatter.js.map +1 -1
- package/lib/cjs/Formatter/Interfaces.d.ts +2 -0
- package/lib/cjs/Formatter/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Formatter/Interfaces.js.map +1 -1
- package/lib/cjs/Interfaces.d.ts +13 -0
- package/lib/cjs/Interfaces.d.ts.map +1 -1
- package/lib/cjs/Interfaces.js +11 -0
- package/lib/cjs/Interfaces.js.map +1 -1
- package/lib/cjs/Parser.d.ts +2 -0
- package/lib/cjs/Parser.d.ts.map +1 -1
- package/lib/cjs/Parser.js +66 -18
- package/lib/cjs/Parser.js.map +1 -1
- package/lib/cjs/Quantity.d.ts +14 -0
- package/lib/cjs/Quantity.d.ts.map +1 -1
- package/lib/cjs/Quantity.js +41 -3
- package/lib/cjs/Quantity.js.map +1 -1
- package/lib/esm/Exception.d.ts +2 -1
- package/lib/esm/Exception.d.ts.map +1 -1
- package/lib/esm/Exception.js +1 -0
- package/lib/esm/Exception.js.map +1 -1
- package/lib/esm/Formatter/Format.d.ts +5 -2
- package/lib/esm/Formatter/Format.d.ts.map +1 -1
- package/lib/esm/Formatter/Format.js +21 -27
- package/lib/esm/Formatter/Format.js.map +1 -1
- package/lib/esm/Formatter/FormatEnums.d.ts +42 -16
- package/lib/esm/Formatter/FormatEnums.d.ts.map +1 -1
- package/lib/esm/Formatter/FormatEnums.js +58 -17
- package/lib/esm/Formatter/FormatEnums.js.map +1 -1
- package/lib/esm/Formatter/Formatter.d.ts +1 -0
- package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
- package/lib/esm/Formatter/Formatter.js +72 -26
- package/lib/esm/Formatter/Formatter.js.map +1 -1
- package/lib/esm/Formatter/Interfaces.d.ts +2 -0
- package/lib/esm/Formatter/Interfaces.d.ts.map +1 -1
- package/lib/esm/Formatter/Interfaces.js.map +1 -1
- package/lib/esm/Interfaces.d.ts +13 -0
- package/lib/esm/Interfaces.d.ts.map +1 -1
- package/lib/esm/Interfaces.js +10 -1
- package/lib/esm/Interfaces.js.map +1 -1
- package/lib/esm/Parser.d.ts +2 -0
- package/lib/esm/Parser.d.ts.map +1 -1
- package/lib/esm/Parser.js +67 -19
- package/lib/esm/Parser.js.map +1 -1
- package/lib/esm/Quantity.d.ts +14 -0
- package/lib/esm/Quantity.d.ts.map +1 -1
- package/lib/esm/Quantity.js +37 -1
- package/lib/esm/Quantity.js.map +1 -1
- package/package.json +8 -8
|
@@ -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,CAAC,IAAI,EAAE,MAA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E,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/G,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAC3D,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IACrD,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrF;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC"}
|
package/lib/esm/Interfaces.js
CHANGED
|
@@ -5,5 +5,14 @@
|
|
|
5
5
|
/** @packageDocumentation
|
|
6
6
|
* @module Quantity
|
|
7
7
|
*/
|
|
8
|
-
|
|
8
|
+
/** Indicates the way in which unit values are inverted during conversion
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export var UnitConversionInvert;
|
|
12
|
+
(function (UnitConversionInvert) {
|
|
13
|
+
/** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */
|
|
14
|
+
UnitConversionInvert["InvertPreConversion"] = "InvertPreConversion";
|
|
15
|
+
/** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */
|
|
16
|
+
UnitConversionInvert["InvertPostConversion"] = "InvertPostConversion";
|
|
17
|
+
})(UnitConversionInvert || (UnitConversionInvert = {}));
|
|
9
18
|
//# 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,MAAM,CAAN,IAAY,oBAKX;AALD,WAAY,oBAAoB;IAC9B,mGAAmG;IACnG,mEAA2C,CAAA;IAC3C,gGAAgG;IAChG,qEAA6C,CAAA;AAC/C,CAAC,EALW,oBAAoB,KAApB,oBAAoB,QAK/B","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/** Indicates the way in which unit values are inverted during conversion\r\n * @beta\r\n */\r\nexport enum UnitConversionInvert {\r\n /** Invert value before applying the other conversion steps (the from-unit is the inverted unit) */\r\n InvertPreConversion = \"InvertPreConversion\",\r\n /** Invert value after applying the other conversion steps (the to-unit is the inverted unit) */\r\n InvertPostConversion = \"InvertPostConversion\"\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 /** The factor to multiply the input value by to convert to the output value. */\r\n factor: number;\r\n /** The offset to add to the input value to convert to the output value. */\r\n offset: number;\r\n /** If set, inverts the unit value (1/x) before or after conversion. */\r\n inversion?: UnitConversionInvert;\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"]}
|
package/lib/esm/Parser.d.ts
CHANGED
|
@@ -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;
|
package/lib/esm/Parser.d.ts.map
CHANGED
|
@@ -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,QAAQ;IACX,QAAQ,MAAM;IACd,WAAW,MAAM;CAClB;AAUD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,kBAAkB,CAAC;AAEtE;;GAEG;AACH,cAAM,UAAU;IACP,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;IAClC,UAAU,EAAE,OAAO,CAAS;gBAEvB,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,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DAA2D;IAC3D,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAyCpC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAevC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAkC/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,+BAA+B;IAkE9C;;;OAGG;WACW,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,mBAAmB;IA4BhG;;;;;OAKG;WACW,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,GAAG,mBAAmB;IAyBjI,OAAO,CAAC,MAAM,CAAC,kBAAkB;IA0DjC,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAuCjC,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA0D/B,OAAO,CAAC,MAAM,CAAC,cAAc;IAS7B,OAAO,CAAC,MAAM,CAAC,aAAa;IAc5B,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAsBpC,+HAA+H;WAC3G,gCAAgC,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS,EAAE,qBAAqB,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA4B1L,+HAA+H;WAC3G,yBAAyB,CAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,EAAE,qBAAqB,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;CAgDhO"}
|
package/lib/esm/Parser.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { QuantityConstants } from "./Constants";
|
|
9
9
|
import { QuantityError, QuantityStatus } from "./Exception";
|
|
10
10
|
import { FormatTraits, FormatType } from "./Formatter/FormatEnums";
|
|
11
|
-
import { Quantity } from "./Quantity";
|
|
11
|
+
import { applyConversion, Quantity } from "./Quantity";
|
|
12
12
|
/** Possible parser errors
|
|
13
13
|
* @beta
|
|
14
14
|
*/
|
|
@@ -30,7 +30,7 @@ var Operator;
|
|
|
30
30
|
})(Operator || (Operator = {}));
|
|
31
31
|
function isOperator(char) {
|
|
32
32
|
if (typeof char === "number") {
|
|
33
|
-
// Convert the
|
|
33
|
+
// Convert the CharCode to string.
|
|
34
34
|
char = String.fromCharCode(char);
|
|
35
35
|
}
|
|
36
36
|
return Object.values(Operator).includes(char);
|
|
@@ -169,7 +169,6 @@ export class Parser {
|
|
|
169
169
|
uomSeparatorToIgnore = format.uomSeparator.charCodeAt(0);
|
|
170
170
|
skipCodes.push(uomSeparatorToIgnore);
|
|
171
171
|
}
|
|
172
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
173
172
|
for (let i = 0; i < str.length; i++) {
|
|
174
173
|
const charCode = str.charCodeAt(i);
|
|
175
174
|
if (Parser.isDigitOrDecimalSeparator(charCode, format)) {
|
|
@@ -277,7 +276,7 @@ export class Parser {
|
|
|
277
276
|
continue;
|
|
278
277
|
}
|
|
279
278
|
if (wipToken.length === 0 && charCode === QuantityConstants.CHAR_SPACE) {
|
|
280
|
-
//
|
|
279
|
+
// Don't add space when the wip token is empty.
|
|
281
280
|
continue;
|
|
282
281
|
}
|
|
283
282
|
wipToken = wipToken.concat(str[i]);
|
|
@@ -527,7 +526,7 @@ export class Parser {
|
|
|
527
526
|
}
|
|
528
527
|
}
|
|
529
528
|
if (conversion) {
|
|
530
|
-
value = (value
|
|
529
|
+
value = applyConversion(value, conversion);
|
|
531
530
|
}
|
|
532
531
|
mag = mag + value;
|
|
533
532
|
compositeUnitIndex++;
|
|
@@ -566,12 +565,16 @@ export class Parser {
|
|
|
566
565
|
if (parserSpec.format.type === FormatType.Azimuth) {
|
|
567
566
|
return this.parseAzimuthFormat(inString, parserSpec);
|
|
568
567
|
}
|
|
568
|
+
if (parserSpec.format.type === FormatType.Ratio) {
|
|
569
|
+
return this.parseRatioFormat(inString, parserSpec);
|
|
570
|
+
}
|
|
569
571
|
return this.parseAndProcessTokens(inString, parserSpec.format, parserSpec.unitConversions);
|
|
570
572
|
}
|
|
571
573
|
/** Method to generate a Quantity given a string that represents a quantity value and likely a unit label.
|
|
572
574
|
* @param inString A string that contains text represent a quantity.
|
|
573
575
|
* @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
|
|
574
576
|
* @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
|
|
577
|
+
* @deprecated in 4.10. Check [[Parser.parseQuantityString]] for replacements.
|
|
575
578
|
*/
|
|
576
579
|
static parseToQuantityValue(inString, format, unitsConversions) {
|
|
577
580
|
// TODO: This method is not able to do bearing and azimuth formatting and is overlapping with parseQuantityString.
|
|
@@ -588,9 +591,9 @@ export class Parser {
|
|
|
588
591
|
}
|
|
589
592
|
});
|
|
590
593
|
}
|
|
591
|
-
if (format.type === FormatType.Bearing || format.type === FormatType.Azimuth) {
|
|
594
|
+
if (format.type === FormatType.Bearing || format.type === FormatType.Azimuth || format.type === FormatType.Ratio) {
|
|
592
595
|
// throw error indicating to call parseQuantityString instead
|
|
593
|
-
throw new QuantityError(QuantityStatus.UnsupportedUnit, `Bearing
|
|
596
|
+
throw new QuantityError(QuantityStatus.UnsupportedUnit, `Bearing, Azimuth or Ratio format must be parsed using a ParserSpec. Call parseQuantityString instead.`);
|
|
594
597
|
}
|
|
595
598
|
return this.parseAndProcessTokens(inString, format, unitsConversions);
|
|
596
599
|
}
|
|
@@ -623,7 +626,7 @@ export class Parser {
|
|
|
623
626
|
inString = inString.substring(0, inString.length - DirectionLabel.West.length);
|
|
624
627
|
matchedSuffix = DirectionLabel.West;
|
|
625
628
|
}
|
|
626
|
-
if (matchedPrefix === null
|
|
629
|
+
if (matchedPrefix === null || matchedSuffix === null) {
|
|
627
630
|
return { ok: false, error: ParseError.BearingPrefixOrSuffixMissing };
|
|
628
631
|
}
|
|
629
632
|
const parsedResult = this.parseAndProcessTokens(inString, spec.format, spec.unitConversions);
|
|
@@ -637,18 +640,15 @@ export class Parser {
|
|
|
637
640
|
// we have to turn the value into an east base and counter clockwise (NW and SE are already counter clockwise)
|
|
638
641
|
if (matchedPrefix === DirectionLabel.North) {
|
|
639
642
|
if (matchedSuffix === DirectionLabel.West) {
|
|
640
|
-
magnitude =
|
|
641
|
-
}
|
|
642
|
-
else if (matchedSuffix === DirectionLabel.East) {
|
|
643
|
-
magnitude = quarterRevolution - magnitude;
|
|
643
|
+
magnitude = revolution - magnitude;
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
646
|
else if (matchedPrefix === DirectionLabel.South) {
|
|
647
647
|
if (matchedSuffix === DirectionLabel.West) {
|
|
648
|
-
magnitude = (
|
|
648
|
+
magnitude = (2 * quarterRevolution) + magnitude;
|
|
649
649
|
}
|
|
650
650
|
else if (matchedSuffix === DirectionLabel.East) {
|
|
651
|
-
magnitude = (
|
|
651
|
+
magnitude = (2 * quarterRevolution) - magnitude;
|
|
652
652
|
}
|
|
653
653
|
}
|
|
654
654
|
return { ok: true, value: magnitude };
|
|
@@ -661,8 +661,7 @@ export class Parser {
|
|
|
661
661
|
let magnitude = parsedResult.value;
|
|
662
662
|
const revolution = this.getRevolution(spec);
|
|
663
663
|
magnitude = this.normalizeAngle(magnitude, revolution);
|
|
664
|
-
|
|
665
|
-
let azimuthBase = quarterRevolution;
|
|
664
|
+
let azimuthBase = 0.0;
|
|
666
665
|
if (spec.format.azimuthBase !== undefined) {
|
|
667
666
|
if (spec.azimuthBaseConversion === undefined) {
|
|
668
667
|
throw new QuantityError(QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.format.name}'s azimuth base.`);
|
|
@@ -674,18 +673,67 @@ export class Parser {
|
|
|
674
673
|
}
|
|
675
674
|
azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);
|
|
676
675
|
}
|
|
677
|
-
const
|
|
678
|
-
if (
|
|
676
|
+
const inputIsClockwise = spec.format.azimuthClockwiseOrDefault;
|
|
677
|
+
if (inputIsClockwise && azimuthBase === 0) {
|
|
679
678
|
// parsed result already has the same base and orientation as our desired output
|
|
680
679
|
return parsedResult;
|
|
681
680
|
}
|
|
682
|
-
if (
|
|
681
|
+
if (inputIsClockwise)
|
|
683
682
|
magnitude = azimuthBase + magnitude;
|
|
684
683
|
else
|
|
685
684
|
magnitude = azimuthBase - magnitude;
|
|
686
685
|
magnitude = this.normalizeAngle(magnitude, revolution);
|
|
687
686
|
return { ok: true, value: magnitude };
|
|
688
687
|
}
|
|
688
|
+
static parseRatioFormat(inString, spec) {
|
|
689
|
+
if (!inString)
|
|
690
|
+
return { ok: false, error: ParseError.NoValueOrUnitFoundInString };
|
|
691
|
+
const parts = inString.split(":");
|
|
692
|
+
if (parts.length > 2)
|
|
693
|
+
return { ok: false, error: ParseError.UnableToConvertParseTokensToQuantity };
|
|
694
|
+
const numerator = parseFloat(parts[0]);
|
|
695
|
+
let denominator;
|
|
696
|
+
if (parts.length === 1) {
|
|
697
|
+
denominator = 1.0;
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
denominator = parseFloat(parts[1]);
|
|
701
|
+
}
|
|
702
|
+
if (isNaN(numerator) || isNaN(denominator))
|
|
703
|
+
return { ok: false, error: ParseError.NoValueOrUnitFoundInString };
|
|
704
|
+
const defaultUnit = spec.format.units && spec.format.units.length > 0 ? spec.format.units[0][0] : undefined;
|
|
705
|
+
const unitConversion = defaultUnit ? Parser.tryFindUnitConversion(defaultUnit.label, spec.unitConversions, defaultUnit) : undefined;
|
|
706
|
+
if (!unitConversion) {
|
|
707
|
+
throw new QuantityError(QuantityStatus.MissingRequiredProperty, `Missing input unit or unit conversion for interpreting ${spec.format.name}.`);
|
|
708
|
+
}
|
|
709
|
+
if (denominator === 0) {
|
|
710
|
+
if (unitConversion.inversion && numerator === 1)
|
|
711
|
+
return { ok: true, value: 0.0 };
|
|
712
|
+
else
|
|
713
|
+
return { ok: false, error: ParseError.MathematicOperationFoundButIsNotAllowed };
|
|
714
|
+
}
|
|
715
|
+
let quantity;
|
|
716
|
+
if (spec.format.units && spec.outUnit) {
|
|
717
|
+
quantity = new Quantity(spec.format.units[0][0], numerator / denominator);
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
throw new QuantityError(QuantityStatus.MissingRequiredProperty, "Missing presentation unit or persistence unit for ratio format.");
|
|
721
|
+
}
|
|
722
|
+
let converted;
|
|
723
|
+
try {
|
|
724
|
+
converted = quantity.convertTo(spec.outUnit, unitConversion);
|
|
725
|
+
}
|
|
726
|
+
catch (err) {
|
|
727
|
+
// for input of "0:N" with reversed unit
|
|
728
|
+
if (err instanceof QuantityError && err.errorNumber === QuantityStatus.InvertingZero) {
|
|
729
|
+
return { ok: false, error: ParseError.MathematicOperationFoundButIsNotAllowed };
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
if (converted === undefined || !converted.isValid) {
|
|
733
|
+
throw new QuantityError(QuantityStatus.UnsupportedUnit, `Failed to convert from ${spec.format.units[0][0].name} to ${spec.outUnit.name} On format ${spec.format.name}.`);
|
|
734
|
+
}
|
|
735
|
+
return { ok: true, value: converted.magnitude };
|
|
736
|
+
}
|
|
689
737
|
// TODO: The following two methods are redundant with Formatter. We should consider consolidating them.
|
|
690
738
|
static normalizeAngle(magnitude, revolution) {
|
|
691
739
|
magnitude = magnitude % revolution; // Strip anything that goes around more than once
|