@itwin/core-quantity 4.10.0-dev.10 → 4.10.0-dev.12
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 +6 -1
- package/lib/cjs/Constants.js.map +1 -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 +18 -24
- package/lib/cjs/Formatter/Format.js.map +1 -1
- package/lib/cjs/Formatter/FormatEnums.d.ts +17 -1
- package/lib/cjs/Formatter/FormatEnums.d.ts.map +1 -1
- package/lib/cjs/Formatter/FormatEnums.js +33 -1
- 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 -22
- package/lib/cjs/Formatter/Formatter.js.map +1 -1
- package/lib/cjs/Formatter/FormatterSpec.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 +1 -0
- package/lib/cjs/Parser.d.ts.map +1 -1
- package/lib/cjs/Parser.js +64 -16
- package/lib/cjs/Parser.js.map +1 -1
- package/lib/cjs/ParserSpec.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 +40 -2
- package/lib/cjs/Quantity.js.map +1 -1
- package/lib/cjs/Unit.js.map +1 -1
- package/lib/cjs/core-quantity.js.map +1 -1
- package/lib/esm/Constants.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 +19 -25
- package/lib/esm/Formatter/Format.js.map +1 -1
- package/lib/esm/Formatter/FormatEnums.d.ts +17 -1
- package/lib/esm/Formatter/FormatEnums.d.ts.map +1 -1
- package/lib/esm/Formatter/FormatEnums.js +31 -0
- 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 -24
- package/lib/esm/Formatter/Formatter.js.map +1 -1
- package/lib/esm/Formatter/FormatterSpec.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 +1 -0
- package/lib/esm/Parser.d.ts.map +1 -1
- package/lib/esm/Parser.js +65 -17
- package/lib/esm/Parser.js.map +1 -1
- package/lib/esm/ParserSpec.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/lib/esm/Unit.js.map +1 -1
- package/lib/esm/core-quantity.js.map +1 -1
- 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;;;
|
|
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"]}
|
package/lib/cjs/Interfaces.d.ts
CHANGED
|
@@ -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,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wHAAwH;IACxH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,qEAAqE;IACrE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,uGAAuG;IACvG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,kEAAkE;IAClE,MAA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perty(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":["/*---------------------------------------------------------------------------------------------\
|
|
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"]}
|
package/lib/cjs/Parser.d.ts
CHANGED
|
@@ -109,6 +109,7 @@ export declare class Parser {
|
|
|
109
109
|
static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
|
|
110
110
|
private static parseBearingFormat;
|
|
111
111
|
private static parseAzimuthFormat;
|
|
112
|
+
private static parseRatioFormat;
|
|
112
113
|
private static normalizeAngle;
|
|
113
114
|
private static getRevolution;
|
|
114
115
|
private static parseAndProcessTokens;
|
package/lib/cjs/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;IAC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convert the
|
|
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
|
-
//
|
|
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 = (
|
|
533
|
+
value = (0, Quantity_1.applyConversion)(value, conversion);
|
|
534
534
|
}
|
|
535
535
|
mag = mag + value;
|
|
536
536
|
compositeUnitIndex++;
|
|
@@ -569,6 +569,9 @@ 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.
|
|
@@ -591,9 +594,9 @@ class Parser {
|
|
|
591
594
|
}
|
|
592
595
|
});
|
|
593
596
|
}
|
|
594
|
-
if (format.type === FormatEnums_1.FormatType.Bearing || format.type === FormatEnums_1.FormatType.Azimuth) {
|
|
597
|
+
if (format.type === FormatEnums_1.FormatType.Bearing || format.type === FormatEnums_1.FormatType.Azimuth || format.type === FormatEnums_1.FormatType.Ratio) {
|
|
595
598
|
// throw error indicating to call parseQuantityString instead
|
|
596
|
-
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Bearing
|
|
599
|
+
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.UnsupportedUnit, `Bearing, Azimuth or Ratio format must be parsed using a ParserSpec. Call parseQuantityString instead.`);
|
|
597
600
|
}
|
|
598
601
|
return this.parseAndProcessTokens(inString, format, unitsConversions);
|
|
599
602
|
}
|
|
@@ -640,18 +643,15 @@ class Parser {
|
|
|
640
643
|
// we have to turn the value into an east base and counter clockwise (NW and SE are already counter clockwise)
|
|
641
644
|
if (matchedPrefix === DirectionLabel.North) {
|
|
642
645
|
if (matchedSuffix === DirectionLabel.West) {
|
|
643
|
-
magnitude =
|
|
644
|
-
}
|
|
645
|
-
else if (matchedSuffix === DirectionLabel.East) {
|
|
646
|
-
magnitude = quarterRevolution - magnitude;
|
|
646
|
+
magnitude = revolution - magnitude;
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
else if (matchedPrefix === DirectionLabel.South) {
|
|
650
650
|
if (matchedSuffix === DirectionLabel.West) {
|
|
651
|
-
magnitude = (
|
|
651
|
+
magnitude = (2 * quarterRevolution) + magnitude;
|
|
652
652
|
}
|
|
653
653
|
else if (matchedSuffix === DirectionLabel.East) {
|
|
654
|
-
magnitude = (
|
|
654
|
+
magnitude = (2 * quarterRevolution) - magnitude;
|
|
655
655
|
}
|
|
656
656
|
}
|
|
657
657
|
return { ok: true, value: magnitude };
|
|
@@ -664,8 +664,7 @@ class Parser {
|
|
|
664
664
|
let magnitude = parsedResult.value;
|
|
665
665
|
const revolution = this.getRevolution(spec);
|
|
666
666
|
magnitude = this.normalizeAngle(magnitude, revolution);
|
|
667
|
-
|
|
668
|
-
let azimuthBase = quarterRevolution;
|
|
667
|
+
let azimuthBase = 0.0;
|
|
669
668
|
if (spec.format.azimuthBase !== undefined) {
|
|
670
669
|
if (spec.azimuthBaseConversion === undefined) {
|
|
671
670
|
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.format.name}'s azimuth base.`);
|
|
@@ -677,18 +676,67 @@ class Parser {
|
|
|
677
676
|
}
|
|
678
677
|
azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);
|
|
679
678
|
}
|
|
680
|
-
const
|
|
681
|
-
if (
|
|
679
|
+
const inputIsClockwise = spec.format.azimuthClockwiseOrDefault;
|
|
680
|
+
if (inputIsClockwise && azimuthBase === 0) {
|
|
682
681
|
// parsed result already has the same base and orientation as our desired output
|
|
683
682
|
return parsedResult;
|
|
684
683
|
}
|
|
685
|
-
if (
|
|
684
|
+
if (inputIsClockwise)
|
|
686
685
|
magnitude = azimuthBase + magnitude;
|
|
687
686
|
else
|
|
688
687
|
magnitude = azimuthBase - magnitude;
|
|
689
688
|
magnitude = this.normalizeAngle(magnitude, revolution);
|
|
690
689
|
return { ok: true, value: magnitude };
|
|
691
690
|
}
|
|
691
|
+
static parseRatioFormat(inString, spec) {
|
|
692
|
+
if (!inString)
|
|
693
|
+
return { ok: false, error: ParseError.NoValueOrUnitFoundInString };
|
|
694
|
+
const parts = inString.split(":");
|
|
695
|
+
if (parts.length > 2)
|
|
696
|
+
return { ok: false, error: ParseError.UnableToConvertParseTokensToQuantity };
|
|
697
|
+
const numerator = parseFloat(parts[0]);
|
|
698
|
+
let denominator;
|
|
699
|
+
if (parts.length === 1) {
|
|
700
|
+
denominator = 1.0;
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
denominator = parseFloat(parts[1]);
|
|
704
|
+
}
|
|
705
|
+
if (isNaN(numerator) || isNaN(denominator))
|
|
706
|
+
return { ok: false, error: ParseError.NoValueOrUnitFoundInString };
|
|
707
|
+
const defaultUnit = spec.format.units && spec.format.units.length > 0 ? spec.format.units[0][0] : undefined;
|
|
708
|
+
const unitConversion = defaultUnit ? Parser.tryFindUnitConversion(defaultUnit.label, spec.unitConversions, defaultUnit) : undefined;
|
|
709
|
+
if (!unitConversion) {
|
|
710
|
+
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, `Missing input unit or unit conversion for interpreting ${spec.format.name}.`);
|
|
711
|
+
}
|
|
712
|
+
if (denominator === 0) {
|
|
713
|
+
if (unitConversion.inversion && numerator === 1)
|
|
714
|
+
return { ok: true, value: 0.0 };
|
|
715
|
+
else
|
|
716
|
+
return { ok: false, error: ParseError.MathematicOperationFoundButIsNotAllowed };
|
|
717
|
+
}
|
|
718
|
+
let quantity;
|
|
719
|
+
if (spec.format.units && spec.outUnit) {
|
|
720
|
+
quantity = new Quantity_1.Quantity(spec.format.units[0][0], numerator / denominator);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.MissingRequiredProperty, "Missing presentation unit or persistence unit for ratio format.");
|
|
724
|
+
}
|
|
725
|
+
let converted;
|
|
726
|
+
try {
|
|
727
|
+
converted = quantity.convertTo(spec.outUnit, unitConversion);
|
|
728
|
+
}
|
|
729
|
+
catch (err) {
|
|
730
|
+
// for input of "0:N" with reversed unit
|
|
731
|
+
if (err instanceof Exception_1.QuantityError && err.errorNumber === Exception_1.QuantityStatus.InvertingZero) {
|
|
732
|
+
return { ok: false, error: ParseError.MathematicOperationFoundButIsNotAllowed };
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (converted === undefined || !converted.isValid) {
|
|
736
|
+
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}.`);
|
|
737
|
+
}
|
|
738
|
+
return { ok: true, value: converted.magnitude };
|
|
739
|
+
}
|
|
692
740
|
// TODO: The following two methods are redundant with Formatter. We should consider consolidating them.
|
|
693
741
|
static normalizeAngle(magnitude, revolution) {
|
|
694
742
|
magnitude = magnitude % revolution; // Strip anything that goes around more than once
|