@itwin/core-quantity 5.2.0-dev.3 → 5.2.0-dev.30

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,QAAQ,CAAY;IACpB,YAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;IAC7D,OAAO,CAAS;IACd,sBAAsB,CAAuB,CAAC,iDAAiD;IAC/F,qBAAqB,CAAuB,CAAC,+CAA+C;IAEtG;;;;OAIG;IACH,YAAY,OAAkB,EAAE,MAAc,EAAE,WAAiC;QAC/E,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,wGAAwG;IACxG,IAAW,eAAe,KAA2B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAW,OAAO,KAAgB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,IAAW,qBAAqB,KAAsC,OAAO,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAC3G,IAAW,oBAAoB,KAAsC,OAAO,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAEzG;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,aAA4B,EAAE,OAAkB,EAAE,qBAAmD;QAC9I,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,aAAa,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC;QACjH,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,sBAAsB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACnG,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,sBAAsB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,qBAAqB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YACjG,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,qBAAqB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC5D,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0HAA0H;IACnH,oBAAoB,CAAC,QAAgB;QAC1C,OAAO,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { Format } from \"./Formatter/Format\";\nimport { AlternateUnitLabelsProvider, UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"./Interfaces\";\nimport { Parser, QuantityParseResult } from \"./Parser\";\n\n/** A ParserSpec holds information needed to parse a string into a quantity synchronously.\n * @beta\n */\nexport class ParserSpec {\n private _outUnit: UnitProps;\n private _conversions: UnitConversionSpec[] = []; // max four entries\n private _format: Format;\n protected _azimuthBaseConversion?: UnitConversionProps; // converts azimuth base unit to persistence unit\n protected _revolutionConversion?: UnitConversionProps; // converts revolution unit to persistence unit\n\n /** Constructor\n * @param outUnit The name of a format specification.\n * @param format Defines the output format for the quantity value.\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format..\n */\n constructor(outUnit: UnitProps, format: Format, conversions: UnitConversionSpec[]) {\n this._outUnit = outUnit;\n this._format = format;\n this._conversions = conversions;\n }\n\n /** Returns an array of UnitConversionSpecs for each unit label that may be used in the input string. */\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\n public get format(): Format { return this._format; }\n public get outUnit(): UnitProps { return this._outUnit; }\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\n\n /** Static async method to create a ParserSpec given the format and unit of the quantity that will be passed to the Parser. The input unit will\n * be used to generate conversion information for each unit specified in the Format. This method is async due to the fact that the units provider must make\n * async calls to lookup unit definitions.\n * @param format The format specification.\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\n * @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.\n */\n public static async create(format: Format, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<ParserSpec> {\n const conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);\n const spec = new ParserSpec(outUnit, format, conversions);\n if (format.azimuthBaseUnit !== undefined) {\n if (outUnit !== undefined) {\n spec._azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, outUnit);\n } else {\n spec._azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n if (format.revolutionUnit !== undefined) {\n if (outUnit !== undefined) {\n spec._revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, outUnit);\n } else {\n spec._revolutionConversion = { factor: 1.0, offset: 0.0 };\n }\n }\n return spec;\n }\n\n /** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */\n public parseToQuantityValue(inString: string): QuantityParseResult {\n return Parser.parseQuantityString(inString, this);\n }\n}\n\n"]}
1
+ {"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH,OAAO,EAAE,MAAM,EAAuB,MAAM,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,UAAU;IACb,QAAQ,CAAY;IACpB,YAAY,GAAyB,EAAE,CAAC,CAAE,mBAAmB;IAC7D,OAAO,CAAS;IACd,sBAAsB,CAAuB,CAAC,iDAAiD;IAC/F,qBAAqB,CAAuB,CAAC,+CAA+C;IAEtG;;;;OAIG;IACH,YAAY,OAAkB,EAAE,MAAc,EAAE,WAAiC;QAC/E,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,wGAAwG;IACxG,IAAW,eAAe,KAA2B,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAChF,IAAW,MAAM,KAAa,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACpD,IAAW,OAAO,KAAgB,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,IAAW,qBAAqB,KAAsC,OAAO,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAC3G,IAAW,oBAAoB,KAAsC,OAAO,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAEzG;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,aAA4B,EAAE,OAAkB,EAAE,qBAAmD;QAC9I,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,gCAAgC,CAAC,aAAa,EAAE,OAAO,EAAE,qBAAqB,CAAC,CAAC;QACjH,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QAC1D,IAAI,MAAM,CAAC,eAAe,KAAK,SAAS,EAAE,CAAC;YACzC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,sBAAsB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;YACnG,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,sBAAsB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,IAAI,CAAC,qBAAqB,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YACjG,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,qBAAqB,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;YAC5D,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0HAA0H;IACnH,oBAAoB,CAAC,QAAgB;QAC1C,OAAO,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { Format } from \"./Formatter/Format\";\r\nimport { AlternateUnitLabelsProvider, UnitConversionProps, UnitConversionSpec, UnitProps, UnitsProvider } from \"./Interfaces\";\r\nimport { Parser, QuantityParseResult } from \"./Parser\";\r\n\r\n/** A ParserSpec holds information needed to parse a string into a quantity synchronously.\r\n * @beta\r\n */\r\nexport class ParserSpec {\r\n private _outUnit: UnitProps;\r\n private _conversions: UnitConversionSpec[] = []; // max four entries\r\n private _format: Format;\r\n protected _azimuthBaseConversion?: UnitConversionProps; // converts azimuth base unit to persistence unit\r\n protected _revolutionConversion?: UnitConversionProps; // converts revolution unit to persistence unit\r\n\r\n /** Constructor\r\n * @param outUnit The name of a format specification.\r\n * @param format Defines the output format for the quantity value.\r\n * @param conversions An array of conversion factors necessary to convert from an input unit to the units specified in the format..\r\n */\r\n constructor(outUnit: UnitProps, format: Format, conversions: UnitConversionSpec[]) {\r\n this._outUnit = outUnit;\r\n this._format = format;\r\n this._conversions = conversions;\r\n }\r\n\r\n /** Returns an array of UnitConversionSpecs for each unit label that may be used in the input string. */\r\n public get unitConversions(): UnitConversionSpec[] { return this._conversions; }\r\n public get format(): Format { return this._format; }\r\n public get outUnit(): UnitProps { return this._outUnit; }\r\n public get azimuthBaseConversion(): UnitConversionProps | undefined { return this._azimuthBaseConversion; }\r\n public get revolutionConversion(): UnitConversionProps | undefined { return this._revolutionConversion; }\r\n\r\n /** Static async method to create a ParserSpec given the format and unit of the quantity that will be passed to the Parser. The input unit will\r\n * be used to generate conversion information for each unit specified in the Format. This method is async due to the fact that the units provider must make\r\n * async calls to lookup unit definitions.\r\n * @param format The format specification.\r\n * @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.\r\n * @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.\r\n */\r\n public static async create(format: Format, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<ParserSpec> {\r\n const conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);\r\n const spec = new ParserSpec(outUnit, format, conversions);\r\n if (format.azimuthBaseUnit !== undefined) {\r\n if (outUnit !== undefined) {\r\n spec._azimuthBaseConversion = await unitsProvider.getConversion(format.azimuthBaseUnit, outUnit);\r\n } else {\r\n spec._azimuthBaseConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n }\r\n if (format.revolutionUnit !== undefined) {\r\n if (outUnit !== undefined) {\r\n spec._revolutionConversion = await unitsProvider.getConversion(format.revolutionUnit, outUnit);\r\n } else {\r\n spec._revolutionConversion = { factor: 1.0, offset: 0.0 };\r\n }\r\n }\r\n return spec;\r\n }\r\n\r\n /** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */\r\n public parseToQuantityValue(inString: string): QuantityParseResult {\r\n return Parser.parseQuantityString(inString, this);\r\n }\r\n}\r\n\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAiB,oBAAoB,EAAkC,MAAM,cAAc,CAAC;AAEnG;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,YAAoB,sBAAsB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC1E,OAAO,OAAO,IAAI,eAAe,CAAC;AACpC,CAAC;AAED;;;GAG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C,OAAO,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,KAA0B;IACvE,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,8CAA8C;IAC9C,IAAI,KAAK,CAAC,SAAS,KAAK,oBAAoB,CAAC,mBAAmB,EAAE,CAAC;QACjE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,yCAAyC;IACzC,cAAc,GAAG,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;IAEhE,+CAA+C;IAC/C,IAAI,KAAK,CAAC,SAAS,KAAK,oBAAoB,CAAC,oBAAoB,EAAE,CAAC;QAClE,cAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","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 { QuantityError, QuantityStatus } from \"./Exception\";\nimport { QuantityProps, UnitConversionInvert, UnitConversionProps, UnitProps } from \"./Interfaces\";\n\n/**\n * Checks if two numbers are approximately equal within given relative tolerance.\n * @param a - The first number to compare.\n * @param b - The second number to compare.\n * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).\n * @returns True if the numbers are approximately equal, false otherwise.\n * @internal\n */\nexport function almostEqual(a: number, b: number, tolerance: number = 2.2204460492503131e-16): boolean {\n const absDiff = Math.abs(a - b);\n const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;\n return absDiff <= scaledTolerance;\n}\n\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\n * returned as the result of parsing a string that represents a quantity.\n * @beta\n */\nexport class Quantity implements QuantityProps {\n protected _magnitude: number = 0.0;\n protected _unit: UnitProps;\n protected _isValid: boolean = false;\n\n public get unit(): UnitProps { return this._unit; }\n public get magnitude(): number { return this._magnitude; }\n public get isValid(): boolean { return this._isValid; }\n\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\n * @param unit Defines the quantity's unit.\n * @param magnitude Defines the magnitude of the quantity.\n */\n public constructor(unit?: UnitProps, magnitude?: number) {\n if (undefined !== unit) {\n this._unit = unit;\n this._isValid = true;\n } else {\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\n }\n\n if (undefined !== magnitude)\n this._magnitude = magnitude;\n }\n\n /** Convert a Quantity to the specified unit given the UnitConversion.\n * @param toUnit The new unit for the quantity.\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\n * returned from the UnitsProvider.\n */\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity | undefined {\n const newMagnitude = applyConversion(this.magnitude, conversion);\n return new Quantity(toUnit, newMagnitude);\n }\n}\n\nfunction invert(input: number): number {\n if (almostZero(input)) // mimic the behavior of native here. We don't want to invert those very small values\n throw new QuantityError(QuantityStatus.InvertingZero, \"Cannot invert zero value\");\n return 1 / input;\n}\n\n/** Determines if a value is almost zero. (less than 1e-16)\n * @param value - The value to be checked.\n * @returns `true` if the value is almost zero, `false` otherwise.\n * @internal\n */\nexport function almostZero(value: number): boolean {\n return almostEqual(value, 0.0);\n}\n\n/**\n * Applies a unit conversion to a given value.\n * @param value - The value to be converted.\n * @param props - The unit conversion properties.\n * @returns The converted value.\n * @internal\n */\nexport function applyConversion(value: number, props: UnitConversionProps): number {\n let convertedValue = value;\n\n // Apply pre-conversion inversion if specified\n if (props.inversion === UnitConversionInvert.InvertPreConversion) {\n convertedValue = invert(convertedValue);\n }\n\n // Apply the conversion factor and offset\n convertedValue = (convertedValue * props.factor) + props.offset;\n\n // Apply post-conversion inversion if specified\n if (props.inversion === UnitConversionInvert.InvertPostConversion) {\n convertedValue = invert(convertedValue);\n }\n\n return convertedValue;\n}\n"]}
1
+ {"version":3,"file":"Quantity.js","sourceRoot":"","sources":["../../src/Quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAiB,oBAAoB,EAAkC,MAAM,cAAc,CAAC;AAEnG;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,CAAS,EAAE,CAAS,EAAE,YAAoB,sBAAsB;IAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAChC,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAC1E,OAAO,OAAO,IAAI,eAAe,CAAC;AACpC,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,QAAQ;IACT,UAAU,GAAW,GAAG,CAAC;IACzB,KAAK,CAAY;IACjB,QAAQ,GAAY,KAAK,CAAC;IAEpC,IAAW,IAAI,KAAgB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,IAAW,SAAS,KAAa,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;IAC1D,IAAW,OAAO,KAAc,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvD;;;OAGG;IACH,YAAmB,IAAgB,EAAE,SAAkB;QACrD,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,I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c,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { QuantityError, QuantityStatus } from \"./Exception\";\r\nimport { QuantityProps, UnitConversionInvert, UnitConversionProps, UnitProps } from \"./Interfaces\";\r\n\r\n/**\r\n * Checks if two numbers are approximately equal within given relative tolerance.\r\n * @param a - The first number to compare.\r\n * @param b - The second number to compare.\r\n * @param tolerance - Tolerance, scales based on the input number values (multiplied by 1, abs(a) or abs(b), whichever is biggest).\r\n * @returns True if the numbers are approximately equal, false otherwise.\r\n * @internal\r\n */\r\nexport function almostEqual(a: number, b: number, tolerance: number = 2.2204460492503131e-16): boolean {\r\n const absDiff = Math.abs(a - b);\r\n const scaledTolerance = Math.max(1, Math.abs(a), Math.abs(b)) * tolerance;\r\n return absDiff <= scaledTolerance;\r\n}\r\n\r\n/** The Quantity class is convenient container to specify both the magnitude and unit of a quantity. This class is commonly\r\n * returned as the result of parsing a string that represents a quantity.\r\n * @beta\r\n */\r\nexport class Quantity implements QuantityProps {\r\n protected _magnitude: number = 0.0;\r\n protected _unit: UnitProps;\r\n protected _isValid: boolean = false;\r\n\r\n public get unit(): UnitProps { return this._unit; }\r\n public get magnitude(): number { return this._magnitude; }\r\n public get isValid(): boolean { return this._isValid; }\r\n\r\n /** Constructor. The Quantity will only be set as valid if a unit is specified.\r\n * @param unit Defines the quantity's unit.\r\n * @param magnitude Defines the magnitude of the quantity.\r\n */\r\n public constructor(unit?: UnitProps, magnitude?: number) {\r\n if (undefined !== unit) {\r\n this._unit = unit;\r\n this._isValid = true;\r\n } else {\r\n this._unit = { name: \"unknown\", label: \"unknown\", phenomenon: \"unknown\", isValid: false, system: \"unknown\" };\r\n }\r\n\r\n if (undefined !== magnitude)\r\n this._magnitude = magnitude;\r\n }\r\n\r\n /** Convert a Quantity to the specified unit given the UnitConversion.\r\n * @param toUnit The new unit for the quantity.\r\n * @param conversion Defines the information needed to convert the Quantity's magnitude from the current unit to another unit. This conversion info is usually\r\n * returned from the UnitsProvider.\r\n */\r\n public convertTo(toUnit: UnitProps, conversion: UnitConversionProps): Quantity | undefined {\r\n const newMagnitude = applyConversion(this.magnitude, conversion);\r\n return new Quantity(toUnit, newMagnitude);\r\n }\r\n}\r\n\r\nfunction invert(input: number): number {\r\n if (almostZero(input)) // mimic the behavior of native here. We don't want to invert those very small values\r\n throw new QuantityError(QuantityStatus.InvertingZero, \"Cannot invert zero value\");\r\n return 1 / input;\r\n}\r\n\r\n/** Determines if a value is almost zero. (less than 1e-16)\r\n * @param value - The value to be checked.\r\n * @returns `true` if the value is almost zero, `false` otherwise.\r\n * @internal\r\n */\r\nexport function almostZero(value: number): boolean {\r\n return almostEqual(value, 0.0);\r\n}\r\n\r\n/**\r\n * Applies a unit conversion to a given value.\r\n * @param value - The value to be converted.\r\n * @param props - The unit conversion properties.\r\n * @returns The converted value.\r\n * @internal\r\n */\r\nexport function applyConversion(value: number, props: UnitConversionProps): number {\r\n let convertedValue = value;\r\n\r\n // Apply pre-conversion inversion if specified\r\n if (props.inversion === UnitConversionInvert.InvertPreConversion) {\r\n convertedValue = invert(convertedValue);\r\n }\r\n\r\n // Apply the conversion factor and offset\r\n convertedValue = (convertedValue * props.factor) + props.offset;\r\n\r\n // Apply post-conversion inversion if specified\r\n if (props.inversion === UnitConversionInvert.InvertPostConversion) {\r\n convertedValue = invert(convertedValue);\r\n }\r\n\r\n return convertedValue;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../src/Unit.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;GAEG;AACH,MAAM,OAAO,SAAS;IACb,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAW,SAAS,CAAC;IAElC,YAAY,IAAY,EAAE,KAAa,EAAE,UAAkB,EAAE,MAAe;QAC1E,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,IAAI,MAAM;gBACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAAO;IACX,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAG,SAAS,CAAC;CAC3B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\nimport { UnitProps } from \"./Interfaces\";\n\n/** This class provides basic implementation of UnitProps interface.\n * @beta\n */\nexport class BasicUnit implements UnitProps {\n public name = \"\";\n public label = \"\";\n public phenomenon = \"\";\n public isValid = false;\n public system: string = \"unknown\";\n\n constructor(name: string, label: string, phenomenon: string, system?: string) {\n if (name && name.length > 0 && label && label.length > 0 && phenomenon && phenomenon.length > 0) {\n this.name = name;\n this.label = label;\n this.phenomenon = phenomenon;\n this.isValid = true;\n if (system)\n this.system = system;\n }\n }\n}\n\n/** This class is a convenience class that can be returned when a valid Unit cannot be determined.\n * @beta\n */\nexport class BadUnit implements UnitProps {\n public name = \"\";\n public label = \"\";\n public phenomenon = \"\";\n public isValid = false;\n public system = \"unknown\";\n}\n"]}
1
+ {"version":3,"file":"Unit.js","sourceRoot":"","sources":["../../src/Unit.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAIH;;GAEG;AACH,MAAM,OAAO,SAAS;IACb,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAW,SAAS,CAAC;IAElC,YAAY,IAAY,EAAE,KAAa,EAAE,UAAkB,EAAE,MAAe;QAC1E,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;YACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;YACnB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,IAAI,MAAM;gBACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,OAAO;IACX,IAAI,GAAG,EAAE,CAAC;IACV,KAAK,GAAG,EAAE,CAAC;IACX,UAAU,GAAG,EAAE,CAAC;IAChB,OAAO,GAAG,KAAK,CAAC;IAChB,MAAM,GAAG,SAAS,CAAC;CAC3B","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\nimport { UnitProps } from \"./Interfaces\";\r\n\r\n/** This class provides basic implementation of UnitProps interface.\r\n * @beta\r\n */\r\nexport class BasicUnit implements UnitProps {\r\n public name = \"\";\r\n public label = \"\";\r\n public phenomenon = \"\";\r\n public isValid = false;\r\n public system: string = \"unknown\";\r\n\r\n constructor(name: string, label: string, phenomenon: string, system?: string) {\r\n if (name && name.length > 0 && label && label.length > 0 && phenomenon && phenomenon.length > 0) {\r\n this.name = name;\r\n this.label = label;\r\n this.phenomenon = phenomenon;\r\n this.isValid = true;\r\n if (system)\r\n this.system = system;\r\n }\r\n }\r\n}\r\n\r\n/** This class is a convenience class that can be returned when a valid Unit cannot be determined.\r\n * @beta\r\n */\r\nexport class BadUnit implements UnitProps {\r\n public name = \"\";\r\n public label = \"\";\r\n public phenomenon = \"\";\r\n public isValid = false;\r\n public system = \"unknown\";\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"core-quantity.js","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AAEvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC;;GAEG;AAEH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nexport * from \"./Constants\";\nexport * from \"./Exception\";\nexport * from \"./Interfaces\";\nexport * from \"./Parser\";\nexport * from \"./ParserSpec\";\nexport * from \"./Quantity\";\nexport * from \"./Unit\";\n\nexport * from \"./Formatter/Format\";\nexport * from \"./Formatter/FormatterSpec\";\nexport * from \"./Formatter/FormatEnums\";\nexport * from \"./Formatter/Formatter\";\nexport * from \"./Formatter/Interfaces\";\n\n/** @docs-package-description\n * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.\n */\n\n/**\n * @docs-group-description Quantity\n * Classes, Interfaces, and definitions used to format and parse quantity values.\n */\n"]}
1
+ {"version":3,"file":"core-quantity.js","sourceRoot":"","sources":["../../src/core-quantity.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AAEvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AAEvC;;GAEG;AAEH;;;GAGG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nexport * from \"./Constants\";\r\nexport * from \"./Exception\";\r\nexport * from \"./Interfaces\";\r\nexport * from \"./Parser\";\r\nexport * from \"./ParserSpec\";\r\nexport * from \"./Quantity\";\r\nexport * from \"./Unit\";\r\n\r\nexport * from \"./Formatter/Format\";\r\nexport * from \"./Formatter/FormatterSpec\";\r\nexport * from \"./Formatter/FormatEnums\";\r\nexport * from \"./Formatter/Formatter\";\r\nexport * from \"./Formatter/Interfaces\";\r\n\r\n/** @docs-package-description\r\n * The core-quantity package always runs in a web browser. It contains classes, interfaces, and definitions for formatting and parsing quantity values.\r\n */\r\n\r\n/**\r\n * @docs-group-description Quantity\r\n * Classes, Interfaces, and definitions used to format and parse quantity values.\r\n */\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/core-quantity",
3
- "version": "5.2.0-dev.3",
3
+ "version": "5.2.0-dev.30",
4
4
  "description": "Quantity parsing, formatting and conversions for iModel.js",
5
5
  "main": "lib/cjs/core-quantity.js",
6
6
  "module": "lib/esm/core-quantity.js",
@@ -28,11 +28,11 @@
28
28
  "rimraf": "^6.0.1",
29
29
  "typescript": "~5.6.2",
30
30
  "vitest": "^3.0.6",
31
- "@itwin/build-tools": "5.2.0-dev.3",
32
- "@itwin/core-bentley": "5.2.0-dev.3"
31
+ "@itwin/build-tools": "5.2.0-dev.30",
32
+ "@itwin/core-bentley": "5.2.0-dev.30"
33
33
  },
34
34
  "peerDependencies": {
35
- "@itwin/core-bentley": "5.2.0-dev.3"
35
+ "@itwin/core-bentley": "5.2.0-dev.30"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "npm run -s build:cjs && npm run -s build:esm",