@itwin/core-quantity 5.0.0-dev.65 → 5.0.0-dev.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -1
- package/README.md +9 -5
- package/lib/cjs/ParserSpec.d.ts +1 -1
- package/lib/cjs/ParserSpec.js +1 -1
- package/lib/cjs/ParserSpec.js.map +1 -1
- package/lib/esm/ParserSpec.d.ts +1 -1
- package/lib/esm/ParserSpec.js +1 -1
- package/lib/esm/ParserSpec.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Change Log - @itwin/core-quantity
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 18 Feb 2025 17:30:07 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 4.10.7
|
|
6
|
+
Tue, 18 Feb 2025 17:27:03 GMT
|
|
7
|
+
|
|
8
|
+
_Version update only_
|
|
4
9
|
|
|
5
10
|
## 4.10.6
|
|
6
11
|
Fri, 24 Jan 2025 08:02:40 GMT
|
package/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# @itwin/core-quantity
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The __@itwin/core-quantity__ package contains classes for quantity formatting and parsing. For detailed API documentation, see our [iTwin.js reference documentation](https://www.itwinjs.org/reference/core-quantity/quantity/).
|
|
4
|
+
|
|
5
|
+
Also check the [iTwin.js learning documentation](https://www.itwinjs.org/learning/quantity) explaining quantity formatting and its basic concepts.
|
|
4
6
|
|
|
5
|
-
##
|
|
7
|
+
## Contributing
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
When adding new APIs or updating documentation for this package, review if [QuantityFormatting.md](https://github.com/iTwin/itwinjs-core/blob/master/docs/learning/frontend/QuantityFormatting.md) or the [core-quantity learning page](https://github.com/iTwin/itwinjs-core/blob/master/docs/learning/quantity/index.md) needs to be updated as well. When adding or editing code examples, it's encouraged to keep the examples consistent between this file and the linked file above.
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
See the [Contributing.md](https://github.com/iTwin/itwinjs-core/blob/master/CONTRIBUTING.md) for more details.
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
## Licensing
|
|
14
|
+
|
|
15
|
+
Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.
|
package/lib/cjs/ParserSpec.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare class ParserSpec {
|
|
|
30
30
|
* async calls to lookup unit definitions.
|
|
31
31
|
* @param format The format specification.
|
|
32
32
|
* @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.
|
|
33
|
-
* @param outUnit The unit
|
|
33
|
+
* @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.
|
|
34
34
|
*/
|
|
35
35
|
static create(format: Format, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<ParserSpec>;
|
|
36
36
|
/** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */
|
package/lib/cjs/ParserSpec.js
CHANGED
|
@@ -39,7 +39,7 @@ class ParserSpec {
|
|
|
39
39
|
* async calls to lookup unit definitions.
|
|
40
40
|
* @param format The format specification.
|
|
41
41
|
* @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.
|
|
42
|
-
* @param outUnit The unit
|
|
42
|
+
* @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.
|
|
43
43
|
*/
|
|
44
44
|
static async create(format, unitsProvider, outUnit, altUnitLabelsProvider) {
|
|
45
45
|
const conversions = await Parser_1.Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":";A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,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,eAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;CACF;AAxDD,gCAwDC","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
|
|
1
|
+
{"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAIH,qCAAuD;AAEvD;;GAEG;AACH,MAAa,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,I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;YAC5D,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0HAA0H;IACnH,oBAAoB,CAAC,QAAgB;QAC1C,OAAO,eAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC;CACF;AAxDD,gCAwDC","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"]}
|
package/lib/esm/ParserSpec.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare class ParserSpec {
|
|
|
30
30
|
* async calls to lookup unit definitions.
|
|
31
31
|
* @param format The format specification.
|
|
32
32
|
* @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.
|
|
33
|
-
* @param outUnit The unit
|
|
33
|
+
* @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.
|
|
34
34
|
*/
|
|
35
35
|
static create(format: Format, unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<ParserSpec>;
|
|
36
36
|
/** Do the parsing. Done this way to allow Custom Parser Specs to parse custom formatted strings into their quantities. */
|
package/lib/esm/ParserSpec.js
CHANGED
|
@@ -36,7 +36,7 @@ export class ParserSpec {
|
|
|
36
36
|
* async calls to lookup unit definitions.
|
|
37
37
|
* @param format The format specification.
|
|
38
38
|
* @param unitsProvider The units provider is used to look up unit definitions and provide conversion information for converting between units.
|
|
39
|
-
* @param outUnit The unit
|
|
39
|
+
* @param outUnit The unit a value will be formatted to. This unit is often referred to as persistence unit.
|
|
40
40
|
*/
|
|
41
41
|
static async create(format, unitsProvider, outUnit, altUnitLabelsProvider) {
|
|
42
42
|
const conversions = await Parser.createUnitConversionSpecsForUnit(unitsProvider, outUnit, altUnitLabelsProvider);
|
|
@@ -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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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 { 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
|
|
1
|
+
{"version":3,"file":"ParserSpec.js","sourceRoot":"","sources":["../../src/ParserSpec.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GA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,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/core-quantity",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.67",
|
|
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": "^3.0.2",
|
|
29
29
|
"typescript": "~5.6.2",
|
|
30
30
|
"vitest": "^3.0.5",
|
|
31
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
32
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
31
|
+
"@itwin/build-tools": "5.0.0-dev.67",
|
|
32
|
+
"@itwin/core-bentley": "5.0.0-dev.67"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
35
|
+
"@itwin/core-bentley": "5.0.0-dev.67"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "npm run -s build:cjs && npm run -s build:esm",
|