@itwin/core-quantity 4.0.0-dev.48 → 4.0.0-dev.51

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.
Files changed (79) hide show
  1. package/lib/cjs/Constants.d.ts +27 -27
  2. package/lib/cjs/Constants.js +52 -52
  3. package/lib/cjs/Constants.js.map +1 -1
  4. package/lib/cjs/Exception.d.ts +26 -26
  5. package/lib/cjs/Exception.js +38 -38
  6. package/lib/cjs/Exception.js.map +1 -1
  7. package/lib/cjs/Formatter/Format.d.ts +91 -91
  8. package/lib/cjs/Formatter/Format.js +328 -328
  9. package/lib/cjs/Formatter/Format.js.map +1 -1
  10. package/lib/cjs/Formatter/FormatEnums.d.ts +133 -133
  11. package/lib/cjs/Formatter/FormatEnums.js +318 -318
  12. package/lib/cjs/Formatter/FormatEnums.js.map +1 -1
  13. package/lib/cjs/Formatter/Formatter.d.ts +44 -44
  14. package/lib/cjs/Formatter/Formatter.js +371 -371
  15. package/lib/cjs/Formatter/Formatter.js.map +1 -1
  16. package/lib/cjs/Formatter/FormatterSpec.d.ts +39 -39
  17. package/lib/cjs/Formatter/FormatterSpec.js +101 -101
  18. package/lib/cjs/Formatter/FormatterSpec.js.map +1 -1
  19. package/lib/cjs/Formatter/Interfaces.d.ts +62 -62
  20. package/lib/cjs/Formatter/Interfaces.js +17 -17
  21. package/lib/cjs/Formatter/Interfaces.js.map +1 -1
  22. package/lib/cjs/Interfaces.d.ts +86 -86
  23. package/lib/cjs/Interfaces.js +9 -9
  24. package/lib/cjs/Interfaces.js.map +1 -1
  25. package/lib/cjs/Parser.d.ts +93 -93
  26. package/lib/cjs/Parser.js +592 -592
  27. package/lib/cjs/Parser.js.map +1 -1
  28. package/lib/cjs/ParserSpec.d.ts +34 -34
  29. package/lib/cjs/ParserSpec.js +47 -47
  30. package/lib/cjs/ParserSpec.js.map +1 -1
  31. package/lib/cjs/Quantity.d.ts +27 -27
  32. package/lib/cjs/Quantity.js +46 -46
  33. package/lib/cjs/Quantity.js.map +1 -1
  34. package/lib/cjs/Unit.d.ts +25 -25
  35. package/lib/cjs/Unit.js +44 -44
  36. package/lib/cjs/Unit.js.map +1 -1
  37. package/lib/cjs/core-quantity.d.ts +19 -19
  38. package/lib/cjs/core-quantity.js +35 -35
  39. package/lib/cjs/core-quantity.js.map +1 -1
  40. package/lib/esm/Constants.d.ts +27 -27
  41. package/lib/esm/Constants.js +48 -48
  42. package/lib/esm/Constants.js.map +1 -1
  43. package/lib/esm/Exception.d.ts +26 -26
  44. package/lib/esm/Exception.js +34 -34
  45. package/lib/esm/Exception.js.map +1 -1
  46. package/lib/esm/Formatter/Format.d.ts +91 -91
  47. package/lib/esm/Formatter/Format.js +323 -323
  48. package/lib/esm/Formatter/Format.js.map +1 -1
  49. package/lib/esm/Formatter/FormatEnums.d.ts +133 -133
  50. package/lib/esm/Formatter/FormatEnums.js +302 -302
  51. package/lib/esm/Formatter/FormatEnums.js.map +1 -1
  52. package/lib/esm/Formatter/Formatter.d.ts +44 -44
  53. package/lib/esm/Formatter/Formatter.js +367 -367
  54. package/lib/esm/Formatter/Formatter.js.map +1 -1
  55. package/lib/esm/Formatter/FormatterSpec.d.ts +39 -39
  56. package/lib/esm/Formatter/FormatterSpec.js +97 -97
  57. package/lib/esm/Formatter/FormatterSpec.js.map +1 -1
  58. package/lib/esm/Formatter/Interfaces.d.ts +62 -62
  59. package/lib/esm/Formatter/Interfaces.js +13 -13
  60. package/lib/esm/Formatter/Interfaces.js.map +1 -1
  61. package/lib/esm/Interfaces.d.ts +86 -86
  62. package/lib/esm/Interfaces.js +8 -8
  63. package/lib/esm/Interfaces.js.map +1 -1
  64. package/lib/esm/Parser.d.ts +93 -93
  65. package/lib/esm/Parser.js +588 -588
  66. package/lib/esm/Parser.js.map +1 -1
  67. package/lib/esm/ParserSpec.d.ts +34 -34
  68. package/lib/esm/ParserSpec.js +43 -43
  69. package/lib/esm/ParserSpec.js.map +1 -1
  70. package/lib/esm/Quantity.d.ts +27 -27
  71. package/lib/esm/Quantity.js +42 -42
  72. package/lib/esm/Quantity.js.map +1 -1
  73. package/lib/esm/Unit.d.ts +25 -25
  74. package/lib/esm/Unit.js +39 -39
  75. package/lib/esm/Unit.js.map +1 -1
  76. package/lib/esm/core-quantity.d.ts +19 -19
  77. package/lib/esm/core-quantity.js +23 -23
  78. package/lib/esm/core-quantity.js.map +1 -1
  79. package/package.json +4 -4
@@ -1,14 +1,14 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module Quantity
7
- */
8
- /** CustomFormatProps type guard.
9
- * @beta
10
- */
11
- export const isCustomFormatProps = (item) => {
12
- return item.custom !== undefined;
13
- };
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Quantity
7
+ */
8
+ /** CustomFormatProps type guard.
9
+ * @beta
10
+ */
11
+ export const isCustomFormatProps = (item) => {
12
+ return item.custom !== undefined;
13
+ };
14
14
  //# sourceMappingURL=Interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAsCH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,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 { 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 readonly scientificType?: string; // conditionally required\n readonly stationOffsetSize?: number; // conditionally required\n readonly stationSeparator?: string;\n readonly composite?: {\n readonly spacer?: string;\n readonly includeZero?: boolean; // not currently used in Native formatter\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"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../../src/Formatter/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAsCH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,IAAiB,EAA6B,EAAE;IAClF,OAAQ,IAA0B,CAAC,MAAM,KAAK,SAAS,CAAC;AAC1D,CAAC,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 { UnitProps } from \"../Interfaces\";\r\nimport { DecimalPrecision, FormatTraits, FormatType, FractionalPrecision } from \"./FormatEnums\";\r\n\r\n/** This interface defines the persistence format for describing the formatting of quantity values.\r\n * @beta\r\n */\r\nexport interface FormatProps {\r\n readonly type: string;\r\n readonly precision?: number;\r\n readonly roundFactor?: number;\r\n readonly minWidth?: number;\r\n readonly showSignOption?: string;\r\n readonly formatTraits?: string | string[];\r\n readonly decimalSeparator?: string;\r\n readonly thousandSeparator?: string;\r\n readonly uomSeparator?: string;\r\n readonly scientificType?: string; // conditionally required\r\n readonly stationOffsetSize?: number; // conditionally required\r\n readonly stationSeparator?: string;\r\n readonly composite?: {\r\n readonly spacer?: string;\r\n readonly includeZero?: boolean; // not currently used in Native formatter\r\n readonly units: Array<{\r\n readonly name: string;\r\n readonly label?: string;\r\n }>;\r\n };\r\n}\r\n\r\n/** This interface is used when supporting Custom Formatters that need more than the standard set of properties.\r\n * @beta\r\n */\r\nexport interface CustomFormatProps extends FormatProps {\r\n readonly custom: any;\r\n}\r\n\r\n/** CustomFormatProps type guard.\r\n * @beta\r\n */\r\nexport const isCustomFormatProps = (item: FormatProps): item is CustomFormatProps => {\r\n return (item as CustomFormatProps).custom !== undefined;\r\n};\r\n\r\n/** CloneFormat defines unit and label specification if primary unit is to be set during clone.\r\n * @beta\r\n */\r\nexport interface CloneUnit {\r\n unit?: UnitProps;\r\n label?: string;\r\n}\r\n\r\n/** CloneOptions that define modifications that can be made during the cloning of a Format.\r\n * @beta\r\n */\r\nexport interface CloneOptions {\r\n /** allows composite formats to be converted to only show primary unit */\r\n showOnlyPrimaryUnit?: boolean;\r\n /** allow format traits to be set */\r\n traits?: FormatTraits;\r\n /** allows new FormatType to be specified */\r\n type?: FormatType;\r\n /** allows precision to be set, this will throw if value is not valid for FormatType */\r\n precision?: DecimalPrecision | FractionalPrecision;\r\n /** allows primary unit and label to be specified */\r\n primaryUnit?: CloneUnit;\r\n}\r\n"]}
@@ -1,87 +1,87 @@
1
- /** @packageDocumentation
2
- * @module Quantity
3
- */
4
- /** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.
5
- * @beta
6
- */
7
- export interface AlternateUnitLabelsProvider {
8
- getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;
9
- }
10
- /** This interface provides basic information about a Unit that is return from a UnitProvider. This info
11
- * uniquely identifies a unit by its name.
12
- * @beta
13
- */
14
- export interface UnitProps {
15
- /** Unique name for unit. */
16
- readonly name: string;
17
- /** Default label for unit. */
18
- readonly label: string;
19
- /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */
20
- readonly phenomenon: string;
21
- /** This is set to true if the Unit is known by the UnitsProvider. */
22
- readonly isValid: boolean;
23
- /** Unique system name. Example "Units.USCUSTOM"," Units.METRIC", "Units.USSURVEY", "Units.IMPERIAL" */
24
- readonly system: string;
25
- }
26
- /** This interface defines the required properties of a Quantity.
27
- * @beta
28
- */
29
- export interface QuantityProps {
30
- readonly magnitude: number;
31
- readonly unit: UnitProps;
32
- readonly isValid: boolean;
33
- }
34
- /** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.
35
- * @beta
36
- */
37
- export interface UnitConversionSpec {
38
- /** Unit name that was used to locate the unit by the Unit Provider */
39
- name: string;
40
- /** The default label that is used to display unit */
41
- label: string;
42
- /** Unit system name, used to when finding preferred parse unit */
43
- system: string;
44
- /** the information necessary to convert the unit to a specific display unit */
45
- conversion: UnitConversion;
46
- /** Labels that may be used to represent the unit in a string that is to be parsed. */
47
- parseLabels?: string[];
48
- }
49
- /** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet
50
- * or from Celsius to Fahrenheit.
51
- * @beta
52
- */
53
- export interface UnitConversion {
54
- factor: number;
55
- offset: number;
56
- }
57
- /** Interface that defines potential parse units that may be found in user's string input of a quantity value.
58
- * @beta
59
- */
60
- export interface PotentialParseUnit {
61
- unitName: string;
62
- altLabels?: string[];
63
- }
64
- /**
65
- * This interface defines extra properties to be associated with Units from Units Schema by name
66
- * @alpha
67
- */
68
- export interface UnitExtraData {
69
- readonly name: string;
70
- readonly altDisplayLabels: string[];
71
- }
72
- /** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.
73
- * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.
74
- * @beta
75
- */
76
- export interface UnitsProvider {
77
- findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
78
- getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;
79
- findUnitByName(unitName: string): Promise<UnitProps>;
80
- getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;
81
- }
82
- /**
83
- * Used to uniquely identify a unit system.
84
- * @beta
85
- */
86
- export declare type UnitSystemKey = "metric" | "imperial" | "usCustomary" | "usSurvey";
1
+ /** @packageDocumentation
2
+ * @module Quantity
3
+ */
4
+ /** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.
5
+ * @beta
6
+ */
7
+ export interface AlternateUnitLabelsProvider {
8
+ getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;
9
+ }
10
+ /** This interface provides basic information about a Unit that is return from a UnitProvider. This info
11
+ * uniquely identifies a unit by its name.
12
+ * @beta
13
+ */
14
+ export interface UnitProps {
15
+ /** Unique name for unit. */
16
+ readonly name: string;
17
+ /** Default label for unit. */
18
+ readonly label: string;
19
+ /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */
20
+ readonly phenomenon: string;
21
+ /** This is set to true if the Unit is known by the UnitsProvider. */
22
+ readonly isValid: boolean;
23
+ /** Unique system name. Example "Units.USCUSTOM"," Units.METRIC", "Units.USSURVEY", "Units.IMPERIAL" */
24
+ readonly system: string;
25
+ }
26
+ /** This interface defines the required properties of a Quantity.
27
+ * @beta
28
+ */
29
+ export interface QuantityProps {
30
+ readonly magnitude: number;
31
+ readonly unit: UnitProps;
32
+ readonly isValid: boolean;
33
+ }
34
+ /** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.
35
+ * @beta
36
+ */
37
+ export interface UnitConversionSpec {
38
+ /** Unit name that was used to locate the unit by the Unit Provider */
39
+ name: string;
40
+ /** The default label that is used to display unit */
41
+ label: string;
42
+ /** Unit system name, used to when finding preferred parse unit */
43
+ system: string;
44
+ /** the information necessary to convert the unit to a specific display unit */
45
+ conversion: UnitConversion;
46
+ /** Labels that may be used to represent the unit in a string that is to be parsed. */
47
+ parseLabels?: string[];
48
+ }
49
+ /** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet
50
+ * or from Celsius to Fahrenheit.
51
+ * @beta
52
+ */
53
+ export interface UnitConversion {
54
+ factor: number;
55
+ offset: number;
56
+ }
57
+ /** Interface that defines potential parse units that may be found in user's string input of a quantity value.
58
+ * @beta
59
+ */
60
+ export interface PotentialParseUnit {
61
+ unitName: string;
62
+ altLabels?: string[];
63
+ }
64
+ /**
65
+ * This interface defines extra properties to be associated with Units from Units Schema by name
66
+ * @alpha
67
+ */
68
+ export interface UnitExtraData {
69
+ readonly name: string;
70
+ readonly altDisplayLabels: string[];
71
+ }
72
+ /** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.
73
+ * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.
74
+ * @beta
75
+ */
76
+ export interface UnitsProvider {
77
+ findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;
78
+ getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;
79
+ findUnitByName(unitName: string): Promise<UnitProps>;
80
+ getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;
81
+ }
82
+ /**
83
+ * Used to uniquely identify a unit system.
84
+ * @beta
85
+ */
86
+ export declare type UnitSystemKey = "metric" | "imperial" | "usCustomary" | "usSurvey";
87
87
  //# sourceMappingURL=Interfaces.d.ts.map
@@ -1,9 +1,9 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- /** @packageDocumentation
6
- * @module Quantity
7
- */
8
- export {};
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Quantity
7
+ */
8
+ export {};
9
9
  //# sourceMappingURL=Interfaces.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Quantity\n */\n\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\n * @beta\n */\nexport interface AlternateUnitLabelsProvider {\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\n}\n\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\n * uniquely identifies a unit by its name.\n * @beta\n */\nexport interface UnitProps {\n /** Unique name for unit. */\n readonly name: string;\n /** Default label for unit. */\n readonly label: string;\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\n readonly phenomenon: string;\n /** This is set to true if the Unit is known by the UnitsProvider. */\n readonly isValid: boolean;\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\n readonly system: string;\n}\n\n/** This interface defines the required properties of a Quantity.\n * @beta\n */\nexport interface QuantityProps {\n readonly magnitude: number;\n readonly unit: UnitProps;\n readonly isValid: boolean;\n}\n\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\n * @beta\n */\nexport interface UnitConversionSpec {\n /** Unit name that was used to locate the unit by the Unit Provider */\n name: string;\n /** The default label that is used to display unit */\n label: string;\n /** Unit system name, used to when finding preferred parse unit */\n system: string;\n /** the information necessary to convert the unit to a specific display unit */\n conversion: UnitConversion;\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\n parseLabels?: string[];\n}\n\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\n * or from Celsius to Fahrenheit.\n * @beta\n */\nexport interface UnitConversion {\n factor: number;\n offset: number;\n}\n\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\n * @beta\n */\nexport interface PotentialParseUnit {\n unitName: string;\n altLabels?: string[];\n}\n\n/**\n * This interface defines extra properties to be associated with Units from Units Schema by name\n * @alpha\n */\nexport interface UnitExtraData {\n readonly name: string;\n readonly altDisplayLabels: string[];\n}\n\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\n * @beta\n */\nexport interface UnitsProvider {\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\n findUnitByName(unitName: string): Promise<UnitProps>;\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;\n}\n\n/**\n * Used to uniquely identify a unit system.\n * @beta\n */\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\n"]}
1
+ {"version":3,"file":"Interfaces.js","sourceRoot":"","sources":["../../src/Interfaces.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Quantity\r\n */\r\n\r\n/** This interface allows a provider to be specified that will define an array of alternate labels for a specific unit.\r\n * @beta\r\n */\r\nexport interface AlternateUnitLabelsProvider {\r\n getAlternateUnitLabels: (unit: UnitProps) => string[] | undefined;\r\n}\r\n\r\n/** This interface provides basic information about a Unit that is return from a UnitProvider. This info\r\n * uniquely identifies a unit by its name.\r\n * @beta\r\n */\r\nexport interface UnitProps {\r\n /** Unique name for unit. */\r\n readonly name: string;\r\n /** Default label for unit. */\r\n readonly label: string;\r\n /** Unique name of unit phenomenon. Example phenomenon names include 'Units.LENGTH', 'Units.AREA', and 'Units.VOLUME' */\r\n readonly phenomenon: string;\r\n /** This is set to true if the Unit is known by the UnitsProvider. */\r\n readonly isValid: boolean;\r\n /** Unique system name. Example \"Units.USCUSTOM\",\" Units.METRIC\", \"Units.USSURVEY\", \"Units.IMPERIAL\" */\r\n readonly system: string;\r\n}\r\n\r\n/** This interface defines the required properties of a Quantity.\r\n * @beta\r\n */\r\nexport interface QuantityProps {\r\n readonly magnitude: number;\r\n readonly unit: UnitProps;\r\n readonly isValid: boolean;\r\n}\r\n\r\n/** Interface that defines how to convert between a specific unit an another in synchronous formatting or parsing processing.\r\n * @beta\r\n */\r\nexport interface UnitConversionSpec {\r\n /** Unit name that was used to locate the unit by the Unit Provider */\r\n name: string;\r\n /** The default label that is used to display unit */\r\n label: string;\r\n /** Unit system name, used to when finding preferred parse unit */\r\n system: string;\r\n /** the information necessary to convert the unit to a specific display unit */\r\n conversion: UnitConversion;\r\n /** Labels that may be used to represent the unit in a string that is to be parsed. */\r\n parseLabels?: string[];\r\n}\r\n\r\n/** This interface defines the properties required to convert a quantity value from one unit to another such as from meters to feet\r\n * or from Celsius to Fahrenheit.\r\n * @beta\r\n */\r\nexport interface UnitConversion {\r\n factor: number;\r\n offset: number;\r\n}\r\n\r\n/** Interface that defines potential parse units that may be found in user's string input of a quantity value.\r\n * @beta\r\n */\r\nexport interface PotentialParseUnit {\r\n unitName: string;\r\n altLabels?: string[];\r\n}\r\n\r\n/**\r\n * This interface defines extra properties to be associated with Units from Units Schema by name\r\n * @alpha\r\n */\r\nexport interface UnitExtraData {\r\n readonly name: string;\r\n readonly altDisplayLabels: string[];\r\n}\r\n\r\n/** This interface is implemented by the class that is responsible for locating units by name or label and providing conversion values between units.\r\n * The methods to be implemented are async allowing the UnitsProvider to query the backend when necessary to look up unit definition and conversion rules.\r\n * @beta\r\n */\r\nexport interface UnitsProvider {\r\n findUnit(unitLabel: string, schemaName?: string, phenomenon?: string, unitSystem?: string): Promise<UnitProps>;\r\n getUnitsByFamily(phenomenon: string): Promise<UnitProps[]>;\r\n findUnitByName(unitName: string): Promise<UnitProps>;\r\n getConversion(fromUnit: UnitProps, toUnit: UnitProps): Promise<UnitConversion>;\r\n}\r\n\r\n/**\r\n * Used to uniquely identify a unit system.\r\n * @beta\r\n */\r\nexport type UnitSystemKey = \"metric\" | \"imperial\" | \"usCustomary\" | \"usSurvey\";\r\n"]}
@@ -1,94 +1,94 @@
1
- /** @packageDocumentation
2
- * @module Quantity
3
- */
4
- import { Format } from "./Formatter/Format";
5
- import { AlternateUnitLabelsProvider, PotentialParseUnit, QuantityProps, UnitConversionSpec, UnitProps, UnitsProvider } from "./Interfaces";
6
- import { ParserSpec } from "./ParserSpec";
7
- /** Possible parser errors
8
- * @beta
9
- */
10
- export declare enum ParseError {
11
- UnableToGenerateParseTokens = 1,
12
- NoValueOrUnitFoundInString = 2,
13
- UnitLabelSuppliedButNotMatched = 3,
14
- UnknownUnit = 4,
15
- UnableToConvertParseTokensToQuantity = 5,
16
- InvalidParserSpec = 6
17
- }
18
- /** Parse error result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]].
19
- * @beta
20
- */
21
- export interface ParseQuantityError {
22
- /** Union discriminator for [[QuantityParseResult]]. */
23
- ok: false;
24
- /** The specific error that occurred during parsing. */
25
- error: ParseError;
26
- }
27
- /** Successful result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]].
28
- * @beta
29
- */
30
- export interface ParsedQuantity {
31
- /** Union discriminator for [[QuantityParseResult]]. */
32
- ok: true;
33
- /** The magnitude of the parsed quantity. */
34
- value: number;
35
- }
36
- /**
37
- * Defines Results of parsing a string input by a user into its desired value type
38
- * @beta
39
- */
40
- export declare type QuantityParseResult = ParsedQuantity | ParseQuantityError;
41
- /** A ParseToken holds either a numeric or string token extracted from a string that represents a quantity value.
42
- * @beta
43
- */
44
- declare class ParseToken {
45
- value: number | string;
46
- constructor(value: string | number);
47
- get isString(): boolean;
48
- get isNumber(): boolean;
49
- }
50
- /** A Parser class that is used to break a string that represents a quantity value into tokens.
51
- * @beta
52
- */
53
- export declare class Parser {
54
- private static _log;
55
- static isParsedQuantity(item: QuantityParseResult): item is ParsedQuantity;
56
- static isParseError(item: QuantityParseResult): item is ParseQuantityError;
57
- private static checkForScientificNotation;
58
- private static checkForFractions;
59
- private static isDigit;
60
- private static isDigitOrDecimalSeparator;
61
- /** Parse the quantity string and return and array of ParseTokens that represent the component invariant values and unit labels.
62
- * @param quantitySpecification The quantity string to ba parsed.
63
- */
64
- static parseQuantitySpecification(quantitySpecification: string, format: Format): ParseToken[];
65
- private static lookupUnitByLabel;
66
- private static createQuantityFromParseTokens;
67
- /** Async method to generate a Quantity given a string that represents a quantity value and likely a unit label.
68
- * @param inString A string that contains text represent a quantity.
69
- * @param format Defines the likely format of inString.
70
- * @param unitsProvider required to look up units that may be specified in inString
71
- */
72
- static parseIntoQuantity(inString: string, format: Format, unitsProvider: UnitsProvider, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<QuantityProps>;
73
- /** method to get the Unit Conversion given a unit label */
74
- private static tryFindUnitConversion;
75
- private static getQuantityValueFromParseTokens;
76
- /** Method to generate a Quantity given a string that represents a quantity value.
77
- * @param inString A string that contains text represent a quantity.
78
- * @param parserSpec unit label if not explicitly defined by user. Must have matching entry in supplied array of unitsConversions.
79
- * @param defaultValue default value to return if parsing is un successful
80
- */
81
- static parseQuantityString(inString: string, parserSpec: ParserSpec): QuantityParseResult;
82
- /** Method to generate a Quantity given a string that represents a quantity value and likely a unit label.
83
- * @param inString A string that contains text represent a quantity.
84
- * @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
85
- * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
86
- */
87
- static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
88
- /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
89
- static createUnitConversionSpecsForUnit(unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]>;
90
- /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
91
- static createUnitConversionSpecs(unitsProvider: UnitsProvider, outUnitName: string, potentialParseUnits: PotentialParseUnit[], altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]>;
92
- }
93
- export {};
1
+ /** @packageDocumentation
2
+ * @module Quantity
3
+ */
4
+ import { Format } from "./Formatter/Format";
5
+ import { AlternateUnitLabelsProvider, PotentialParseUnit, QuantityProps, UnitConversionSpec, UnitProps, UnitsProvider } from "./Interfaces";
6
+ import { ParserSpec } from "./ParserSpec";
7
+ /** Possible parser errors
8
+ * @beta
9
+ */
10
+ export declare enum ParseError {
11
+ UnableToGenerateParseTokens = 1,
12
+ NoValueOrUnitFoundInString = 2,
13
+ UnitLabelSuppliedButNotMatched = 3,
14
+ UnknownUnit = 4,
15
+ UnableToConvertParseTokensToQuantity = 5,
16
+ InvalidParserSpec = 6
17
+ }
18
+ /** Parse error result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]].
19
+ * @beta
20
+ */
21
+ export interface ParseQuantityError {
22
+ /** Union discriminator for [[QuantityParseResult]]. */
23
+ ok: false;
24
+ /** The specific error that occurred during parsing. */
25
+ error: ParseError;
26
+ }
27
+ /** Successful result from [[Parser.parseToQuantityValue]] or [[Parser.parseToQuantityValue]].
28
+ * @beta
29
+ */
30
+ export interface ParsedQuantity {
31
+ /** Union discriminator for [[QuantityParseResult]]. */
32
+ ok: true;
33
+ /** The magnitude of the parsed quantity. */
34
+ value: number;
35
+ }
36
+ /**
37
+ * Defines Results of parsing a string input by a user into its desired value type
38
+ * @beta
39
+ */
40
+ export declare type QuantityParseResult = ParsedQuantity | ParseQuantityError;
41
+ /** A ParseToken holds either a numeric or string token extracted from a string that represents a quantity value.
42
+ * @beta
43
+ */
44
+ declare class ParseToken {
45
+ value: number | string;
46
+ constructor(value: string | number);
47
+ get isString(): boolean;
48
+ get isNumber(): boolean;
49
+ }
50
+ /** A Parser class that is used to break a string that represents a quantity value into tokens.
51
+ * @beta
52
+ */
53
+ export declare class Parser {
54
+ private static _log;
55
+ static isParsedQuantity(item: QuantityParseResult): item is ParsedQuantity;
56
+ static isParseError(item: QuantityParseResult): item is ParseQuantityError;
57
+ private static checkForScientificNotation;
58
+ private static checkForFractions;
59
+ private static isDigit;
60
+ private static isDigitOrDecimalSeparator;
61
+ /** Parse the quantity string and return and array of ParseTokens that represent the component invariant values and unit labels.
62
+ * @param quantitySpecification The quantity string to ba parsed.
63
+ */
64
+ static parseQuantitySpecification(quantitySpecification: string, format: Format): ParseToken[];
65
+ private static lookupUnitByLabel;
66
+ private static createQuantityFromParseTokens;
67
+ /** Async method to generate a Quantity given a string that represents a quantity value and likely a unit label.
68
+ * @param inString A string that contains text represent a quantity.
69
+ * @param format Defines the likely format of inString.
70
+ * @param unitsProvider required to look up units that may be specified in inString
71
+ */
72
+ static parseIntoQuantity(inString: string, format: Format, unitsProvider: UnitsProvider, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<QuantityProps>;
73
+ /** method to get the Unit Conversion given a unit label */
74
+ private static tryFindUnitConversion;
75
+ private static getQuantityValueFromParseTokens;
76
+ /** Method to generate a Quantity given a string that represents a quantity value.
77
+ * @param inString A string that contains text represent a quantity.
78
+ * @param parserSpec unit label if not explicitly defined by user. Must have matching entry in supplied array of unitsConversions.
79
+ * @param defaultValue default value to return if parsing is un successful
80
+ */
81
+ static parseQuantityString(inString: string, parserSpec: ParserSpec): QuantityParseResult;
82
+ /** Method to generate a Quantity given a string that represents a quantity value and likely a unit label.
83
+ * @param inString A string that contains text represent a quantity.
84
+ * @param format Defines the likely format of inString. Primary unit serves as a default unit if no unit label found in string.
85
+ * @param unitsConversions dictionary of conversions used to convert from unit used in inString to output quantity
86
+ */
87
+ static parseToQuantityValue(inString: string, format: Format, unitsConversions: UnitConversionSpec[]): QuantityParseResult;
88
+ /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
89
+ static createUnitConversionSpecsForUnit(unitsProvider: UnitsProvider, outUnit: UnitProps, altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]>;
90
+ /** Async Method used to create an array of UnitConversionSpec entries that can be used in synchronous calls to parse units. */
91
+ static createUnitConversionSpecs(unitsProvider: UnitsProvider, outUnitName: string, potentialParseUnits: PotentialParseUnit[], altUnitLabelsProvider?: AlternateUnitLabelsProvider): Promise<UnitConversionSpec[]>;
92
+ }
93
+ export {};
94
94
  //# sourceMappingURL=Parser.d.ts.map