@itwin/core-quantity 5.1.0-dev.9 → 5.2.0-dev.1
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 +61 -1
- package/lib/cjs/Constants.js +1 -1
- package/lib/cjs/Constants.js.map +1 -1
- package/lib/cjs/Formatter/Format.d.ts +6 -0
- package/lib/cjs/Formatter/Format.d.ts.map +1 -1
- package/lib/cjs/Formatter/Format.js +22 -4
- package/lib/cjs/Formatter/Format.js.map +1 -1
- package/lib/cjs/Formatter/FormatEnums.d.ts +3 -3
- package/lib/cjs/Formatter/FormatEnums.js +3 -3
- package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
- package/lib/cjs/Formatter/Formatter.d.ts.map +1 -1
- package/lib/cjs/Formatter/Formatter.js +6 -4
- 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/Parser.d.ts +8 -3
- package/lib/cjs/Parser.d.ts.map +1 -1
- package/lib/cjs/Parser.js +50 -4
- package/lib/cjs/Parser.js.map +1 -1
- package/lib/esm/Constants.js +1 -1
- package/lib/esm/Constants.js.map +1 -1
- package/lib/esm/Formatter/Format.d.ts +6 -0
- package/lib/esm/Formatter/Format.d.ts.map +1 -1
- package/lib/esm/Formatter/Format.js +22 -4
- package/lib/esm/Formatter/Format.js.map +1 -1
- package/lib/esm/Formatter/FormatEnums.d.ts +3 -3
- package/lib/esm/Formatter/FormatEnums.js +3 -3
- package/lib/esm/Formatter/FormatEnums.js.map +1 -1
- package/lib/esm/Formatter/Formatter.d.ts.map +1 -1
- package/lib/esm/Formatter/Formatter.js +6 -4
- 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/Parser.d.ts +8 -3
- package/lib/esm/Parser.d.ts.map +1 -1
- package/lib/esm/Parser.js +50 -4
- package/lib/esm/Parser.js.map +1 -1
- package/package.json +7 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Formatter.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Formatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA8FhD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAW;IAE1C,OAAO,CAAC,MAAM,CAAC,YAAY;IAE3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAW1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA0BhC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAajC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkBlC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAyD9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;
|
|
1
|
+
{"version":3,"file":"Formatter.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Formatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AA8FhD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAW;IAE1C,OAAO,CAAC,MAAM,CAAC,YAAY;IAE3B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAW1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IA0BhC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAajC;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkBlC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAyD9B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IA+H9B,OAAO,CAAC,MAAM,CAAC,WAAW;IAU1B;;;OAGG;WACW,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM;IA8D5E,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAoFvC,OAAO,CAAC,MAAM,CAAC,cAAc;IAS7B,OAAO,CAAC,MAAM,CAAC,aAAa;IAc5B,OAAO,CAAC,MAAM,CAAC,WAAW;CAqC3B"}
|
|
@@ -182,7 +182,7 @@ class Formatter {
|
|
|
182
182
|
let unitValue = 0.0;
|
|
183
183
|
if (spec.format.type === FormatEnums_1.FormatType.Ratio) {
|
|
184
184
|
if (1 !== spec.format.units.length)
|
|
185
|
-
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name}
|
|
185
|
+
throw new Exception_1.QuantityError(Exception_1.QuantityStatus.InvalidCompositeFormat, `The Format '${spec.format.name}' with type 'ratio' must have exactly one unit.`);
|
|
186
186
|
try {
|
|
187
187
|
unitValue = (0, Quantity_1.applyConversion)(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;
|
|
188
188
|
}
|
|
@@ -303,13 +303,15 @@ class Formatter {
|
|
|
303
303
|
else /* if (usesStops)*/ {
|
|
304
304
|
// we assume that stopping value is always positive
|
|
305
305
|
posMagnitude = Math.floor(posMagnitude * precisionScale + FPV_ROUNDFACTOR) / precisionScale;
|
|
306
|
-
const
|
|
306
|
+
const baseFactor = spec.format.stationBaseFactor ?? 1;
|
|
307
|
+
const stationOffsetSize = spec.format.stationOffsetSize || 0; // Provide default if undefined
|
|
308
|
+
const denominator = baseFactor * Math.pow(10, stationOffsetSize);
|
|
307
309
|
const tVal = Math.floor(posMagnitude); // this is the integer part only
|
|
308
310
|
const hiPart = Math.floor(tVal / denominator);
|
|
309
311
|
const lowPart = tVal - hiPart * denominator;
|
|
310
312
|
const fract = posMagnitude - tVal;
|
|
311
313
|
const fractionPart = Math.floor(fract * precisionScale + FPV_ROUNDFACTOR);
|
|
312
|
-
const stationString = hiPart.toFixed(0) + spec.format.stationSeparator + lowPart.toFixed(0).padStart(
|
|
314
|
+
const stationString = hiPart.toFixed(0) + spec.format.stationSeparator + lowPart.toFixed(0).padStart(stationOffsetSize, "0");
|
|
313
315
|
let fractionString = "";
|
|
314
316
|
if (fractionPart > 0) {
|
|
315
317
|
fractionString = (fractionPart / precisionScale).toFixed(spec.format.precision);
|
|
@@ -364,7 +366,7 @@ class Formatter {
|
|
|
364
366
|
}
|
|
365
367
|
break;
|
|
366
368
|
case FormatEnums_1.ShowSignOption.OnlyNegative:
|
|
367
|
-
if (valueIsNegative)
|
|
369
|
+
if (valueIsNegative && spec.format.type !== FormatEnums_1.FormatType.Bearing && spec.format.type !== FormatEnums_1.FormatType.Azimuth)
|
|
368
370
|
prefix += "-";
|
|
369
371
|
break;
|
|
370
372
|
case FormatEnums_1.ShowSignOption.SignAlways:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Formatter.js","sourceRoot":"","sources":["../../../src/Formatter/Formatter.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,4CAAiD;AACjD,4CAA6D;AAE7D,+CAA2I;AAC3I,0CAAwD;AAExD;;GAEG;AACH,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC;;GAEG;AACH,MAAM,iBAAiB;IACb,SAAS,GAAW,CAAC,CAAC;IACtB,UAAU,GAAW,CAAC,CAAC;IACvB,YAAY,GAAW,CAAC,CAAC;IACzB,qBAAqB,GAAW,CAAC,CAAC;IAClC,UAAU,GAAa,EAAE,CAAC;IAElC,YAAY,KAAa,EAAE,SAA8B,EAAE,MAAe;QACxE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAmB,CAAC,CAAC;QAC3C,IA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C,WAAW,EAAE,IAAI,CAAC,EAAE,CAAC;YAC/F;gBACE,MAAM,IAAI,yBAAa,CAAC,0BAAc,CAAC,sBAAsB,EAAE,cAAc,IAAI,CAAC,MAAM,CAAC,IAAI,uCAAuC,CAAC,CAAC;QAC1I,CAAC;IACH,CAAC;;AAhfH,8BAifC","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 { QuantityConstants } from \"../Constants\";\nimport { QuantityError, QuantityStatus } from \"../Exception\";\nimport { FormatterSpec } from \"./FormatterSpec\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, RatioType, ScientificType, ShowSignOption } from \"./FormatEnums\";\nimport { applyConversion, Quantity } from \"../Quantity\";\n\n/** rounding additive\n * @internal\n */\nconst FPV_ROUNDFACTOR = 0.50000000001;\n\n/** A private helper class used to format fraction part of value into a numerator and denominator.\n * @internal\n */\nclass FractionalNumeric {\n private _integral: number = 0;\n private _numerator: number = 0;\n private _denominator: number = 1;\n private _greatestCommonFactor: number = 1;\n private _textParts: string[] = [];\n\n constructor(value: number, precision: FractionalPrecision, reduce: boolean) {\n this.calculate(value, precision as number);\n this.formTextParts(reduce);\n }\n\n private calculate(value: number, denominator: number) {\n const positiveValue = Math.abs(value);\n this._denominator = denominator;\n this._integral = Math.floor(positiveValue);\n const fractionPart = positiveValue - this._integral;\n this._numerator = Math.floor(fractionPart * this._denominator + FPV_ROUNDFACTOR);\n\n if (0 !== denominator && (this._numerator / this._denominator) === 1) {\n this._numerator = 0;\n this._integral += 1;\n } else {\n this._greatestCommonFactor = FractionalNumeric.getGreatestCommonFactor(this._numerator, this._denominator);\n }\n }\n\n /** Determine the GCD given two values. This value can be used to reduce a fraction.\n * See algorithm description http://en.wikipedia.org/wiki/Euclidean_algorithm\n */\n public static getGreatestCommonFactor(numerator: number, denominator: number): number {\n let r;\n while (denominator !== 0) {\n r = numerator % denominator;\n numerator = denominator;\n denominator = r;\n }\n return (numerator < 0) ? -numerator : numerator;\n }\n\n public get greatestCommonFactor(): number { return this._greatestCommonFactor; }\n public get hasFractionPart(): boolean { return this._textParts.length > 0; }\n public get isZero(): boolean { return 0 === this._numerator; }\n\n public getIntegralString(): string {\n if (this._textParts.length > 0)\n return this._textParts[0];\n\n return \"\";\n }\n\n public getNumeratorString(): string {\n if (this._textParts.length >= 3)\n return this._textParts[1];\n\n return \"\";\n }\n\n public getDenominatorString(): string {\n if (this._textParts.length >= 3)\n return this._textParts[2];\n\n return \"\";\n }\n\n private formTextParts(reduce: boolean): void {\n let numerator = this._numerator;\n let denominator = this._denominator;\n\n if (reduce && this._greatestCommonFactor > 1) {\n numerator /= this.greatestCommonFactor;\n denominator /= this.greatestCommonFactor;\n }\n\n this._textParts.push(this._integral.toFixed(0));\n if (numerator > 0) {\n this._textParts.push(numerator.toFixed(0));\n this._textParts.push(denominator.toFixed(0));\n }\n }\n}\n\n/** A helper class that contains methods used to format quantity values based on a format that are defined via the Format class.\n * @beta\n */\nexport class Formatter {\n private static FPV_MINTHRESHOLD = 1.0e-14;\n\n private static isNegligible(value: number): boolean { return (Math.abs(value) < Formatter.FPV_MINTHRESHOLD); }\n\n /** Return floating point value rounded by specific rounding factor.\n * @param value Value to be rounded.\n * @param roundTo Rounding factor.\n */\n private static roundDouble(value: number, roundTo: number): number {\n if (Formatter.isNegligible(roundTo))\n return value;\n\n roundTo = Math.abs(roundTo);\n let rnd = FPV_ROUNDFACTOR + (value / roundTo);\n const iVal = Math.floor(rnd);\n rnd = iVal * roundTo;\n return (value < 0.0) ? -rnd : rnd;\n }\n\n /** Generate a formatted text string integer value insert 1000 separators if appropriate.\n * @param wholePart Integer value to be formatted.\n */\n private static integerPartToText(wholePart: number, spec: FormatterSpec): string {\n // build invariant string represent wholePart\n let formattedValue = wholePart.toFixed(0);\n\n if ((formattedValue.length > 3) && (spec.format.hasFormatTraitSet(FormatTraits.Use1000Separator) && (spec.format.thousandSeparator.length > 0))) {\n let numSeparators = Math.floor(formattedValue.length / 3);\n let groupLength = formattedValue.length % 3;\n\n if (groupLength === 0) {\n numSeparators = numSeparators - 1;\n groupLength = groupLength + 3;\n }\n\n let outString = formattedValue.substring(0, groupLength);\n\n for (let i = 1; i <= numSeparators; i += 1) {\n outString = outString + spec.format.thousandSeparator + formattedValue.substring(groupLength, groupLength + 3);\n groupLength = groupLength + 3;\n }\n\n formattedValue = outString;\n }\n\n return formattedValue;\n }\n\n /** Trim trailing \"0\" from the text that represent the fractional part of a floating point value.\n * @param strVal The value string.\n */\n private static trimTrailingZeroes(strVal: string): string {\n let lastNonZeroCharIndex = -1;\n for (let i = strVal.length - 1; i >= 0; i--) {\n if (strVal.charCodeAt(i) !== QuantityConstants.CHAR_DIGIT_ZERO) {\n lastNonZeroCharIndex = i;\n break;\n }\n }\n if (lastNonZeroCharIndex >= 0)\n return strVal.substring(0, lastNonZeroCharIndex + 1);\n return \"\";\n }\n\n /** Format a quantity value into a composite format such as ft-in or deg-min-sec.\n * @param compositeValue The value for this part of the composite\n * @param isLastPart If false the composite value should be a whole value, if true then the value should be formatted as a floating point value.\n * @param label Label for this part of the composite. This will be either the default unit label or a custom label specified the format specification.\n */\n private static formatCompositePart(compositeValue: number, isLastPart: boolean, label: string, spec: FormatterSpec): string {\n let componentText = \"\";\n if (!isLastPart) {\n componentText = Formatter.integerPartToText(compositeValue, spec);\n if(spec.format.minWidth) { // integerPartToText does not do this padding\n componentText = this.countAndPad(componentText, spec.format.minWidth);\n }\n } else {\n componentText = Formatter.formatMagnitude(compositeValue, spec);\n }\n\n if (spec.format.hasFormatTraitSet(FormatTraits.ShowUnitLabel)) {\n componentText = componentText + spec.format.uomSeparator + label;\n }\n\n return componentText;\n }\n\n /** Format a quantity value into a composite format such as ft-in or deg-min-sec.\n * @param magnitude quantity value\n * @param fromUnit quantity unit\n */\n private static formatComposite(magnitude: number, spec: FormatterSpec): string {\n const compositeStrings: string[] = [];\n\n // Caller will deal with appending +||-||() value sign as specified by formatting options so just format positive value\n let posMagnitude = Math.abs(magnitude);\n\n for (let i = 0; i < spec.unitConversions.length; i++) {\n const currentLabel = spec.unitConversions[i].label;\n const unitConversion = spec.unitConversions[i].conversion;\n\n if (i > 0 && unitConversion.factor < 1.0)\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification.`);\n if (i > 0 && unitConversion.offset !== 0) // offset should only ever be defined for major unit\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification.`);\n\n let unitValue = 0.0;\n if (spec.format.type === FormatType.Ratio){\n if (1 !== spec.format.units!.length)\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has an invalid unit specification, we require single presentation unit when using format type 'ratio'`);\n\n try {\n unitValue = applyConversion(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;\n } catch (e) {\n // The \"InvertingZero\" error is thrown when the value is zero and the conversion factor is inverted.\n // For ratio, we actually want to support this corner case and return \"1:0\" as the formatted value.\n if (e instanceof QuantityError && e.errorNumber === QuantityStatus.InvertingZero) {\n return \"1:0\";\n }\n }\n\n compositeStrings.push(this.formatRatio(unitValue, spec));\n continue;\n }\n\n unitValue = applyConversion(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;\n\n if (0 === i) {\n const precisionScale = Math.pow(10, 8); // use a fixed round off precision of 8 to avoid loss of precision in actual magnitude\n unitValue = Math.floor(unitValue * precisionScale + FPV_ROUNDFACTOR) / precisionScale;\n if ((Math.abs(unitValue) < 0.0001) && spec.format.hasFormatTraitSet(FormatTraits.ZeroEmpty))\n return \"\";\n }\n\n if (i < spec.format.units!.length - 1) {\n const wholePart = Math.floor(unitValue);\n const componentText = Formatter.formatCompositePart(wholePart, false, currentLabel, spec);\n posMagnitude = unitValue - wholePart;\n compositeStrings.push(componentText);\n } else {\n const componentText = Formatter.formatCompositePart(unitValue, true, currentLabel, spec);\n compositeStrings.push(componentText);\n }\n }\n\n return compositeStrings.join(spec.format.spacerOrDefault);\n }\n\n /** Format a quantity value into a single text string. Imitate how formatting done by server method NumericFormatSpec::FormatDouble.\n * @param magnitude quantity value\n */\n private static formatMagnitude(magnitude: number, spec: FormatterSpec): string {\n let posMagnitude = Math.abs(magnitude);\n if ((Math.abs(posMagnitude) < 0.0001) && spec.format.hasFormatTraitSet(FormatTraits.ZeroEmpty))\n return \"\";\n\n if (spec.format.hasFormatTraitSet(FormatTraits.ApplyRounding))\n posMagnitude = Math.abs(Formatter.roundDouble(magnitude, spec.format.roundFactor));\n\n const isSci = ((posMagnitude > 1.0e12) || spec.format.type === FormatType.Scientific);\n const isDecimal = (isSci || spec.format.type === FormatType.Decimal || spec.format.type === FormatType.Bearing || spec.format.type === FormatType.Azimuth) || spec.format.type === FormatType.Ratio;\n const isFractional = (!isDecimal && spec.format.type === FormatType.Fractional);\n /* const usesStops = spec.format.type === FormatType.Station; */\n const isPrecisionZero = spec.format.precision === DecimalPrecision.Zero;\n const isKeepSingleZero = spec.format.hasFormatTraitSet(FormatTraits.KeepSingleZero);\n const precisionScale = Math.pow(10.0, spec.format.precision);\n const isKeepTrailingZeroes = spec.format.hasFormatTraitSet(FormatTraits.TrailZeroes);\n let expInt = 0.0;\n\n if (isSci && (posMagnitude !== 0.0)) {\n let exp = Math.log10(posMagnitude);\n let negativeExp = false;\n if (exp < 0.0) {\n exp = -exp;\n negativeExp = true;\n }\n\n expInt = Math.floor(exp);\n if (spec.format.type === FormatType.Scientific) {\n if (spec.format.scientificType === ScientificType.ZeroNormalized && posMagnitude > 1.0)\n expInt += 1.0;\n else if (spec.format.scientificType === ScientificType.Normalized && posMagnitude < 1.0)\n expInt += 1.0;\n\n if (negativeExp)\n expInt = -expInt;\n }\n\n const factor = Math.pow(10.0, -expInt);\n posMagnitude *= factor;\n }\n\n let formattedValue = \"\";\n if (isDecimal) {\n const actualVal = isPrecisionZero ? posMagnitude + FPV_ROUNDFACTOR : posMagnitude + Formatter.FPV_MINTHRESHOLD;\n let wholePart = Math.floor(actualVal);\n let fractionPart = actualVal - wholePart;\n if (!isPrecisionZero) {\n fractionPart = Math.abs(fractionPart) * precisionScale + FPV_ROUNDFACTOR;\n if (fractionPart >= precisionScale) {\n wholePart += 1;\n fractionPart -= precisionScale;\n }\n }\n\n formattedValue = Formatter.integerPartToText(wholePart, spec);\n if (isPrecisionZero) {\n if (spec.format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint) && !isKeepSingleZero)\n formattedValue = formattedValue + spec.format.decimalSeparator;\n else if (isKeepSingleZero)\n formattedValue = `${formattedValue + spec.format.decimalSeparator}0`;\n } else {\n fractionPart = Math.floor(fractionPart) / precisionScale;\n let fractionString = fractionPart.toFixed(spec.format.precision);\n // remove leading \"0.\"\n fractionString = fractionString.substring(2).padEnd(spec.format.precision, \"0\");\n if (!isKeepTrailingZeroes)\n fractionString = Formatter.trimTrailingZeroes(fractionString);\n\n if (fractionString.length > 0)\n formattedValue = formattedValue + spec.format.decimalSeparator + fractionString;\n else {\n if (spec.format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint))\n formattedValue = formattedValue + spec.format.decimalSeparator + (isKeepSingleZero ? \"0\" : \"\");\n }\n }\n\n if (isSci) {\n const expString = `e${expInt.toFixed(0)}`;\n formattedValue = formattedValue + expString;\n }\n } else if (isFractional) {\n const fn = new FractionalNumeric(posMagnitude, spec.format.precision as FractionalPrecision, true);\n formattedValue = fn.getIntegralString();\n\n if (!fn.isZero && fn.hasFractionPart) {\n const wholeFractionSeparator = spec.format.hasFormatTraitSet(FormatTraits.FractionDash) ? \"-\" : \" \";\n const fractionString = `${fn.getNumeratorString()}/${fn.getDenominatorString()}`;\n formattedValue = formattedValue + wholeFractionSeparator + fractionString;\n }\n } else /* if (usesStops)*/ {\n // we assume that stopping value is always positive\n posMagnitude = Math.floor(posMagnitude * precisionScale + FPV_ROUNDFACTOR) / precisionScale;\n\n const denominator = (Math.pow(10, spec.format.stationOffsetSize!));\n const tVal = Math.floor(posMagnitude); // this is the integer part only\n const hiPart = Math.floor(tVal / denominator);\n const lowPart = tVal - hiPart * denominator;\n const fract = posMagnitude - tVal;\n const fractionPart = Math.floor(fract * precisionScale + FPV_ROUNDFACTOR);\n const stationString = hiPart.toFixed(0) + spec.format.stationSeparator + lowPart.toFixed(0).padStart(spec.format.stationOffsetSize!, \"0\");\n let fractionString = \"\";\n if (fractionPart > 0) {\n fractionString = (fractionPart/precisionScale).toFixed(spec.format.precision);\n // remove leading \"0.\"\n fractionString = fractionString.substring(2).padEnd(spec.format.precision, \"0\");\n if (!isKeepTrailingZeroes)\n fractionString = Formatter.trimTrailingZeroes(fractionString);\n\n formattedValue = stationString + spec.format.decimalSeparator + fractionString;\n } else {\n if (isKeepTrailingZeroes)\n fractionString = spec.format.decimalSeparator + \"\".padEnd(spec.format.precision, \"0\");\n else if (spec.format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint))\n fractionString = spec.format.decimalSeparator;\n formattedValue = stationString + fractionString;\n }\n }\n\n if(spec.format.minWidth) {\n formattedValue = this.countAndPad(formattedValue, spec.format.minWidth);\n }\n\n return formattedValue;\n }\n\n private static countAndPad(value: string, minWidth: number): string {\n const regex = /[\\d,.]/g;\n const matches = value.match(regex);\n const count = matches ? matches.length : 0;\n if (count < minWidth) {\n value = value.padStart(minWidth, \"0\");\n }\n return value;\n }\n\n /** Format a quantity value into a single text string based on the current format specification of this class.\n * @param magnitude defines the value to spec.format.\n * @param spec A FormatterSpec object the defines specification for the magnitude and unit conversions for the formatter.\n */\n public static formatQuantity(magnitude: number, spec: FormatterSpec): string {\n const valueIsNegative = magnitude < 0.0;\n let prefix = \"\";\n let suffix = \"\";\n let formattedValue = \"\";\n if(spec.format.type === FormatType.Bearing || spec.format.type === FormatType.Azimuth) {\n const result = this.processBearingAndAzimuth(magnitude, spec);\n magnitude = result.magnitude;\n prefix = result.prefix ?? \"\";\n suffix = result.suffix ?? \"\";\n }\n\n switch (spec.format.showSignOption) {\n case ShowSignOption.NegativeParentheses:\n if (valueIsNegative) {\n prefix += \"(\";\n suffix = `)${suffix}`;\n }\n break;\n\n case ShowSignOption.OnlyNegative:\n if (valueIsNegative)\n prefix += \"-\";\n\n break;\n\n case ShowSignOption.SignAlways:\n if (valueIsNegative)\n prefix += \"-\";\n else\n prefix += \"+\";\n\n break;\n\n case ShowSignOption.NoSign:\n default:\n break;\n }\n\n let formattedMagnitude = \"\";\n\n if (spec.format.hasUnits) {\n formattedMagnitude = Formatter.formatComposite(magnitude, spec);\n } else {\n // unitless quantity\n formattedMagnitude = Formatter.formatMagnitude(magnitude, spec);\n if (formattedMagnitude.length > 0 && spec.unitConversions.length > 0 && spec.format.hasFormatTraitSet(FormatTraits.ShowUnitLabel)) {\n if (spec.format.hasFormatTraitSet(FormatTraits.PrependUnitLabel))\n formattedMagnitude = spec.unitConversions[0].label + spec.format.uomSeparator + formattedMagnitude;\n else\n formattedMagnitude = formattedMagnitude + spec.format.uomSeparator + spec.unitConversions[0].label;\n }\n }\n // add Sign prefix and suffix as necessary\n if ((prefix.length > 0 || suffix.length > 0) && formattedMagnitude.length > 0)\n formattedValue = prefix + formattedMagnitude + suffix;\n else\n formattedValue = formattedMagnitude;\n\n return formattedValue;\n }\n\n private static processBearingAndAzimuth(magnitude: number, spec: FormatterSpec): {magnitude: number, prefix?: string, suffix?: string} {\n const type = spec.format.type;\n if (type !== FormatType.Bearing && type !== FormatType.Azimuth)\n return {magnitude};\n\n const revolution = this.getRevolution(spec);\n magnitude = this.normalizeAngle(magnitude, revolution);\n const quarterRevolution = revolution / 4;\n\n if (type === FormatType.Bearing) {\n let quadrant = 0;\n while (magnitude > quarterRevolution) {\n magnitude -= quarterRevolution;\n quadrant++;\n }\n let prefix, suffix: string;\n\n // Quadrants are\n // 3 0\n // 2 1\n // For quadrants 1 and 3 we have to subtract the angle from quarterRevolution degrees because they go counter-clockwise\n if (quadrant === 1 || quadrant === 3)\n magnitude = quarterRevolution - magnitude;\n\n // TODO: at some point we will want to open this for localization, in the first release it's going to be hard coded\n if (quadrant === 0 || quadrant === 3)\n prefix = \"N\";\n\n if (quadrant === 2 || quadrant === 1)\n prefix = \"S\";\n\n if (quadrant === 0 || quadrant === 1)\n suffix = \"E\";\n\n if (quadrant === 3 || quadrant === 2)\n suffix = \"W\";\n\n // special case, if in quadrant 2 and value is very close to quarter revolution (90°), turn prefix to N because N90:00:00W is preferred over S90:00:00W\n if (quadrant === 2 && spec.unitConversions.length > 0) {\n // To determine if value is small, we need to convert it to the smallest unit presented and use the provided precision on it\n const unitConversion = spec.unitConversions[spec.unitConversions.length - 1].conversion;\n const smallestFormattedDelta = applyConversion((quarterRevolution - magnitude), unitConversion) + this.FPV_MINTHRESHOLD;\n\n const precisionScale = Math.pow(10.0, spec.format.precision);\n const floor = Math.floor((smallestFormattedDelta) * precisionScale + FPV_ROUNDFACTOR) / precisionScale;\n if(floor === 0) {\n prefix = \"N\";\n }\n }\n\n return {magnitude, prefix, suffix: suffix!};\n }\n\n if (type === FormatType.Azimuth) {\n let azimuthBase = 0; // default base is North\n if (spec.format.azimuthBase !== undefined) {\n if (spec.azimuthBaseConversion === undefined) {\n throw new QuantityError(QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.name}'s azimuth base.`);\n }\n const azBaseQuantity: Quantity = new Quantity(spec.format.azimuthBaseUnit, spec.format.azimuthBase);\n const azBaseConverted = azBaseQuantity.convertTo(spec.persistenceUnit, spec.azimuthBaseConversion);\n if (azBaseConverted === undefined || !azBaseConverted.isValid) {\n throw new QuantityError(QuantityStatus.UnsupportedUnit, `Failed to convert azimuth base unit to ${spec.persistenceUnit.name}.`);\n }\n azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);\n }\n\n if (azimuthBase === 0.0 && spec.format.azimuthClockwiseOrDefault)\n return {magnitude}; // no conversion necessary, the input is already using the result parameters (north base and clockwise)\n\n // subtract the base from the actual value\n magnitude -= azimuthBase;\n if (spec.format.azimuthClockwiseOrDefault)\n return {magnitude: this.normalizeAngle(magnitude, revolution)};\n\n // turn it into a counter-clockwise angle\n magnitude = revolution - magnitude;\n // normalize the result as it may have become negative or exceed the revolution\n magnitude = this.normalizeAngle(magnitude, revolution);\n }\n\n return {magnitude};\n }\n\n private static normalizeAngle(magnitude: number, revolution: number): number {\n magnitude = magnitude % revolution; // Strip anything that goes around more than once\n\n if (magnitude < 0) // If the value is negative, we want to normalize it to a positive angle\n magnitude += revolution;\n\n return magnitude;\n }\n\n private static getRevolution(spec: FormatterSpec): number {\n if (spec.revolutionConversion === undefined) {\n throw new QuantityError(QuantityStatus.MissingRequiredProperty, `Missing revolution unit conversion for calculating ${spec.name}'s revolution.`);\n }\n\n const revolution: Quantity = new Quantity(spec.format.revolutionUnit, 1.0);\n const converted = revolution.convertTo(spec.persistenceUnit, spec.revolutionConversion);\n if (converted === undefined || !converted.isValid) {\n throw new QuantityError(QuantityStatus.UnsupportedUnit, `Failed to convert revolution unit to ${spec.persistenceUnit.name}.`);\n }\n\n return converted.magnitude;\n }\n\n private static formatRatio(magnitude: number, spec: FormatterSpec): string {\n if (null === spec.format.ratioType)\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} must have a ratio type specified.`);\n\n const precisionScale = Math.pow(10.0, spec.format.precision);\n\n let reciprocal = 0;\n\n if (magnitude === 0.0)\n return \"0:1\";\n else\n reciprocal = 1.0/magnitude;\n\n switch (spec.format.ratioType) {\n case RatioType.OneToN:\n return `1:${this.formatMagnitude(reciprocal, spec)}`;\n case RatioType.NToOne:\n return `${this.formatMagnitude(magnitude, spec)}:1`;\n case RatioType.ValueBased:\n if (magnitude > 1.0)\n return `${this.formatMagnitude(magnitude, spec)}:1`;\n else\n return `1:${this.formatMagnitude(reciprocal, spec)}`;\n case RatioType.UseGreatestCommonDivisor:\n magnitude = Math.round(magnitude * precisionScale)/precisionScale;\n let numerator = magnitude * precisionScale;\n let denominator = precisionScale;\n\n const gcd = FractionalNumeric.getGreatestCommonFactor(numerator, denominator);\n numerator /= gcd;\n denominator /= gcd;\n\n return `${this.formatMagnitude(numerator, spec)}:${this.formatMagnitude(denominator, spec)}`;\n default:\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has an invalid ratio type specified.`);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Formatter.js","sourceRoot":"","sources":["../../../src/Formatter/Formatter.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,4CAAiD;AACjD,4CAA6D;AAE7D,+CAA2I;AAC3I,0CAAwD;AAExD;;GAEG;AACH,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC;;GAEG;AACH,MAAM,iBAAiB;IACb,SAAS,GAAW,CAAC,CAAC;IACtB,UAAU,GAAW,CAAC,CAAC;IACvB,YAAY,GAAW,CAAC,CAAC;IACzB,qBAAqB,GAAW,CAAC,CAAC;IAClC,UAAU,GAAa,EAAE,CAAC;IAElC,YAAY,KAAa,EAAE,SAA8B,EAAE,MAAe;QACxE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,SAAmB,CAAC,CAAC;QAC3C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAEO,SAAS,CAAC,KAAa,EAAE,WAAmB;QAClD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC3C,MAAM,YAAY,GAAG,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC;QACpD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC,CAAC;QAEjF,IAAI,CAAC,K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------------------------------------------------------------------------------\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 { QuantityConstants } from \"../Constants\";\nimport { QuantityError, QuantityStatus } from \"../Exception\";\nimport { FormatterSpec } from \"./FormatterSpec\";\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision, RatioType, ScientificType, ShowSignOption } from \"./FormatEnums\";\nimport { applyConversion, Quantity } from \"../Quantity\";\n\n/** rounding additive\n * @internal\n */\nconst FPV_ROUNDFACTOR = 0.50000000001;\n\n/** A private helper class used to format fraction part of value into a numerator and denominator.\n * @internal\n */\nclass FractionalNumeric {\n private _integral: number = 0;\n private _numerator: number = 0;\n private _denominator: number = 1;\n private _greatestCommonFactor: number = 1;\n private _textParts: string[] = [];\n\n constructor(value: number, precision: FractionalPrecision, reduce: boolean) {\n this.calculate(value, precision as number);\n this.formTextParts(reduce);\n }\n\n private calculate(value: number, denominator: number) {\n const positiveValue = Math.abs(value);\n this._denominator = denominator;\n this._integral = Math.floor(positiveValue);\n const fractionPart = positiveValue - this._integral;\n this._numerator = Math.floor(fractionPart * this._denominator + FPV_ROUNDFACTOR);\n\n if (0 !== denominator && (this._numerator / this._denominator) === 1) {\n this._numerator = 0;\n this._integral += 1;\n } else {\n this._greatestCommonFactor = FractionalNumeric.getGreatestCommonFactor(this._numerator, this._denominator);\n }\n }\n\n /** Determine the GCD given two values. This value can be used to reduce a fraction.\n * See algorithm description http://en.wikipedia.org/wiki/Euclidean_algorithm\n */\n public static getGreatestCommonFactor(numerator: number, denominator: number): number {\n let r;\n while (denominator !== 0) {\n r = numerator % denominator;\n numerator = denominator;\n denominator = r;\n }\n return (numerator < 0) ? -numerator : numerator;\n }\n\n public get greatestCommonFactor(): number { return this._greatestCommonFactor; }\n public get hasFractionPart(): boolean { return this._textParts.length > 0; }\n public get isZero(): boolean { return 0 === this._numerator; }\n\n public getIntegralString(): string {\n if (this._textParts.length > 0)\n return this._textParts[0];\n\n return \"\";\n }\n\n public getNumeratorString(): string {\n if (this._textParts.length >= 3)\n return this._textParts[1];\n\n return \"\";\n }\n\n public getDenominatorString(): string {\n if (this._textParts.length >= 3)\n return this._textParts[2];\n\n return \"\";\n }\n\n private formTextParts(reduce: boolean): void {\n let numerator = this._numerator;\n let denominator = this._denominator;\n\n if (reduce && this._greatestCommonFactor > 1) {\n numerator /= this.greatestCommonFactor;\n denominator /= this.greatestCommonFactor;\n }\n\n this._textParts.push(this._integral.toFixed(0));\n if (numerator > 0) {\n this._textParts.push(numerator.toFixed(0));\n this._textParts.push(denominator.toFixed(0));\n }\n }\n}\n\n/** A helper class that contains methods used to format quantity values based on a format that are defined via the Format class.\n * @beta\n */\nexport class Formatter {\n private static FPV_MINTHRESHOLD = 1.0e-14;\n\n private static isNegligible(value: number): boolean { return (Math.abs(value) < Formatter.FPV_MINTHRESHOLD); }\n\n /** Return floating point value rounded by specific rounding factor.\n * @param value Value to be rounded.\n * @param roundTo Rounding factor.\n */\n private static roundDouble(value: number, roundTo: number): number {\n if (Formatter.isNegligible(roundTo))\n return value;\n\n roundTo = Math.abs(roundTo);\n let rnd = FPV_ROUNDFACTOR + (value / roundTo);\n const iVal = Math.floor(rnd);\n rnd = iVal * roundTo;\n return (value < 0.0) ? -rnd : rnd;\n }\n\n /** Generate a formatted text string integer value insert 1000 separators if appropriate.\n * @param wholePart Integer value to be formatted.\n */\n private static integerPartToText(wholePart: number, spec: FormatterSpec): string {\n // build invariant string represent wholePart\n let formattedValue = wholePart.toFixed(0);\n\n if ((formattedValue.length > 3) && (spec.format.hasFormatTraitSet(FormatTraits.Use1000Separator) && (spec.format.thousandSeparator.length > 0))) {\n let numSeparators = Math.floor(formattedValue.length / 3);\n let groupLength = formattedValue.length % 3;\n\n if (groupLength === 0) {\n numSeparators = numSeparators - 1;\n groupLength = groupLength + 3;\n }\n\n let outString = formattedValue.substring(0, groupLength);\n\n for (let i = 1; i <= numSeparators; i += 1) {\n outString = outString + spec.format.thousandSeparator + formattedValue.substring(groupLength, groupLength + 3);\n groupLength = groupLength + 3;\n }\n\n formattedValue = outString;\n }\n\n return formattedValue;\n }\n\n /** Trim trailing \"0\" from the text that represent the fractional part of a floating point value.\n * @param strVal The value string.\n */\n private static trimTrailingZeroes(strVal: string): string {\n let lastNonZeroCharIndex = -1;\n for (let i = strVal.length - 1; i >= 0; i--) {\n if (strVal.charCodeAt(i) !== QuantityConstants.CHAR_DIGIT_ZERO) {\n lastNonZeroCharIndex = i;\n break;\n }\n }\n if (lastNonZeroCharIndex >= 0)\n return strVal.substring(0, lastNonZeroCharIndex + 1);\n return \"\";\n }\n\n /** Format a quantity value into a composite format such as ft-in or deg-min-sec.\n * @param compositeValue The value for this part of the composite\n * @param isLastPart If false the composite value should be a whole value, if true then the value should be formatted as a floating point value.\n * @param label Label for this part of the composite. This will be either the default unit label or a custom label specified the format specification.\n */\n private static formatCompositePart(compositeValue: number, isLastPart: boolean, label: string, spec: FormatterSpec): string {\n let componentText = \"\";\n if (!isLastPart) {\n componentText = Formatter.integerPartToText(compositeValue, spec);\n if(spec.format.minWidth) { // integerPartToText does not do this padding\n componentText = this.countAndPad(componentText, spec.format.minWidth);\n }\n } else {\n componentText = Formatter.formatMagnitude(compositeValue, spec);\n }\n\n if (spec.format.hasFormatTraitSet(FormatTraits.ShowUnitLabel)) {\n componentText = componentText + spec.format.uomSeparator + label;\n }\n\n return componentText;\n }\n\n /** Format a quantity value into a composite format such as ft-in or deg-min-sec.\n * @param magnitude quantity value\n * @param fromUnit quantity unit\n */\n private static formatComposite(magnitude: number, spec: FormatterSpec): string {\n const compositeStrings: string[] = [];\n\n // Caller will deal with appending +||-||() value sign as specified by formatting options so just format positive value\n let posMagnitude = Math.abs(magnitude);\n\n for (let i = 0; i < spec.unitConversions.length; i++) {\n const currentLabel = spec.unitConversions[i].label;\n const unitConversion = spec.unitConversions[i].conversion;\n\n if (i > 0 && unitConversion.factor < 1.0)\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification.`);\n if (i > 0 && unitConversion.offset !== 0) // offset should only ever be defined for major unit\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has a invalid unit specification.`);\n\n let unitValue = 0.0;\n if (spec.format.type === FormatType.Ratio){\n if (1 !== spec.format.units!.length)\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format '${spec.format.name}' with type 'ratio' must have exactly one unit.`);\n\n try {\n unitValue = applyConversion(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;\n } catch (e) {\n // The \"InvertingZero\" error is thrown when the value is zero and the conversion factor is inverted.\n // For ratio, we actually want to support this corner case and return \"1:0\" as the formatted value.\n if (e instanceof QuantityError && e.errorNumber === QuantityStatus.InvertingZero) {\n return \"1:0\";\n }\n }\n\n compositeStrings.push(this.formatRatio(unitValue, spec));\n continue;\n }\n\n unitValue = applyConversion(posMagnitude, unitConversion) + this.FPV_MINTHRESHOLD;\n\n if (0 === i) {\n const precisionScale = Math.pow(10, 8); // use a fixed round off precision of 8 to avoid loss of precision in actual magnitude\n unitValue = Math.floor(unitValue * precisionScale + FPV_ROUNDFACTOR) / precisionScale;\n if ((Math.abs(unitValue) < 0.0001) && spec.format.hasFormatTraitSet(FormatTraits.ZeroEmpty))\n return \"\";\n }\n\n if (i < spec.format.units!.length - 1) {\n const wholePart = Math.floor(unitValue);\n const componentText = Formatter.formatCompositePart(wholePart, false, currentLabel, spec);\n posMagnitude = unitValue - wholePart;\n compositeStrings.push(componentText);\n } else {\n const componentText = Formatter.formatCompositePart(unitValue, true, currentLabel, spec);\n compositeStrings.push(componentText);\n }\n }\n\n return compositeStrings.join(spec.format.spacerOrDefault);\n }\n\n /** Format a quantity value into a single text string. Imitate how formatting done by server method NumericFormatSpec::FormatDouble.\n * @param magnitude quantity value\n */\n private static formatMagnitude(magnitude: number, spec: FormatterSpec): string {\n let posMagnitude = Math.abs(magnitude);\n if ((Math.abs(posMagnitude) < 0.0001) && spec.format.hasFormatTraitSet(FormatTraits.ZeroEmpty))\n return \"\";\n\n if (spec.format.hasFormatTraitSet(FormatTraits.ApplyRounding))\n posMagnitude = Math.abs(Formatter.roundDouble(magnitude, spec.format.roundFactor));\n\n const isSci = ((posMagnitude > 1.0e12) || spec.format.type === FormatType.Scientific);\n const isDecimal = (isSci || spec.format.type === FormatType.Decimal || spec.format.type === FormatType.Bearing || spec.format.type === FormatType.Azimuth) || spec.format.type === FormatType.Ratio;\n const isFractional = (!isDecimal && spec.format.type === FormatType.Fractional);\n /* const usesStops = spec.format.type === FormatType.Station; */\n const isPrecisionZero = spec.format.precision === DecimalPrecision.Zero;\n const isKeepSingleZero = spec.format.hasFormatTraitSet(FormatTraits.KeepSingleZero);\n const precisionScale = Math.pow(10.0, spec.format.precision);\n const isKeepTrailingZeroes = spec.format.hasFormatTraitSet(FormatTraits.TrailZeroes);\n let expInt = 0.0;\n\n if (isSci && (posMagnitude !== 0.0)) {\n let exp = Math.log10(posMagnitude);\n let negativeExp = false;\n if (exp < 0.0) {\n exp = -exp;\n negativeExp = true;\n }\n\n expInt = Math.floor(exp);\n if (spec.format.type === FormatType.Scientific) {\n if (spec.format.scientificType === ScientificType.ZeroNormalized && posMagnitude > 1.0)\n expInt += 1.0;\n else if (spec.format.scientificType === ScientificType.Normalized && posMagnitude < 1.0)\n expInt += 1.0;\n\n if (negativeExp)\n expInt = -expInt;\n }\n\n const factor = Math.pow(10.0, -expInt);\n posMagnitude *= factor;\n }\n\n let formattedValue = \"\";\n if (isDecimal) {\n const actualVal = isPrecisionZero ? posMagnitude + FPV_ROUNDFACTOR : posMagnitude + Formatter.FPV_MINTHRESHOLD;\n let wholePart = Math.floor(actualVal);\n let fractionPart = actualVal - wholePart;\n if (!isPrecisionZero) {\n fractionPart = Math.abs(fractionPart) * precisionScale + FPV_ROUNDFACTOR;\n if (fractionPart >= precisionScale) {\n wholePart += 1;\n fractionPart -= precisionScale;\n }\n }\n\n formattedValue = Formatter.integerPartToText(wholePart, spec);\n if (isPrecisionZero) {\n if (spec.format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint) && !isKeepSingleZero)\n formattedValue = formattedValue + spec.format.decimalSeparator;\n else if (isKeepSingleZero)\n formattedValue = `${formattedValue + spec.format.decimalSeparator}0`;\n } else {\n fractionPart = Math.floor(fractionPart) / precisionScale;\n let fractionString = fractionPart.toFixed(spec.format.precision);\n // remove leading \"0.\"\n fractionString = fractionString.substring(2).padEnd(spec.format.precision, \"0\");\n if (!isKeepTrailingZeroes)\n fractionString = Formatter.trimTrailingZeroes(fractionString);\n\n if (fractionString.length > 0)\n formattedValue = formattedValue + spec.format.decimalSeparator + fractionString;\n else {\n if (spec.format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint))\n formattedValue = formattedValue + spec.format.decimalSeparator + (isKeepSingleZero ? \"0\" : \"\");\n }\n }\n\n if (isSci) {\n const expString = `e${expInt.toFixed(0)}`;\n formattedValue = formattedValue + expString;\n }\n } else if (isFractional) {\n const fn = new FractionalNumeric(posMagnitude, spec.format.precision as FractionalPrecision, true);\n formattedValue = fn.getIntegralString();\n\n if (!fn.isZero && fn.hasFractionPart) {\n const wholeFractionSeparator = spec.format.hasFormatTraitSet(FormatTraits.FractionDash) ? \"-\" : \" \";\n const fractionString = `${fn.getNumeratorString()}/${fn.getDenominatorString()}`;\n formattedValue = formattedValue + wholeFractionSeparator + fractionString;\n }\n } else /* if (usesStops)*/ {\n // we assume that stopping value is always positive\n posMagnitude = Math.floor(posMagnitude * precisionScale + FPV_ROUNDFACTOR) / precisionScale;\n\n const baseFactor = spec.format.stationBaseFactor ?? 1;\n const stationOffsetSize = spec.format.stationOffsetSize || 0; // Provide default if undefined\n const denominator = baseFactor * Math.pow(10, stationOffsetSize);\n const tVal = Math.floor(posMagnitude); // this is the integer part only\n const hiPart = Math.floor(tVal / denominator);\n const lowPart = tVal - hiPart * denominator;\n const fract = posMagnitude - tVal;\n const fractionPart = Math.floor(fract * precisionScale + FPV_ROUNDFACTOR);\n const stationString = hiPart.toFixed(0) + spec.format.stationSeparator + lowPart.toFixed(0).padStart(stationOffsetSize, \"0\");\n let fractionString = \"\";\n if (fractionPart > 0) {\n fractionString = (fractionPart/precisionScale).toFixed(spec.format.precision);\n // remove leading \"0.\"\n fractionString = fractionString.substring(2).padEnd(spec.format.precision, \"0\");\n if (!isKeepTrailingZeroes)\n fractionString = Formatter.trimTrailingZeroes(fractionString);\n\n formattedValue = stationString + spec.format.decimalSeparator + fractionString;\n } else {\n if (isKeepTrailingZeroes)\n fractionString = spec.format.decimalSeparator + \"\".padEnd(spec.format.precision, \"0\");\n else if (spec.format.hasFormatTraitSet(FormatTraits.KeepDecimalPoint))\n fractionString = spec.format.decimalSeparator;\n formattedValue = stationString + fractionString;\n }\n }\n\n if(spec.format.minWidth) {\n formattedValue = this.countAndPad(formattedValue, spec.format.minWidth);\n }\n\n return formattedValue;\n }\n\n private static countAndPad(value: string, minWidth: number): string {\n const regex = /[\\d,.]/g;\n const matches = value.match(regex);\n const count = matches ? matches.length : 0;\n if (count < minWidth) {\n value = value.padStart(minWidth, \"0\");\n }\n return value;\n }\n\n /** Format a quantity value into a single text string based on the current format specification of this class.\n * @param magnitude defines the value to spec.format.\n * @param spec A FormatterSpec object the defines specification for the magnitude and unit conversions for the formatter.\n */\n public static formatQuantity(magnitude: number, spec: FormatterSpec): string {\n const valueIsNegative = magnitude < 0.0;\n let prefix = \"\";\n let suffix = \"\";\n let formattedValue = \"\";\n if(spec.format.type === FormatType.Bearing || spec.format.type === FormatType.Azimuth) {\n const result = this.processBearingAndAzimuth(magnitude, spec);\n magnitude = result.magnitude;\n prefix = result.prefix ?? \"\";\n suffix = result.suffix ?? \"\";\n }\n\n switch (spec.format.showSignOption) {\n case ShowSignOption.NegativeParentheses:\n if (valueIsNegative) {\n prefix += \"(\";\n suffix = `)${suffix}`;\n }\n break;\n\n case ShowSignOption.OnlyNegative:\n if (valueIsNegative && spec.format.type !== FormatType.Bearing && spec.format.type !== FormatType.Azimuth)\n prefix += \"-\";\n\n break;\n\n case ShowSignOption.SignAlways:\n if (valueIsNegative)\n prefix += \"-\";\n else\n prefix += \"+\";\n\n break;\n\n case ShowSignOption.NoSign:\n default:\n break;\n }\n\n let formattedMagnitude = \"\";\n\n if (spec.format.hasUnits) {\n formattedMagnitude = Formatter.formatComposite(magnitude, spec);\n } else {\n // unitless quantity\n formattedMagnitude = Formatter.formatMagnitude(magnitude, spec);\n if (formattedMagnitude.length > 0 && spec.unitConversions.length > 0 && spec.format.hasFormatTraitSet(FormatTraits.ShowUnitLabel)) {\n if (spec.format.hasFormatTraitSet(FormatTraits.PrependUnitLabel))\n formattedMagnitude = spec.unitConversions[0].label + spec.format.uomSeparator + formattedMagnitude;\n else\n formattedMagnitude = formattedMagnitude + spec.format.uomSeparator + spec.unitConversions[0].label;\n }\n }\n // add Sign prefix and suffix as necessary\n if ((prefix.length > 0 || suffix.length > 0) && formattedMagnitude.length > 0)\n formattedValue = prefix + formattedMagnitude + suffix;\n else\n formattedValue = formattedMagnitude;\n\n return formattedValue;\n }\n\n private static processBearingAndAzimuth(magnitude: number, spec: FormatterSpec): {magnitude: number, prefix?: string, suffix?: string} {\n const type = spec.format.type;\n if (type !== FormatType.Bearing && type !== FormatType.Azimuth)\n return {magnitude};\n\n const revolution = this.getRevolution(spec);\n magnitude = this.normalizeAngle(magnitude, revolution);\n const quarterRevolution = revolution / 4;\n\n if (type === FormatType.Bearing) {\n let quadrant = 0;\n while (magnitude > quarterRevolution) {\n magnitude -= quarterRevolution;\n quadrant++;\n }\n let prefix, suffix: string;\n\n // Quadrants are\n // 3 0\n // 2 1\n // For quadrants 1 and 3 we have to subtract the angle from quarterRevolution degrees because they go counter-clockwise\n if (quadrant === 1 || quadrant === 3)\n magnitude = quarterRevolution - magnitude;\n\n // TODO: at some point we will want to open this for localization, in the first release it's going to be hard coded\n if (quadrant === 0 || quadrant === 3)\n prefix = \"N\";\n\n if (quadrant === 2 || quadrant === 1)\n prefix = \"S\";\n\n if (quadrant === 0 || quadrant === 1)\n suffix = \"E\";\n\n if (quadrant === 3 || quadrant === 2)\n suffix = \"W\";\n\n // special case, if in quadrant 2 and value is very close to quarter revolution (90°), turn prefix to N because N90:00:00W is preferred over S90:00:00W\n if (quadrant === 2 && spec.unitConversions.length > 0) {\n // To determine if value is small, we need to convert it to the smallest unit presented and use the provided precision on it\n const unitConversion = spec.unitConversions[spec.unitConversions.length - 1].conversion;\n const smallestFormattedDelta = applyConversion((quarterRevolution - magnitude), unitConversion) + this.FPV_MINTHRESHOLD;\n\n const precisionScale = Math.pow(10.0, spec.format.precision);\n const floor = Math.floor((smallestFormattedDelta) * precisionScale + FPV_ROUNDFACTOR) / precisionScale;\n if(floor === 0) {\n prefix = \"N\";\n }\n }\n\n return {magnitude, prefix, suffix: suffix!};\n }\n\n if (type === FormatType.Azimuth) {\n let azimuthBase = 0; // default base is North\n if (spec.format.azimuthBase !== undefined) {\n if (spec.azimuthBaseConversion === undefined) {\n throw new QuantityError(QuantityStatus.MissingRequiredProperty, `Missing azimuth base conversion for interpreting ${spec.name}'s azimuth base.`);\n }\n const azBaseQuantity: Quantity = new Quantity(spec.format.azimuthBaseUnit, spec.format.azimuthBase);\n const azBaseConverted = azBaseQuantity.convertTo(spec.persistenceUnit, spec.azimuthBaseConversion);\n if (azBaseConverted === undefined || !azBaseConverted.isValid) {\n throw new QuantityError(QuantityStatus.UnsupportedUnit, `Failed to convert azimuth base unit to ${spec.persistenceUnit.name}.`);\n }\n azimuthBase = this.normalizeAngle(azBaseConverted.magnitude, revolution);\n }\n\n if (azimuthBase === 0.0 && spec.format.azimuthClockwiseOrDefault)\n return {magnitude}; // no conversion necessary, the input is already using the result parameters (north base and clockwise)\n\n // subtract the base from the actual value\n magnitude -= azimuthBase;\n if (spec.format.azimuthClockwiseOrDefault)\n return {magnitude: this.normalizeAngle(magnitude, revolution)};\n\n // turn it into a counter-clockwise angle\n magnitude = revolution - magnitude;\n // normalize the result as it may have become negative or exceed the revolution\n magnitude = this.normalizeAngle(magnitude, revolution);\n }\n\n return {magnitude};\n }\n\n private static normalizeAngle(magnitude: number, revolution: number): number {\n magnitude = magnitude % revolution; // Strip anything that goes around more than once\n\n if (magnitude < 0) // If the value is negative, we want to normalize it to a positive angle\n magnitude += revolution;\n\n return magnitude;\n }\n\n private static getRevolution(spec: FormatterSpec): number {\n if (spec.revolutionConversion === undefined) {\n throw new QuantityError(QuantityStatus.MissingRequiredProperty, `Missing revolution unit conversion for calculating ${spec.name}'s revolution.`);\n }\n\n const revolution: Quantity = new Quantity(spec.format.revolutionUnit, 1.0);\n const converted = revolution.convertTo(spec.persistenceUnit, spec.revolutionConversion);\n if (converted === undefined || !converted.isValid) {\n throw new QuantityError(QuantityStatus.UnsupportedUnit, `Failed to convert revolution unit to ${spec.persistenceUnit.name}.`);\n }\n\n return converted.magnitude;\n }\n\n private static formatRatio(magnitude: number, spec: FormatterSpec): string {\n if (null === spec.format.ratioType)\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} must have a ratio type specified.`);\n\n const precisionScale = Math.pow(10.0, spec.format.precision);\n\n let reciprocal = 0;\n\n if (magnitude === 0.0)\n return \"0:1\";\n else\n reciprocal = 1.0/magnitude;\n\n switch (spec.format.ratioType) {\n case RatioType.OneToN:\n return `1:${this.formatMagnitude(reciprocal, spec)}`;\n case RatioType.NToOne:\n return `${this.formatMagnitude(magnitude, spec)}:1`;\n case RatioType.ValueBased:\n if (magnitude > 1.0)\n return `${this.formatMagnitude(magnitude, spec)}:1`;\n else\n return `1:${this.formatMagnitude(reciprocal, spec)}`;\n case RatioType.UseGreatestCommonDivisor:\n magnitude = Math.round(magnitude * precisionScale)/precisionScale;\n let numerator = magnitude * precisionScale;\n let denominator = precisionScale;\n\n const gcd = FractionalNumeric.getGreatestCommonFactor(numerator, denominator);\n numerator /= gcd;\n denominator /= gcd;\n\n return `${this.formatMagnitude(numerator, spec)}:${this.formatMagnitude(denominator, spec)}`;\n default:\n throw new QuantityError(QuantityStatus.InvalidCompositeFormat, `The Format ${spec.format.name} has an invalid ratio type specified.`);\n }\n }\n}\n"]}
|
|
@@ -24,6 +24,8 @@ export interface FormatProps {
|
|
|
24
24
|
/** conditionally required. */
|
|
25
25
|
readonly stationOffsetSize?: number;
|
|
26
26
|
readonly stationSeparator?: string;
|
|
27
|
+
/** Optional base factor for station formatting. A positive integer, defaults to 1. */
|
|
28
|
+
readonly stationBaseFactor?: number;
|
|
27
29
|
/** The base value for azimuth, specified from east counter-clockwise. */
|
|
28
30
|
readonly azimuthBase?: number;
|
|
29
31
|
/** The name of the unit for the azimuth base value. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Interfaces.d.ts","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEhG;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,YA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H,cAAc,EAAE,KAAK,GAAG,MAAM,EAAE,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,CAAC;IAE/D,gBAAgB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,kBAAkB,KAAK,IAAI,CAAC,CAAC;CAC/D;AAED;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,eAAe;IAC7D,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACjE,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
|
|
@@ -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;;;AAgEH;;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 { BeEvent } from \"@itwin/core-bentley\";\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 /** Optional base factor for station formatting. A positive integer, defaults to 1. */\n readonly stationBaseFactor?: number;\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\n/** An extension of FormatProps to help identify formats.\n * @beta\n */\nexport interface FormatDefinition extends FormatProps {\n readonly name?: string;\n readonly label?: string;\n readonly description?: string;\n}\n\n/** Argument for [[FormatsProvider.onFormatsChanged]]\n * @beta\n */\nexport interface FormatsChangedArgs {\n /**\n * If `all` - all formats within the `FormatsProvider` have changed.\n * If array, the array items list the names of formats that were changed or removed.\n */\n formatsChanged: \"all\" | string[];\n}\n\n/** This interface is implemented by a class that would provide formats for use in formatting quantities.\n * @beta\n */\nexport interface FormatsProvider {\n /**\n * @param name The full name of the Format or KindOfQuantity.\n */\n getFormat(name: string): Promise<FormatDefinition | undefined>;\n\n onFormatsChanged: BeEvent<(args: FormatsChangedArgs) => void>;\n}\n\n/** This interface is implemented by a class that would provide and allow creating formats for use in formatting quantities.\n * @beta\n */\nexport interface MutableFormatsProvider extends FormatsProvider {\n addFormat(name: string, format: FormatDefinition): Promise<void>;\n removeFormat(name: string): Promise<void>;\n}\n"]}
|
package/lib/cjs/Parser.d.ts
CHANGED
|
@@ -15,7 +15,8 @@ export declare enum ParseError {
|
|
|
15
15
|
UnableToConvertParseTokensToQuantity = 5,
|
|
16
16
|
InvalidParserSpec = 6,
|
|
17
17
|
BearingPrefixOrSuffixMissing = 7,
|
|
18
|
-
MathematicOperationFoundButIsNotAllowed = 8
|
|
18
|
+
MathematicOperationFoundButIsNotAllowed = 8,
|
|
19
|
+
BearingAngleOutOfRange = 9
|
|
19
20
|
}
|
|
20
21
|
/** Parse error result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]].
|
|
21
22
|
* @beta
|
|
@@ -37,7 +38,9 @@ export interface ParsedQuantity {
|
|
|
37
38
|
}
|
|
38
39
|
declare enum Operator {
|
|
39
40
|
addition = "+",
|
|
40
|
-
subtraction = "-"
|
|
41
|
+
subtraction = "-",
|
|
42
|
+
multiplication = "*",// unsupported but we recognize it during parsing
|
|
43
|
+
division = "/"
|
|
41
44
|
}
|
|
42
45
|
/**
|
|
43
46
|
* Defines Results of parsing a string input by a user into its desired value type
|
|
@@ -106,9 +109,11 @@ export declare class Parser {
|
|
|
106
109
|
* @param inString A string that contains text represent a quantity.
|
|
107
110
|
* @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
|
|
108
111
|
* @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
|
|
109
|
-
* @deprecated in 4.10. Check [[Parser.parseQuantityString]] for replacements.
|
|
112
|
+
* @deprecated in 4.10 - will not be removed until after 2026-06-13. Check [[Parser.parseQuantityString]] for replacements.
|
|
110
113
|
*/
|
|
111
114
|
static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
|
|
115
|
+
/** The value of special direction is always in degrees, try to find the unit conversion for that. */
|
|
116
|
+
private static processSpecialBearingDirection;
|
|
112
117
|
private static parseBearingFormat;
|
|
113
118
|
private static parseAzimuthFormat;
|
|
114
119
|
private static parseRatioFormat;
|
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;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;
|
|
1
|
+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M,CAAC,8BAA8B;IAU7C,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAkFjC,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;IAepC,+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/cjs/Parser.js
CHANGED
|
@@ -25,11 +25,14 @@ var ParseError;
|
|
|
25
25
|
ParseError[ParseError["InvalidParserSpec"] = 6] = "InvalidParserSpec";
|
|
26
26
|
ParseError[ParseError["BearingPrefixOrSuffixMissing"] = 7] = "BearingPrefixOrSuffixMissing";
|
|
27
27
|
ParseError[ParseError["MathematicOperationFoundButIsNotAllowed"] = 8] = "MathematicOperationFoundButIsNotAllowed";
|
|
28
|
+
ParseError[ParseError["BearingAngleOutOfRange"] = 9] = "BearingAngleOutOfRange";
|
|
28
29
|
})(ParseError || (exports.ParseError = ParseError = {}));
|
|
29
30
|
var Operator;
|
|
30
31
|
(function (Operator) {
|
|
31
32
|
Operator["addition"] = "+";
|
|
32
33
|
Operator["subtraction"] = "-";
|
|
34
|
+
Operator["multiplication"] = "*";
|
|
35
|
+
Operator["division"] = "/"; // unsupported but we recognize it during parsing
|
|
33
36
|
})(Operator || (Operator = {}));
|
|
34
37
|
function isOperator(char) {
|
|
35
38
|
if (typeof char === "number") {
|
|
@@ -230,6 +233,15 @@ class Parser {
|
|
|
230
233
|
processingNumber = false;
|
|
231
234
|
wipToken = "";
|
|
232
235
|
}
|
|
236
|
+
else if (format.type === FormatEnums_1.FormatType.Bearing && wipToken.length > 0) {
|
|
237
|
+
if (signToken.length > 0) {
|
|
238
|
+
wipToken = signToken + wipToken;
|
|
239
|
+
signToken = "";
|
|
240
|
+
}
|
|
241
|
+
tokens.push(new ParseToken(parseFloat(wipToken))); // Create token for the current number
|
|
242
|
+
processingNumber = false;
|
|
243
|
+
wipToken = "";
|
|
244
|
+
}
|
|
233
245
|
continue;
|
|
234
246
|
}
|
|
235
247
|
else {
|
|
@@ -514,6 +526,26 @@ class Parser {
|
|
|
514
526
|
}
|
|
515
527
|
const defaultUnit = format.units && format.units.length > 0 ? format.units[0][0] : undefined;
|
|
516
528
|
defaultUnitConversion = defaultUnitConversion ? defaultUnitConversion : Parser.getDefaultUnitConversion(tokens, unitsConversions, defaultUnit);
|
|
529
|
+
if (format.type === FormatEnums_1.FormatType.Bearing && format.units !== undefined && format.units.length > 0) {
|
|
530
|
+
const units = format.units;
|
|
531
|
+
const desiredNumberOfTokens = units.length;
|
|
532
|
+
if (tokens.length < desiredNumberOfTokens && tokens[0].isNumber && desiredNumberOfTokens <= 3) {
|
|
533
|
+
// handle the special XX.YYZZ format which is common for bearings. It uses no separators, so we need to split based on numeric indexes. We support up to 3 units
|
|
534
|
+
const value = tokens[0].value;
|
|
535
|
+
const firstToken = Math.floor(value);
|
|
536
|
+
tokens.pop();
|
|
537
|
+
tokens.push(new ParseToken(firstToken)); // Add the first token back to the list.
|
|
538
|
+
if (desiredNumberOfTokens >= 2) {
|
|
539
|
+
const remaining = (value - firstToken) * 100;
|
|
540
|
+
const secondToken = Math.floor(remaining);
|
|
541
|
+
tokens.push(new ParseToken(secondToken));
|
|
542
|
+
if (desiredNumberOfTokens === 3) {
|
|
543
|
+
const thirdToken = (remaining - secondToken) * 100;
|
|
544
|
+
tokens.push(new ParseToken(thirdToken));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
517
549
|
let tokenPair;
|
|
518
550
|
let increment = 1;
|
|
519
551
|
let mag = 0.0;
|
|
@@ -602,7 +634,7 @@ class Parser {
|
|
|
602
634
|
* @param inString A string that contains text represent a quantity.
|
|
603
635
|
* @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
|
|
604
636
|
* @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
|
|
605
|
-
* @deprecated in 4.10. Check [[Parser.parseQuantityString]] for replacements.
|
|
637
|
+
* @deprecated in 4.10 - will not be removed until after 2026-06-13. Check [[Parser.parseQuantityString]] for replacements.
|
|
606
638
|
*/
|
|
607
639
|
static parseToQuantityValue(inString, format, unitsConversions) {
|
|
608
640
|
// TODO: This method is not able to do bearing and azimuth formatting and is overlapping with parseQuantityString.
|
|
@@ -625,6 +657,17 @@ class Parser {
|
|
|
625
657
|
}
|
|
626
658
|
return this.parseAndProcessTokens(inString, format, unitsConversions);
|
|
627
659
|
}
|
|
660
|
+
/** The value of special direction is always in degrees, try to find the unit conversion for that. */
|
|
661
|
+
static processSpecialBearingDirection(mag, spec) {
|
|
662
|
+
const specialDirUnit = spec.unitConversions.find((unitConversion) => unitConversion.name === "Units.ARC_DEG");
|
|
663
|
+
if (!specialDirUnit)
|
|
664
|
+
return { ok: false, error: ParseError.UnknownUnit };
|
|
665
|
+
const preferredUnit = spec.outUnit;
|
|
666
|
+
const conversion = this.tryFindUnitConversion(specialDirUnit.label, spec.unitConversions, preferredUnit);
|
|
667
|
+
if (!conversion)
|
|
668
|
+
return { ok: true, value: mag };
|
|
669
|
+
return { ok: true, value: (0, Quantity_1.applyConversion)(mag, conversion) };
|
|
670
|
+
}
|
|
628
671
|
static parseBearingFormat(inString, spec) {
|
|
629
672
|
const specialDirections = {
|
|
630
673
|
n: 0,
|
|
@@ -670,7 +713,7 @@ class Parser {
|
|
|
670
713
|
const suffix = matchedSuffix?.toLowerCase() || "";
|
|
671
714
|
const specialDirection = specialDirections[`${prefix}${suffix}`];
|
|
672
715
|
if (specialDirection !== undefined)
|
|
673
|
-
return
|
|
716
|
+
return this.processSpecialBearingDirection(specialDirection, spec);
|
|
674
717
|
}
|
|
675
718
|
if (matchedPrefix === null || matchedSuffix === null) {
|
|
676
719
|
return { ok: false, error: ParseError.BearingPrefixOrSuffixMissing };
|
|
@@ -679,10 +722,12 @@ class Parser {
|
|
|
679
722
|
if (this.isParseError(parsedResult)) {
|
|
680
723
|
return parsedResult;
|
|
681
724
|
}
|
|
682
|
-
let magnitude = parsedResult.value;
|
|
683
725
|
const revolution = this.getRevolution(spec);
|
|
684
|
-
magnitude = this.normalizeAngle(magnitude, revolution);
|
|
685
726
|
const quarterRevolution = revolution / 4;
|
|
727
|
+
let magnitude = parsedResult.value;
|
|
728
|
+
if (magnitude < -quarterRevolution || magnitude > quarterRevolution) {
|
|
729
|
+
return { ok: false, error: ParseError.BearingAngleOutOfRange };
|
|
730
|
+
}
|
|
686
731
|
// we have to turn the value into an east base and counter clockwise (NW and SE are already counter clockwise)
|
|
687
732
|
if (matchedPrefix === DirectionLabel.North) {
|
|
688
733
|
if (matchedSuffix === DirectionLabel.West) {
|
|
@@ -697,6 +742,7 @@ class Parser {
|
|
|
697
742
|
magnitude = (2 * quarterRevolution) - magnitude;
|
|
698
743
|
}
|
|
699
744
|
}
|
|
745
|
+
magnitude = this.normalizeAngle(magnitude, revolution);
|
|
700
746
|
return { ok: true, value: magnitude };
|
|
701
747
|
}
|
|
702
748
|
static parseAzimuthFormat(inString, spec) {
|