@perses-dev/components 0.35.0 → 0.36.0

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 (177) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
  3. package/dist/ContentWithLegend/ContentWithLegend.js +4 -2
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +9 -3
  6. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  7. package/dist/ContentWithLegend/model/content-with-legend-model.js +17 -7
  8. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  9. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
  10. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
  11. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
  12. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +2 -5
  13. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  14. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  15. package/dist/GaugeChart/GaugeChart.d.ts +1 -1
  16. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  17. package/dist/GaugeChart/GaugeChart.js +1 -2
  18. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  19. package/dist/Legend/CompactLegend.d.ts +3 -1
  20. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  21. package/dist/Legend/CompactLegend.js +5 -2
  22. package/dist/Legend/CompactLegend.js.map +1 -1
  23. package/dist/Legend/Legend.d.ts +11 -2
  24. package/dist/Legend/Legend.d.ts.map +1 -1
  25. package/dist/Legend/Legend.js +4 -2
  26. package/dist/Legend/Legend.js.map +1 -1
  27. package/dist/Legend/ListLegend.d.ts +3 -1
  28. package/dist/Legend/ListLegend.d.ts.map +1 -1
  29. package/dist/Legend/ListLegend.js +5 -4
  30. package/dist/Legend/ListLegend.js.map +1 -1
  31. package/dist/Legend/ListLegendItem.d.ts +15 -2
  32. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  33. package/dist/Legend/ListLegendItem.js +17 -5
  34. package/dist/Legend/ListLegendItem.js.map +1 -1
  35. package/dist/Legend/TableLegend.d.ts +4 -2
  36. package/dist/Legend/TableLegend.d.ts.map +1 -1
  37. package/dist/Legend/TableLegend.js +8 -2
  38. package/dist/Legend/TableLegend.js.map +1 -1
  39. package/dist/LineChart/LineChart.d.ts +17 -3
  40. package/dist/LineChart/LineChart.d.ts.map +1 -1
  41. package/dist/LineChart/LineChart.js +33 -7
  42. package/dist/LineChart/LineChart.js.map +1 -1
  43. package/dist/LineChart/utils.d.ts +2 -1
  44. package/dist/LineChart/utils.d.ts.map +1 -1
  45. package/dist/LineChart/utils.js +14 -1
  46. package/dist/LineChart/utils.js.map +1 -1
  47. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +12 -0
  48. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -0
  49. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +45 -0
  50. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -0
  51. package/dist/RefreshIntervalPicker/index.d.ts +2 -0
  52. package/dist/RefreshIntervalPicker/index.d.ts.map +1 -0
  53. package/dist/{model/units → RefreshIntervalPicker}/index.js +1 -3
  54. package/dist/RefreshIntervalPicker/index.js.map +1 -0
  55. package/dist/StatChart/StatChart.d.ts +1 -1
  56. package/dist/StatChart/StatChart.d.ts.map +1 -1
  57. package/dist/StatChart/StatChart.js +1 -1
  58. package/dist/StatChart/StatChart.js.map +1 -1
  59. package/dist/Table/InnerTable.js +2 -2
  60. package/dist/Table/InnerTable.js.map +1 -1
  61. package/dist/Table/Table.d.ts +1 -1
  62. package/dist/Table/Table.d.ts.map +1 -1
  63. package/dist/Table/Table.js +57 -9
  64. package/dist/Table/Table.js.map +1 -1
  65. package/dist/Table/TableCell.d.ts +11 -1
  66. package/dist/Table/TableCell.d.ts.map +1 -1
  67. package/dist/Table/TableCell.js +8 -3
  68. package/dist/Table/TableCell.js.map +1 -1
  69. package/dist/Table/TableCheckbox.js +1 -1
  70. package/dist/Table/TableCheckbox.js.map +1 -1
  71. package/dist/Table/TableHeaderCell.d.ts +23 -0
  72. package/dist/Table/TableHeaderCell.d.ts.map +1 -0
  73. package/dist/Table/TableHeaderCell.js +53 -0
  74. package/dist/Table/TableHeaderCell.js.map +1 -0
  75. package/dist/Table/VirtualizedTable.d.ts +3 -3
  76. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  77. package/dist/Table/VirtualizedTable.js +43 -8
  78. package/dist/Table/VirtualizedTable.js.map +1 -1
  79. package/dist/Table/model/table-model.d.ts +71 -7
  80. package/dist/Table/model/table-model.d.ts.map +1 -1
  81. package/dist/Table/model/table-model.js +6 -2
  82. package/dist/Table/model/table-model.js.map +1 -1
  83. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
  84. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  85. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
  86. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  87. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -1
  88. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  89. package/dist/TimeSeriesTooltip/nearby-series.js +2 -11
  90. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  91. package/dist/UnitSelector/UnitSelector.d.ts +1 -1
  92. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  93. package/dist/UnitSelector/UnitSelector.js +1 -2
  94. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  95. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +4 -2
  96. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +17 -7
  97. package/dist/cjs/GaugeChart/GaugeChart.js +2 -3
  98. package/dist/cjs/Legend/CompactLegend.js +5 -2
  99. package/dist/cjs/Legend/Legend.js +4 -2
  100. package/dist/cjs/Legend/ListLegend.js +5 -4
  101. package/dist/cjs/Legend/ListLegendItem.js +17 -5
  102. package/dist/cjs/Legend/TableLegend.js +8 -2
  103. package/dist/cjs/LineChart/LineChart.js +31 -5
  104. package/dist/cjs/LineChart/utils.js +14 -3
  105. package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +51 -0
  106. package/dist/cjs/{model/units → RefreshIntervalPicker}/index.js +1 -3
  107. package/dist/cjs/StatChart/StatChart.js +4 -4
  108. package/dist/cjs/Table/InnerTable.js +2 -2
  109. package/dist/cjs/Table/Table.js +56 -8
  110. package/dist/cjs/Table/TableCell.js +8 -3
  111. package/dist/cjs/Table/TableCheckbox.js +1 -1
  112. package/dist/cjs/Table/TableHeaderCell.js +59 -0
  113. package/dist/cjs/Table/VirtualizedTable.js +43 -8
  114. package/dist/cjs/Table/model/table-model.js +6 -2
  115. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
  116. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -11
  117. package/dist/cjs/UnitSelector/UnitSelector.js +6 -7
  118. package/dist/cjs/index.js +1 -0
  119. package/dist/cjs/model/index.js +1 -1
  120. package/dist/{model/units/types.js → cjs/model/timeOption.js} +4 -10
  121. package/dist/index.d.ts +1 -0
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +1 -0
  124. package/dist/index.js.map +1 -1
  125. package/dist/model/index.d.ts +1 -1
  126. package/dist/model/index.d.ts.map +1 -1
  127. package/dist/model/index.js +1 -1
  128. package/dist/model/index.js.map +1 -1
  129. package/dist/model/theme.d.ts +1 -4
  130. package/dist/model/theme.d.ts.map +1 -1
  131. package/dist/model/theme.js.map +1 -1
  132. package/dist/model/timeOption.d.ts +6 -0
  133. package/dist/model/timeOption.d.ts.map +1 -0
  134. package/dist/model/{units/constants.js → timeOption.js} +2 -4
  135. package/dist/model/timeOption.js.map +1 -0
  136. package/package.json +3 -4
  137. package/dist/cjs/model/units/bytes.js +0 -84
  138. package/dist/cjs/model/units/constants.js +0 -23
  139. package/dist/cjs/model/units/decimal.js +0 -62
  140. package/dist/cjs/model/units/percent.js +0 -73
  141. package/dist/cjs/model/units/time.js +0 -105
  142. package/dist/cjs/model/units/types.js +0 -28
  143. package/dist/cjs/model/units/units.js +0 -101
  144. package/dist/cjs/model/units/utils.js +0 -42
  145. package/dist/model/units/bytes.d.ts +0 -13
  146. package/dist/model/units/bytes.d.ts.map +0 -1
  147. package/dist/model/units/bytes.js +0 -66
  148. package/dist/model/units/bytes.js.map +0 -1
  149. package/dist/model/units/constants.d.ts +0 -2
  150. package/dist/model/units/constants.d.ts.map +0 -1
  151. package/dist/model/units/constants.js.map +0 -1
  152. package/dist/model/units/decimal.d.ts +0 -13
  153. package/dist/model/units/decimal.d.ts.map +0 -1
  154. package/dist/model/units/decimal.js +0 -49
  155. package/dist/model/units/decimal.js.map +0 -1
  156. package/dist/model/units/index.d.ts +0 -4
  157. package/dist/model/units/index.d.ts.map +0 -1
  158. package/dist/model/units/index.js.map +0 -1
  159. package/dist/model/units/percent.d.ts +0 -12
  160. package/dist/model/units/percent.d.ts.map +0 -1
  161. package/dist/model/units/percent.js +0 -60
  162. package/dist/model/units/percent.js.map +0 -1
  163. package/dist/model/units/time.d.ts +0 -22
  164. package/dist/model/units/time.d.ts.map +0 -1
  165. package/dist/model/units/time.js +0 -91
  166. package/dist/model/units/time.js.map +0 -1
  167. package/dist/model/units/types.d.ts +0 -47
  168. package/dist/model/units/types.d.ts.map +0 -1
  169. package/dist/model/units/types.js.map +0 -1
  170. package/dist/model/units/units.d.ts +0 -40
  171. package/dist/model/units/units.d.ts.map +0 -1
  172. package/dist/model/units/units.js +0 -80
  173. package/dist/model/units/units.js.map +0 -1
  174. package/dist/model/units/utils.d.ts +0 -4
  175. package/dist/model/units/utils.d.ts.map +0 -1
  176. package/dist/model/units/utils.js +0 -32
  177. package/dist/model/units/utils.js.map +0 -1
@@ -1,66 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import numbro from 'numbro';
14
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
16
- const DEFAULT_NUMBRO_MANTISSA = 2;
17
- const bytesUnitKinds = [
18
- 'Bytes'
19
- ];
20
- export const BYTES_GROUP_CONFIG = {
21
- label: 'Bytes',
22
- decimal_places: true,
23
- abbreviate: true
24
- };
25
- export const BYTES_UNIT_CONFIG = {
26
- // These units are powers of 1000.
27
- // In other words, 1 KB = 1000 bytes.
28
- Bytes: {
29
- group: 'Bytes',
30
- label: 'Bytes'
31
- }
32
- };
33
- export function formatBytes(bytes, options) {
34
- const { abbreviate , decimal_places } = options;
35
- if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
36
- const formatterOptions = {
37
- style: 'unit',
38
- unit: 'byte',
39
- unitDisplay: 'long',
40
- useGrouping: true
41
- };
42
- if (hasDecimalPlaces(decimal_places)) {
43
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
44
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
45
- } else {
46
- // This can happen if bytes is between -1000 and 1000
47
- if (shouldAbbreviate(abbreviate)) {
48
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
49
- }
50
- }
51
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
52
- }
53
- // numbro is able to add units like KB, MB, GB, etc. correctly
54
- return numbro(bytes).format({
55
- output: 'byte',
56
- base: 'decimal',
57
- spaceSeparated: true,
58
- mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
59
- // trimMantissa trims trailing 0s
60
- trimMantissa: !hasDecimalPlaces(decimal_places),
61
- // optionalMantissa excludes all the decimal places if they're all zeros
62
- optionalMantissa: !hasDecimalPlaces(decimal_places)
63
- });
64
- }
65
-
66
- //# sourceMappingURL=bytes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n // These units are powers of 1000.\n // In other words, 1 KB = 1000 bytes.\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, options: BytesUnitOptions) {\n const { abbreviate, decimal_places } = options;\n\n if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n // This can happen if bytes is between -1000 and 1000\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(bytes);\n }\n\n // numbro is able to add units like KB, MB, GB, etc. correctly\n return numbro(bytes).format({\n output: 'byte',\n base: 'decimal',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimal_places),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimal_places),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","DEFAULT_NUMBRO_MANTISSA","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","options","Math","abs","formatterOptions","style","unit","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEA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;YACrE,CAAC;QACH,CAAC;QAED,OAAO0B,IAAI,CAACC,YAAY,CAAC,OAAO,EAAET,gBAAgB,CAAC,CAACU,MAAM,CAACd,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,8DAA8D;IAC9D,OAAOf,MAAM,CAACe,KAAK,CAAC,CAACc,MAAM,CAAC;QAC1BC,MAAM,EAAE,MAAM;QACdC,IAAI,EAAE,SAAS;QACfC,cAAc,EAAE,IAAI;QACpBC,QAAQ,EAAE/B,gBAAgB,CAACO,cAAc,CAAC,GAAGA,cAAc,GAAGJ,uBAAuB;QACrF,iCAAiC;QACjC6B,YAAY,EAAE,CAAChC,gBAAgB,CAACO,cAAc,CAAC;QAC/C,wEAAwE;QACxE0B,gBAAgB,EAAE,CAACjC,gBAAgB,CAACO,cAAc,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const MAX_SIGNIFICANT_DIGITS = 3;
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/model/units/constants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/constants.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common constants needed across individual unit groups and the overall\n// combined units.\nexport const MAX_SIGNIFICANT_DIGITS = 3;\n"],"names":["MAX_SIGNIFICANT_DIGITS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wEAAwE;AACxE,kBAAkB;AAClB,OAAO,MAAMA,sBAAsB,GAAG,CAAC,CAAC"}
@@ -1,13 +0,0 @@
1
- import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const decimalUnitKinds: readonly ["Decimal"];
3
- declare type DecimalUnitKind = (typeof decimalUnitKinds)[number];
4
- export declare type DecimalUnitOptions = {
5
- kind: DecimalUnitKind;
6
- decimal_places?: number;
7
- abbreviate?: boolean;
8
- };
9
- export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
10
- export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
11
- export declare function formatDecimal(value: number, options: DecimalUnitOptions): string;
12
- export {};
13
- //# sourceMappingURL=decimal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAsBhF"}
@@ -1,49 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
15
- const decimalUnitKinds = [
16
- 'Decimal'
17
- ];
18
- export const DECIMAL_GROUP_CONFIG = {
19
- label: 'Decimal',
20
- decimal_places: true,
21
- abbreviate: true
22
- };
23
- export const DECIMAL_UNIT_CONFIG = {
24
- Decimal: {
25
- group: 'Decimal',
26
- label: 'Decimal'
27
- }
28
- };
29
- export function formatDecimal(value, options) {
30
- const { abbreviate , decimal_places } = options;
31
- const formatterOptions = {
32
- style: 'decimal',
33
- useGrouping: true
34
- };
35
- if (shouldAbbreviate(abbreviate)) {
36
- formatterOptions.notation = 'compact';
37
- }
38
- if (hasDecimalPlaces(decimal_places)) {
39
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
40
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
41
- } else {
42
- if (shouldAbbreviate(abbreviate)) {
43
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
44
- }
45
- }
46
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
47
- }
48
-
49
- //# sourceMappingURL=decimal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, options: DecimalUnitOptions): string {\n const { abbreviate, decimal_places } = options;\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","decimalUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","options","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBL,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASM,aAAa,CAACC,KAAa,EAAEC,OAA2B,EAAU;IAChF,MAAM,EAAEN,UAAU,CAAA,EAAED,cAAc,CAAA,EAAE,GAAGO,OAAO,AAAC;IAE/C,MAAMC,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,IAAI;KAClB,AAAC;IAEF,IAAId,gBAAgB,CAACK,UAAU,CAAC,EAAE;QAChCO,gBAAgB,CAACG,QAAQ,GAAG,SAAS,CAAC;IACxC,CAAC;IAED,IAAIjB,gBAAgB,CAACM,cAAc,CAAC,EAAE;QACpCQ,gBAAgB,CAACI,qBAAqB,GAAGjB,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EQ,gBAAgB,CAACK,qBAAqB,GAAGlB,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACL,IAAIJ,gBAAgB,CAACK,UAAU,CAAC,EAAE;YAChCO,gBAAgB,CAACM,wBAAwB,GAAGrB,sBAAsB,CAAC;QACrE,CAAC;IACH,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,CAACS,MAAM,CAACX,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './units';
2
- export * from './constants';
3
- export * from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/units/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './units';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -1,12 +0,0 @@
1
- import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const percentUnitKinds: readonly ["Percent", "PercentDecimal", "%"];
3
- declare type PercentUnitKind = (typeof percentUnitKinds)[number];
4
- export declare type PercentUnitOptions = {
5
- kind: PercentUnitKind;
6
- decimal_places?: number;
7
- };
8
- export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
9
- export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
10
- export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
11
- export {};
12
- //# sourceMappingURL=percent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAmBjG"}
@@ -1,60 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const percentUnitKinds = [
16
- 'Percent',
17
- 'PercentDecimal',
18
- '%'
19
- ];
20
- export const PERCENT_GROUP_CONFIG = {
21
- label: 'Percent',
22
- decimal_places: true
23
- };
24
- const PERCENT_GROUP = 'Percent';
25
- export const PERCENT_UNIT_CONFIG = {
26
- Percent: {
27
- group: PERCENT_GROUP,
28
- label: 'Percent (0-100)'
29
- },
30
- PercentDecimal: {
31
- group: PERCENT_GROUP,
32
- label: 'Percent (0.0-1.0)'
33
- },
34
- '%': {
35
- // This option is not shown in the selector because it is a shorthand
36
- // duplicate of `Percent`.
37
- disableSelectorOption: true,
38
- group: PERCENT_GROUP,
39
- label: '%'
40
- }
41
- };
42
- export function formatPercent(value, { kind , decimal_places }) {
43
- // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
44
- if (kind === 'Percent') {
45
- value = value / 100;
46
- }
47
- const formatterOptions = {
48
- style: 'percent',
49
- useGrouping: true
50
- };
51
- if (hasDecimalPlaces(decimal_places)) {
52
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
53
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
54
- } else {
55
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
56
- }
57
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
58
- }
59
-
60
- //# sourceMappingURL=percent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string {\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%\n if (kind === 'Percent') {\n value = value / 100;\n }\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","formatPercent","value","kind","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format"],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AAC;QAC5EU,gBAAgB,CAACI,qBAAqB,GAAGlB,kBAAkB,CAACI,cAAc,CAAC,CAAC;IAC9E,OAAO;QACLU,gBAAgB,CAACK,wBAAwB,GAAGrB,sBAAsB,CAAC;IACrE,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,gBAAgB,CAAC,CAACQ,MAAM,CAACV,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -1,22 +0,0 @@
1
- import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const timeUnitKinds: readonly ["Milliseconds", "Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", "Years"];
3
- declare type TimeUnitKind = (typeof timeUnitKinds)[number];
4
- export declare type TimeUnitOptions = {
5
- kind: TimeUnitKind;
6
- decimal_places?: number;
7
- };
8
- export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
9
- export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
10
- export declare enum PersesTimeToIntlTime {
11
- Milliseconds = "millisecond",
12
- Seconds = "second",
13
- Minutes = "minute",
14
- Hours = "hour",
15
- Days = "day",
16
- Weeks = "week",
17
- Months = "month",
18
- Years = "year"
19
- }
20
- export declare function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string;
21
- export {};
22
- //# sourceMappingURL=time.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,eAAe,GAAG,MAAM,CAiB3F"}
@@ -1,91 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const timeUnitKinds = [
16
- 'Milliseconds',
17
- 'Seconds',
18
- 'Minutes',
19
- 'Hours',
20
- 'Days',
21
- 'Weeks',
22
- 'Months',
23
- 'Years'
24
- ];
25
- const TIME_GROUP = 'Time';
26
- export const TIME_GROUP_CONFIG = {
27
- label: 'Time',
28
- decimal_places: true
29
- };
30
- export const TIME_UNIT_CONFIG = {
31
- Milliseconds: {
32
- group: TIME_GROUP,
33
- label: 'Milliseconds'
34
- },
35
- Seconds: {
36
- group: TIME_GROUP,
37
- label: 'Seconds'
38
- },
39
- Minutes: {
40
- group: TIME_GROUP,
41
- label: 'Minutes'
42
- },
43
- Hours: {
44
- group: TIME_GROUP,
45
- label: 'Hours'
46
- },
47
- Days: {
48
- group: TIME_GROUP,
49
- label: 'Days'
50
- },
51
- Weeks: {
52
- group: TIME_GROUP,
53
- label: 'Weeks'
54
- },
55
- Months: {
56
- group: TIME_GROUP,
57
- label: 'Months'
58
- },
59
- Years: {
60
- group: TIME_GROUP,
61
- label: 'Years'
62
- }
63
- };
64
- export var PersesTimeToIntlTime;
65
- (function(PersesTimeToIntlTime) {
66
- PersesTimeToIntlTime["Milliseconds"] = 'millisecond';
67
- PersesTimeToIntlTime["Seconds"] = 'second';
68
- PersesTimeToIntlTime["Minutes"] = 'minute';
69
- PersesTimeToIntlTime["Hours"] = 'hour';
70
- PersesTimeToIntlTime["Days"] = 'day';
71
- PersesTimeToIntlTime["Weeks"] = 'week';
72
- PersesTimeToIntlTime["Months"] = 'month';
73
- PersesTimeToIntlTime["Years"] = 'year';
74
- })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
75
- export function formatTime(value, { kind , decimal_places }) {
76
- const isMonthOrYear = kind === 'Months' || kind === 'Years';
77
- const formatterOptions = {
78
- style: 'unit',
79
- unit: PersesTimeToIntlTime[kind],
80
- unitDisplay: isMonthOrYear ? 'long' : 'narrow'
81
- };
82
- if (hasDecimalPlaces(decimal_places)) {
83
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
84
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
85
- } else {
86
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
87
- }
88
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
89
- }
90
-
91
- //# sourceMappingURL=time.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\n Milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n Seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n Minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n Hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n Days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n Weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n Months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n Years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum PersesTimeToIntlTime {\n Milliseconds = 'millisecond',\n Seconds = 'second',\n Minutes = 'minute',\n Hours = 'hour',\n Days = 'day',\n Weeks = 'week',\n Months = 'month',\n Years = 'year',\n}\n\nexport function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string {\n const isMonthOrYear = kind === 'Months' || kind === 'Years';\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[kind],\n unitDisplay: isMonthOrYear ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","decimal_places","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","PersesTimeToIntlTime","formatTime","value","kind","isMonthOrYear","formatterOptions","style","unit","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,SAAS,CAAC;AAE/D,MAAMC,aAAa,GAAG;IAAC,cAAc;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;IAAE,MAAM;IAAE,OAAO;IAAE,QAAQ;IAAE,OAAO;CAAC,AAAS,AAAC;AAMnH,MAAMC,UAAU,GAAG,MAAM,AAAC;AAC1B,OAAO,MAAMC,iBAAiB,GAAoB;IAChDC,KAAK,EAAE,MAAM;IACbC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,OAAO,MAAMC,gBAAgB,GAA+C;IAC1EC,YAAY,EAAE;QACZC,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,cAAc;KACtB;IACDK,OAAO,EAAE;QACPD,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,SAAS;KACjB;IACD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AE;QACpCgB,gBAAgB,CAACI,qBAAqB,GAAGzB,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EgB,gBAAgB,CAACK,qBAAqB,GAAG1B,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACLgB,gBAAgB,CAACM,wBAAwB,GAAG7B,sBAAsB,CAAC;IACrE,CAAC;IAED,OAAO8B,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,CAACS,MAAM,CAACZ,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -1,47 +0,0 @@
1
- import { UnitOptions } from './units';
2
- export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes"];
3
- export declare type UnitGroup = (typeof UNIT_GROUPS)[number];
4
- /**
5
- * Configuration for rendering units that are part of a group.
6
- */
7
- export declare type UnitGroupConfig = {
8
- /**
9
- * The label that is shown in the UI.
10
- */
11
- label: string;
12
- /**
13
- * When true, the unit group supports setting decimal places.
14
- */
15
- decimal_places?: boolean;
16
- /**
17
- * When true, the unit group supports enabling abbreviate.
18
- */
19
- abbreviate?: boolean;
20
- };
21
- /**
22
- * Configuration for rendering a specific unit.
23
- */
24
- export declare type UnitConfig = {
25
- /**
26
- * The group the unit is part of. This will inform common rendering behavior.
27
- */
28
- group: UnitGroup;
29
- /**
30
- * When true, this unit will not be displayed in the unit selector. This is
31
- * useful for units that are shorthand variants of other units.
32
- */
33
- disableSelectorOption?: boolean;
34
- /**
35
- * The label that is shown in the UI.
36
- */
37
- label: string;
38
- };
39
- /**
40
- * Used in the tests for each type of unit.
41
- */
42
- export interface UnitTestCase {
43
- value: number;
44
- unit: UnitOptions;
45
- expected: string;
46
- }
47
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,WAAW,kDAAmD,CAAC;AAC5E,oBAAY,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport { UnitOptions } from './units';\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimal_places?: boolean;\n /**\n * When true, the unit group supports enabling abbreviate.\n */\n abbreviate?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n\n/**\n * Used in the tests for each type of unit.\n */\nexport interface UnitTestCase {\n value: number;\n unit: UnitOptions;\n expected: string;\n}\n"],"names":["UNIT_GROUPS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,6EAA6E;AAC7E,SAAS;AAIT,OAAO,MAAMA,WAAW,GAAG;IAAC,MAAM;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;CAAC,AAAS,CAAC"}
@@ -1,40 +0,0 @@
1
- import { BytesUnitOptions } from './bytes';
2
- import { DecimalUnitOptions } from './decimal';
3
- import { PercentUnitOptions } from './percent';
4
- import { TimeUnitOptions } from './time';
5
- import { UnitGroup, UnitGroupConfig, UnitConfig } from './types';
6
- export declare const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>>;
7
- export declare const UNIT_CONFIG: {
8
- readonly Bytes: UnitConfig;
9
- readonly Decimal: UnitConfig;
10
- readonly Percent: UnitConfig;
11
- readonly PercentDecimal: UnitConfig;
12
- readonly "%": UnitConfig;
13
- readonly Milliseconds: UnitConfig;
14
- readonly Seconds: UnitConfig;
15
- readonly Minutes: UnitConfig;
16
- readonly Hours: UnitConfig;
17
- readonly Days: UnitConfig;
18
- readonly Weeks: UnitConfig;
19
- readonly Months: UnitConfig;
20
- readonly Years: UnitConfig;
21
- };
22
- export declare type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;
23
- declare type HasDecimalPlaces<UnitOpt> = UnitOpt extends {
24
- decimal_places?: number;
25
- } ? UnitOpt : never;
26
- declare type HasAbbreviate<UnitOpt> = UnitOpt extends {
27
- abbreviate?: boolean;
28
- } ? UnitOpt : never;
29
- export declare function formatValue(value: number, unitOptions?: UnitOptions): string;
30
- export declare function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig;
31
- export declare function getUnitGroup(unitOptions: UnitOptions): UnitGroup;
32
- export declare function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig;
33
- export declare function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions;
34
- export declare function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions;
35
- export declare function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions;
36
- export declare function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions;
37
- export declare function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions>;
38
- export declare function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions>;
39
- export {};
40
- //# sourceMappingURL=units.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAsD,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAA4D,MAAM,WAAW,CAAC;AACzG,OAAO,EAAuC,kBAAkB,EAAuB,MAAM,WAAW,CAAC;AACzG,OAAO,EAAc,eAAe,EAAuC,MAAM,QAAQ,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,C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Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';
14
- import { DECIMAL_UNIT_CONFIG, formatDecimal, DECIMAL_GROUP_CONFIG } from './decimal';
15
- import { PERCENT_GROUP_CONFIG, formatPercent, PERCENT_UNIT_CONFIG } from './percent';
16
- import { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';
17
- export const UNIT_GROUP_CONFIG = {
18
- Time: TIME_GROUP_CONFIG,
19
- Percent: PERCENT_GROUP_CONFIG,
20
- Decimal: DECIMAL_GROUP_CONFIG,
21
- Bytes: BYTES_GROUP_CONFIG
22
- };
23
- export const UNIT_CONFIG = {
24
- ...TIME_UNIT_CONFIG,
25
- ...PERCENT_UNIT_CONFIG,
26
- ...DECIMAL_UNIT_CONFIG,
27
- ...BYTES_UNIT_CONFIG
28
- };
29
- export function formatValue(value, unitOptions) {
30
- if (unitOptions === undefined) {
31
- return value.toString();
32
- }
33
- if (isDecimalUnit(unitOptions)) {
34
- return formatDecimal(value, unitOptions);
35
- }
36
- if (isTimeUnit(unitOptions)) {
37
- return formatTime(value, unitOptions);
38
- }
39
- if (isPercentUnit(unitOptions)) {
40
- return formatPercent(value, unitOptions);
41
- }
42
- if (isBytesUnit(unitOptions)) {
43
- return formatBytes(value, unitOptions);
44
- }
45
- const exhaustive = unitOptions;
46
- throw new Error(`Unknown unit options ${exhaustive}`);
47
- }
48
- export function getUnitKindConfig(unitOptions) {
49
- return UNIT_CONFIG[unitOptions.kind];
50
- }
51
- export function getUnitGroup(unitOptions) {
52
- return getUnitKindConfig(unitOptions).group;
53
- }
54
- export function getUnitGroupConfig(unitOptions) {
55
- const unitConfig = getUnitKindConfig(unitOptions);
56
- return UNIT_GROUP_CONFIG[unitConfig.group];
57
- }
58
- // Type guards
59
- export function isTimeUnit(unitOptions) {
60
- return getUnitGroup(unitOptions) === 'Time';
61
- }
62
- export function isPercentUnit(unitOptions) {
63
- return getUnitGroup(unitOptions) === 'Percent';
64
- }
65
- export function isDecimalUnit(unitOptions) {
66
- return getUnitGroup(unitOptions) === 'Decimal';
67
- }
68
- export function isBytesUnit(unitOptions) {
69
- return getUnitGroup(unitOptions) === 'Bytes';
70
- }
71
- export function isUnitWithDecimalPlaces(unitOptions) {
72
- const groupConfig = getUnitGroupConfig(unitOptions);
73
- return !!groupConfig.decimal_places;
74
- }
75
- export function isUnitWithAbbreviate(unitOptions) {
76
- const groupConfig = getUnitGroupConfig(unitOptions);
77
- return !!groupConfig.abbreviate;
78
- }
79
-
80
- //# sourceMappingURL=units.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/units.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';\nimport { DecimalUnitOptions, DECIMAL_UNIT_CONFIG, formatDecimal, DECIMAL_GROUP_CONFIG } from './decimal';\nimport { PERCENT_GROUP_CONFIG, formatPercent, PercentUnitOptions, PERCENT_UNIT_CONFIG } from './percent';\nimport { formatTime, TimeUnitOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n} as const;\n\nexport type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimal_places?: number } ? UnitOpt : never;\ntype HasAbbreviate<UnitOpt> = UnitOpt extends { abbreviate?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, unitOptions?: UnitOptions): string {\n if (unitOptions === undefined) {\n return value.toString();\n }\n\n if (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isBytesUnit(unitOptions)) {\n return formatBytes(value, unitOptions);\n }\n\n const exhaustive: never = unitOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig {\n return UNIT_CONFIG[unitOptions.kind];\n}\n\nexport function getUnitGroup(unitOptions: UnitOptions): UnitGroup {\n return getUnitKindConfig(unitOptions).group;\n}\n\nexport function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig {\n const unitConfig = getUnitKindConfig(unitOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group];\n}\n\n// Type guards\nexport function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions {\n return getUnitGroup(unitOptions) === 'Time';\n}\n\nexport function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions {\n return getUnitGroup(unitOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions {\n return getUnitGroup(unitOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions {\n return getUnitGroup(unitOptions) === 'Bytes';\n}\n\nexport function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.decimal_places;\n}\n\nexport function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.abbreviate;\n}\n"],"names":["BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatBytes","DECIMAL_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","PERCENT_GROUP_CONFIG","formatPercent","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","unitOptions","undefined","toString","isDecimalUnit","isTimeUnit","isPercentUnit","isBytesUnit","exhaustive","Error","getUnitKindConfig","kind","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimal_places","isUnitWithAbbreviate","abbreviate"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAA2BA,kBAAkB,EAAEC,iBAAiB,EAAEC,WAAW,QAAQ,SAAS,CAAC;AAC/F,SAA6BC,mBAAmB,EAAEC,aAAa,EAAE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ate?: boolean): boolean;
2
- export declare function hasDecimalPlaces(decimal_places?: number): boolean;
3
- export declare function limitDecimalPlaces(num?: number): number | undefined;
4
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/model/units/utils.ts"],"names":[],"mappings":"AAaA,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,OAAO,WAEpD;AAED,wBAAgB,gBAAgB,CAAC,cAAc,CAAC,EAAE,MAAM,WAEvD;AAKD,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,sBAU9C"}