@perses-dev/components 0.54.0-beta.0 → 0.54.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  3. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +1 -1
  4. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.js +1 -1
  6. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  7. package/dist/FormEditor/FormActions.d.ts +1 -1
  8. package/dist/FormEditor/FormActions.d.ts.map +1 -1
  9. package/dist/FormEditor/FormActions.js.map +1 -1
  10. package/dist/FormatControls/FormatControls.d.ts +1 -1
  11. package/dist/FormatControls/FormatControls.d.ts.map +1 -1
  12. package/dist/FormatControls/FormatControls.js +1 -1
  13. package/dist/FormatControls/FormatControls.js.map +1 -1
  14. package/dist/FormatControls/UnitSelector.d.ts +1 -1
  15. package/dist/FormatControls/UnitSelector.d.ts.map +1 -1
  16. package/dist/FormatControls/UnitSelector.js +1 -1
  17. package/dist/FormatControls/UnitSelector.js.map +1 -1
  18. package/dist/Legend/Legend.js +1 -1
  19. package/dist/Legend/Legend.js.map +1 -1
  20. package/dist/Legend/legend-model.d.ts +1 -1
  21. package/dist/Legend/legend-model.d.ts.map +1 -1
  22. package/dist/Legend/legend-model.js.map +1 -1
  23. package/dist/Table/Table.d.ts +1 -1
  24. package/dist/Table/Table.d.ts.map +1 -1
  25. package/dist/Table/Table.js +26 -6
  26. package/dist/Table/Table.js.map +1 -1
  27. package/dist/Table/TableToolbar.d.ts +34 -0
  28. package/dist/Table/TableToolbar.d.ts.map +1 -0
  29. package/dist/Table/TableToolbar.js +127 -0
  30. package/dist/Table/TableToolbar.js.map +1 -0
  31. package/dist/Table/VirtualizedTable.d.ts +3 -1
  32. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  33. package/dist/Table/VirtualizedTable.js +128 -117
  34. package/dist/Table/VirtualizedTable.js.map +1 -1
  35. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -1
  36. package/dist/Table/VirtualizedTableContainer.js +5 -1
  37. package/dist/Table/VirtualizedTableContainer.js.map +1 -1
  38. package/dist/Table/hooks/useFuzzySearch.d.ts +12 -0
  39. package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -0
  40. package/dist/Table/hooks/useFuzzySearch.js +43 -0
  41. package/dist/Table/hooks/useFuzzySearch.js.map +1 -0
  42. package/dist/Table/model/table-model.d.ts +37 -3
  43. package/dist/Table/model/table-model.d.ts.map +1 -1
  44. package/dist/Table/model/table-model.js.map +1 -1
  45. package/dist/ThresholdsEditor/ThresholdInput.d.ts +1 -1
  46. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
  47. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  48. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +1 -1
  49. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
  50. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  51. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +1 -2
  52. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
  53. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  54. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
  55. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  56. package/dist/TimeSeriesTooltip/nearby-series.js +1 -2
  57. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  58. package/dist/TransformsEditor/TransformEditor.d.ts +1 -1
  59. package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
  60. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  61. package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -1
  62. package/dist/TransformsEditor/TransformEditorContainer.js +1 -1
  63. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  64. package/dist/TransformsEditor/TransformsEditor.d.ts +1 -1
  65. package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -1
  66. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  67. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +2 -2
  68. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -2
  69. package/dist/cjs/FormatControls/FormatControls.js +4 -4
  70. package/dist/cjs/FormatControls/UnitSelector.js +3 -3
  71. package/dist/cjs/Legend/Legend.js +2 -2
  72. package/dist/cjs/Table/Table.js +24 -4
  73. package/dist/cjs/Table/TableToolbar.js +140 -0
  74. package/dist/cjs/Table/VirtualizedTable.js +126 -115
  75. package/dist/cjs/Table/VirtualizedTableContainer.js +5 -1
  76. package/dist/cjs/Table/hooks/useFuzzySearch.js +48 -0
  77. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -3
  78. package/dist/cjs/TransformsEditor/TransformEditorContainer.js +2 -2
  79. package/dist/cjs/model/action.js +43 -0
  80. package/dist/cjs/model/bits.js +113 -0
  81. package/dist/cjs/model/bytes.js +115 -0
  82. package/dist/cjs/model/constants.js +23 -0
  83. package/dist/cjs/model/currency.js +126 -0
  84. package/dist/cjs/model/date.js +297 -0
  85. package/dist/cjs/model/decimal.js +72 -0
  86. package/dist/cjs/model/formatterCache.js +120 -0
  87. package/dist/cjs/model/index.js +16 -0
  88. package/dist/cjs/model/legend.js +101 -0
  89. package/dist/cjs/model/percent.js +82 -0
  90. package/dist/cjs/model/temperature.js +72 -0
  91. package/dist/cjs/model/thresholds.js +16 -0
  92. package/dist/cjs/model/throughput.js +161 -0
  93. package/dist/cjs/model/time.js +178 -0
  94. package/dist/cjs/model/transforms.js +29 -0
  95. package/dist/cjs/model/types.js +16 -0
  96. package/dist/cjs/model/units.js +186 -0
  97. package/dist/cjs/model/utils.js +48 -0
  98. package/dist/cjs/utils/axis.js +5 -5
  99. package/dist/cjs/utils/index.js +1 -0
  100. package/dist/cjs/utils/request-interpolation.js +49 -0
  101. package/dist/model/action.d.ts +4 -0
  102. package/dist/model/action.d.ts.map +1 -0
  103. package/dist/model/action.js +27 -0
  104. package/dist/model/action.js.map +1 -0
  105. package/dist/model/bits.d.ts +12 -0
  106. package/dist/model/bits.d.ts.map +1 -0
  107. package/dist/model/bits.js +89 -0
  108. package/dist/model/bits.js.map +1 -0
  109. package/dist/model/bytes.d.ts +12 -0
  110. package/dist/model/bytes.d.ts.map +1 -0
  111. package/dist/model/bytes.js +91 -0
  112. package/dist/model/bytes.js.map +1 -0
  113. package/dist/model/constants.d.ts +2 -0
  114. package/dist/model/constants.d.ts.map +1 -0
  115. package/dist/model/constants.js +15 -0
  116. package/dist/model/constants.js.map +1 -0
  117. package/dist/model/currency.d.ts +11 -0
  118. package/dist/model/currency.d.ts.map +1 -0
  119. package/dist/model/currency.js +107 -0
  120. package/dist/model/currency.js.map +1 -0
  121. package/dist/model/date.d.ts +28 -0
  122. package/dist/model/date.d.ts.map +1 -0
  123. package/dist/model/date.js +278 -0
  124. package/dist/model/date.js.map +1 -0
  125. package/dist/model/decimal.d.ts +12 -0
  126. package/dist/model/decimal.d.ts.map +1 -0
  127. package/dist/model/decimal.js +53 -0
  128. package/dist/model/decimal.js.map +1 -0
  129. package/dist/model/formatterCache.d.ts +11 -0
  130. package/dist/model/formatterCache.d.ts.map +1 -0
  131. package/dist/model/formatterCache.js +104 -0
  132. package/dist/model/formatterCache.js.map +1 -0
  133. package/dist/model/index.d.ts +16 -0
  134. package/dist/model/index.d.ts.map +1 -1
  135. package/dist/model/index.js +16 -0
  136. package/dist/model/index.js.map +1 -1
  137. package/dist/model/legend.d.ts +19 -0
  138. package/dist/model/legend.d.ts.map +1 -0
  139. package/dist/model/legend.js +61 -0
  140. package/dist/model/legend.js.map +1 -0
  141. package/dist/model/percent.d.ts +11 -0
  142. package/dist/model/percent.d.ts.map +1 -0
  143. package/dist/model/percent.js +63 -0
  144. package/dist/model/percent.js.map +1 -0
  145. package/dist/model/temperature.d.ts +11 -0
  146. package/dist/model/temperature.d.ts.map +1 -0
  147. package/dist/model/temperature.js +53 -0
  148. package/dist/model/temperature.js.map +1 -0
  149. package/dist/model/theme.d.ts +1 -1
  150. package/dist/model/theme.d.ts.map +1 -1
  151. package/dist/model/theme.js.map +1 -1
  152. package/dist/model/thresholds.d.ts +16 -0
  153. package/dist/model/thresholds.d.ts.map +1 -0
  154. package/dist/model/thresholds.js +15 -0
  155. package/dist/model/thresholds.js.map +1 -0
  156. package/dist/model/throughput.d.ts +12 -0
  157. package/dist/model/throughput.d.ts.map +1 -0
  158. package/dist/model/throughput.js +142 -0
  159. package/dist/model/throughput.js.map +1 -0
  160. package/dist/model/time.d.ts +23 -0
  161. package/dist/model/time.d.ts.map +1 -0
  162. package/dist/model/time.js +158 -0
  163. package/dist/model/time.js.map +1 -0
  164. package/dist/model/transforms.d.ts +43 -0
  165. package/dist/model/transforms.d.ts.map +1 -0
  166. package/dist/model/transforms.js +22 -0
  167. package/dist/model/transforms.js.map +1 -0
  168. package/dist/model/types.d.ts +56 -0
  169. package/dist/model/types.d.ts.map +1 -0
  170. package/dist/model/types.js +15 -0
  171. package/dist/model/types.js.map +1 -0
  172. package/dist/model/units.d.ts +105 -0
  173. package/dist/model/units.d.ts.map +1 -0
  174. package/dist/model/units.js +132 -0
  175. package/dist/model/units.js.map +1 -0
  176. package/dist/model/utils.d.ts +4 -0
  177. package/dist/model/utils.d.ts.map +1 -0
  178. package/dist/model/utils.js +32 -0
  179. package/dist/model/utils.js.map +1 -0
  180. package/dist/utils/axis.d.ts +1 -1
  181. package/dist/utils/axis.d.ts.map +1 -1
  182. package/dist/utils/axis.js +1 -1
  183. package/dist/utils/axis.js.map +1 -1
  184. package/dist/utils/index.d.ts +1 -0
  185. package/dist/utils/index.d.ts.map +1 -1
  186. package/dist/utils/index.js +1 -0
  187. package/dist/utils/index.js.map +1 -1
  188. package/dist/utils/request-interpolation.d.ts +6 -0
  189. package/dist/utils/request-interpolation.d.ts.map +1 -0
  190. package/dist/utils/request-interpolation.js +33 -0
  191. package/dist/utils/request-interpolation.js.map +1 -0
  192. package/package.json +2 -1
@@ -0,0 +1,113 @@
1
+ // Copyright 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get BITS_GROUP_CONFIG () {
25
+ return BITS_GROUP_CONFIG;
26
+ },
27
+ get BITS_UNIT_CONFIG () {
28
+ return BITS_UNIT_CONFIG;
29
+ },
30
+ get formatBits () {
31
+ return formatBits;
32
+ }
33
+ });
34
+ const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
35
+ const _constants = require("./constants");
36
+ const _utils = require("./utils");
37
+ const _formatterCache = require("./formatterCache");
38
+ function _interop_require_default(obj) {
39
+ return obj && obj.__esModule ? obj : {
40
+ default: obj
41
+ };
42
+ }
43
+ /**
44
+ * We support both SI (decimal) and IEC (binary) units for bits:
45
+ *
46
+ * SI/decimal (unit: 'decbits'):
47
+ * 1 Kb = 1000 bits (1000^1 bits)
48
+ * 1 Mb = 1,000,000 bits (1000^2 bits)
49
+ * etc.
50
+ *
51
+ * IEC/binary (unit: 'bits'):
52
+ * 1 Kib = 1024 bits (1024^1 bits)
53
+ * 1 Mib = 1,048,576 bits (1024^2 bits)
54
+ * etc.
55
+ */ const DEFAULT_NUMBRO_MANTISSA = 2;
56
+ const BITS_GROUP_CONFIG = {
57
+ label: 'Bits',
58
+ decimalPlaces: true,
59
+ shortValues: true
60
+ };
61
+ const BITS_UNIT_CONFIG = {
62
+ bits: {
63
+ group: 'Bits',
64
+ label: 'Bits (IEC)'
65
+ },
66
+ decbits: {
67
+ group: 'Bits',
68
+ label: 'Bits (SI)'
69
+ }
70
+ };
71
+ function formatBits(bits, { unit = 'bits', shortValues, decimalPlaces }) {
72
+ const isDecimal = unit === 'decbits';
73
+ const threshold = isDecimal ? 1000 : 1024;
74
+ // If we're showing the entire value, we can use Intl.NumberFormat.
75
+ if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bits) < threshold) {
76
+ const formatterOptions = {
77
+ style: 'decimal',
78
+ useGrouping: true
79
+ };
80
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
81
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
82
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
83
+ } else {
84
+ // This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)
85
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
86
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
87
+ }
88
+ }
89
+ const key = [
90
+ formatterOptions.style,
91
+ formatterOptions.useGrouping,
92
+ formatterOptions.maximumSignificantDigits,
93
+ decimalPlaces,
94
+ shortValues,
95
+ unit
96
+ ];
97
+ return `${(0, _formatterCache.getFormatterFromCache)(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;
98
+ }
99
+ // If we're showing the shorten value, we use numbro.
100
+ // numbro is able to add units like Kb, Mb, Gb, etc. correctly.
101
+ const formatted = (0, _numbro.default)(bits).format({
102
+ output: 'byte',
103
+ base: isDecimal ? 'decimal' : 'binary',
104
+ spaceSeparated: true,
105
+ mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
106
+ // trimMantissa trims trailing 0s
107
+ trimMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces),
108
+ // optionalMantissa excludes all the decimal places if they're all zeros
109
+ optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces)
110
+ });
111
+ // Replace byte units with bit units
112
+ return formatted.replace(/KB/g, 'Kb').replace(/MB/g, 'Mb').replace(/GB/g, 'Gb').replace(/TB/g, 'Tb').replace(/PB/g, 'Pb').replace(/EB/g, 'Eb').replace(/KiB/g, 'Kib').replace(/MiB/g, 'Mib').replace(/GiB/g, 'Gib').replace(/TiB/g, 'Tib').replace(/PiB/g, 'Pib').replace(/EiB/g, 'Eib');
113
+ }
@@ -0,0 +1,115 @@
1
+ // Copyright 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get BYTES_GROUP_CONFIG () {
25
+ return BYTES_GROUP_CONFIG;
26
+ },
27
+ get BYTES_UNIT_CONFIG () {
28
+ return BYTES_UNIT_CONFIG;
29
+ },
30
+ get formatBytes () {
31
+ return formatBytes;
32
+ }
33
+ });
34
+ const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
35
+ const _constants = require("./constants");
36
+ const _utils = require("./utils");
37
+ const _formatterCache = require("./formatterCache");
38
+ function _interop_require_default(obj) {
39
+ return obj && obj.__esModule ? obj : {
40
+ default: obj
41
+ };
42
+ }
43
+ /**
44
+ * We support both SI (decimal) and IEC (binary) units for bytes:
45
+ *
46
+ * SI/decimal (unit: 'decbytes'):
47
+ * 1 KB = 1000 bytes (1000^1 bytes)
48
+ * 1 MB = 1,000,000 bytes (1000^2 bytes)
49
+ * etc.
50
+ *
51
+ * IEC/binary (unit: 'bytes'):
52
+ * 1 KiB = 1024 bytes (1024^1 bytes)
53
+ * 1 MiB = 1,048,576 bytes (1024^2 bytes)
54
+ * etc.
55
+ */ const DEFAULT_NUMBRO_MANTISSA = 2;
56
+ const BYTES_GROUP_CONFIG = {
57
+ label: 'Bytes',
58
+ decimalPlaces: true,
59
+ shortValues: true
60
+ };
61
+ const BYTES_UNIT_CONFIG = {
62
+ bytes: {
63
+ group: 'Bytes',
64
+ label: 'Bytes (IEC)'
65
+ },
66
+ decbytes: {
67
+ group: 'Bytes',
68
+ label: 'Bytes (SI)'
69
+ }
70
+ };
71
+ function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces }) {
72
+ const isDecimal = unit === 'decbytes';
73
+ const threshold = isDecimal ? 1000 : 1024;
74
+ // If we're showing the entire value, we can use Intl.NumberFormat.
75
+ if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bytes) < threshold) {
76
+ const formatterOptions = {
77
+ style: 'unit',
78
+ unit: 'byte',
79
+ unitDisplay: 'long',
80
+ useGrouping: true
81
+ };
82
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
83
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
84
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
85
+ } else {
86
+ // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)
87
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
88
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
89
+ }
90
+ }
91
+ const key = [
92
+ formatterOptions.style,
93
+ formatterOptions.unit,
94
+ formatterOptions.unitDisplay,
95
+ formatterOptions.useGrouping,
96
+ formatterOptions.maximumSignificantDigits,
97
+ decimalPlaces,
98
+ shortValues,
99
+ unit
100
+ ];
101
+ return (0, _formatterCache.getFormatterFromCache)(key, 'bytes', formatterOptions, 'en-US')(bytes);
102
+ }
103
+ // If we're showing the shorten value, we use numbro.
104
+ // numbro is able to add units like KB, MB, GB, etc. correctly.
105
+ return (0, _numbro.default)(bytes).format({
106
+ output: 'byte',
107
+ base: isDecimal ? 'decimal' : 'binary',
108
+ spaceSeparated: true,
109
+ mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
110
+ // trimMantissa trims trailing 0s
111
+ trimMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces),
112
+ // optionalMantissa excludes all the decimal places if they're all zeros
113
+ optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces)
114
+ });
115
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "MAX_SIGNIFICANT_DIGITS", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return MAX_SIGNIFICANT_DIGITS;
21
+ }
22
+ });
23
+ const MAX_SIGNIFICANT_DIGITS = 3;
@@ -0,0 +1,126 @@
1
+ // Copyright 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get CURRENCY_GROUP_CONFIG () {
25
+ return CURRENCY_GROUP_CONFIG;
26
+ },
27
+ get CURRENCY_UNIT_CONFIG () {
28
+ return CURRENCY_UNIT_CONFIG;
29
+ },
30
+ get formatCurrency () {
31
+ return formatCurrency;
32
+ }
33
+ });
34
+ const _lodash = require("lodash");
35
+ const _constants = require("./constants");
36
+ const _utils = require("./utils");
37
+ const _formatterCache = require("./formatterCache");
38
+ const CURRENCY_GROUP = 'Currency';
39
+ const CURRENCY_GROUP_CONFIG = {
40
+ label: 'Currency',
41
+ decimalPlaces: true
42
+ };
43
+ const CURRENCY_UNIT_CONFIG = {
44
+ aud: {
45
+ group: CURRENCY_GROUP,
46
+ label: 'Australian Dollar (A$)'
47
+ },
48
+ cad: {
49
+ group: CURRENCY_GROUP,
50
+ label: 'Canadian Dollar (CA$)'
51
+ },
52
+ chf: {
53
+ group: CURRENCY_GROUP,
54
+ label: 'Swiss Franc (CHF)'
55
+ },
56
+ cny: {
57
+ group: CURRENCY_GROUP,
58
+ label: 'Renminbi (CN¥)'
59
+ },
60
+ eur: {
61
+ group: CURRENCY_GROUP,
62
+ label: 'Euro (€)'
63
+ },
64
+ gbp: {
65
+ group: CURRENCY_GROUP,
66
+ label: 'Pound (£)'
67
+ },
68
+ hkd: {
69
+ group: CURRENCY_GROUP,
70
+ label: 'Hong Kong Dollar (HK$)'
71
+ },
72
+ inr: {
73
+ group: CURRENCY_GROUP,
74
+ label: 'Indian Rupee (₹)'
75
+ },
76
+ jpy: {
77
+ group: CURRENCY_GROUP,
78
+ label: 'Yen (¥)'
79
+ },
80
+ krw: {
81
+ group: CURRENCY_GROUP,
82
+ label: 'South Korean Won (₩)'
83
+ },
84
+ nok: {
85
+ group: CURRENCY_GROUP,
86
+ label: 'Norwegian Krone (NOK)'
87
+ },
88
+ nzd: {
89
+ group: CURRENCY_GROUP,
90
+ label: 'New Zealand Dollar (NZ$)'
91
+ },
92
+ sek: {
93
+ group: CURRENCY_GROUP,
94
+ label: 'Swedish Krona (SEK)'
95
+ },
96
+ sgd: {
97
+ group: CURRENCY_GROUP,
98
+ label: 'Singapore Dollar (S$)'
99
+ },
100
+ usd: {
101
+ group: CURRENCY_GROUP,
102
+ label: 'US Dollar ($)'
103
+ }
104
+ };
105
+ function formatCurrency(value, { unit, decimalPlaces }) {
106
+ const formatterOptions = {
107
+ style: 'currency',
108
+ currency: (0, _lodash.toUpper)(unit),
109
+ currencyDisplay: 'symbol'
110
+ };
111
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
112
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
113
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
114
+ } else {
115
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
116
+ }
117
+ const key = [
118
+ formatterOptions.style,
119
+ formatterOptions.currency,
120
+ formatterOptions.currencyDisplay,
121
+ formatterOptions.maximumSignificantDigits,
122
+ decimalPlaces,
123
+ unit
124
+ ];
125
+ return (0, _formatterCache.getFormatterFromCache)(key, 'currency', formatterOptions, 'en-US')(value);
126
+ }
@@ -0,0 +1,297 @@
1
+ // Copyright 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get DATE_GROUP_CONFIG () {
25
+ return DATE_GROUP_CONFIG;
26
+ },
27
+ get DATE_UNIT_CONFIG () {
28
+ return DATE_UNIT_CONFIG;
29
+ },
30
+ get formatDate () {
31
+ return formatDate;
32
+ }
33
+ });
34
+ const DATE_GROUP = 'Date';
35
+ const DATE_GROUP_CONFIG = {
36
+ label: 'Date & Time'
37
+ };
38
+ const DATE_UNIT_CONFIG = {
39
+ 'datetime-iso': {
40
+ group: DATE_GROUP,
41
+ label: 'DateTime (GMT)'
42
+ },
43
+ 'datetime-us': {
44
+ group: DATE_GROUP,
45
+ label: 'DateTime (US-East)'
46
+ },
47
+ 'datetime-local': {
48
+ group: DATE_GROUP,
49
+ label: 'DateTime (Browser Local)'
50
+ },
51
+ 'date-iso': {
52
+ group: DATE_GROUP,
53
+ label: 'Date (GMT)'
54
+ },
55
+ 'date-us': {
56
+ group: DATE_GROUP,
57
+ label: 'Date (US-East)'
58
+ },
59
+ 'date-local': {
60
+ group: DATE_GROUP,
61
+ label: 'Date (Browser Local)'
62
+ },
63
+ 'time-local': {
64
+ group: DATE_GROUP,
65
+ label: 'Time (Browser Local)'
66
+ },
67
+ 'time-iso': {
68
+ group: DATE_GROUP,
69
+ label: 'Time (GMT)'
70
+ },
71
+ 'time-us': {
72
+ group: DATE_GROUP,
73
+ label: 'Time (US-East)'
74
+ },
75
+ 'relative-time': {
76
+ group: DATE_GROUP,
77
+ label: 'Relative Time'
78
+ },
79
+ 'unix-timestamp': {
80
+ group: DATE_GROUP,
81
+ label: 'Unix Timestamp (s)'
82
+ },
83
+ 'unix-timestamp-ms': {
84
+ group: DATE_GROUP,
85
+ label: 'Unix Timestamp (ms)'
86
+ }
87
+ };
88
+ /**
89
+ * Converts a numeric value to a Date object.
90
+ * Handles both Unix timestamps (seconds) and millisecond timestamps.
91
+ */ function valueToDate(value) {
92
+ // Timestamp detection logic with special case handling
93
+ // Main threshold stays at 10 billion to maintain existing behavior
94
+ // Handle special edge cases explicitly
95
+ // Special case: negative timestamps
96
+ if (value < 0) {
97
+ // For negative values, check magnitude to distinguish seconds vs milliseconds
98
+ // Large negative values (> 1 billion in magnitude) are likely milliseconds
99
+ // Small negative values are likely seconds (rare edge case)
100
+ if (Math.abs(value) > 10000000000) {
101
+ return new Date(value); // milliseconds
102
+ } else {
103
+ return new Date(value * 1000); // seconds
104
+ }
105
+ }
106
+ // Special case: year 9999 in seconds (~253402300799)
107
+ // This is a very specific edge case for far-future timestamps
108
+ if (value >= 250000000000 && value <= 260000000000) {
109
+ // Check if this looks like year 9999 in seconds
110
+ const asSeconds = new Date(value * 1000);
111
+ const year = asSeconds.getUTCFullYear();
112
+ if (year >= 9999) {
113
+ return asSeconds; // seconds
114
+ }
115
+ }
116
+ const SECONDS_THRESHOLD = 10000000000; // ~year 2286 - original threshold
117
+ if (value < SECONDS_THRESHOLD) {
118
+ // Assume it's in seconds
119
+ return new Date(value * 1000);
120
+ } else {
121
+ // Assume it's in milliseconds
122
+ return new Date(value);
123
+ }
124
+ }
125
+ /**
126
+ * Formats a relative time string using the Intl.RelativeTimeFormat API.
127
+ */ function formatRelativeTime(date, referenceTime, locale) {
128
+ const referenceDate = new Date(referenceTime);
129
+ const diffMs = date.getTime() - referenceDate.getTime();
130
+ const units = [
131
+ {
132
+ unit: 'year',
133
+ ms: 1000 * 60 * 60 * 24 * 365
134
+ },
135
+ {
136
+ unit: 'month',
137
+ ms: 1000 * 60 * 60 * 24 * 30
138
+ },
139
+ {
140
+ unit: 'week',
141
+ ms: 1000 * 60 * 60 * 24 * 7
142
+ },
143
+ {
144
+ unit: 'day',
145
+ ms: 1000 * 60 * 60 * 24
146
+ },
147
+ {
148
+ unit: 'hour',
149
+ ms: 1000 * 60 * 60
150
+ },
151
+ {
152
+ unit: 'minute',
153
+ ms: 1000 * 60
154
+ },
155
+ {
156
+ unit: 'second',
157
+ ms: 1000
158
+ }
159
+ ];
160
+ for (const { unit, ms } of units){
161
+ // Determine the value for the current unit, ensuring it's an integer for Intl.RelativeTimeFormat
162
+ const value = Math.round(diffMs / ms);
163
+ // If the absolute value is 1 or more, use this unit
164
+ if (Math.abs(value) >= 1) {
165
+ const rtf = new Intl.RelativeTimeFormat(locale, {
166
+ numeric: 'auto'
167
+ });
168
+ return rtf.format(value, unit);
169
+ }
170
+ }
171
+ // If less than a second, show "now" or "0 seconds"
172
+ const rtf = new Intl.RelativeTimeFormat(locale, {
173
+ numeric: 'auto'
174
+ });
175
+ return rtf.format(0, 'second');
176
+ }
177
+ /**
178
+ * Gets the browser's preferred locale with comprehensive fallbacks.
179
+ */ const getBrowserLocale = ()=>{
180
+ if (typeof navigator !== 'undefined') {
181
+ if (navigator.language) return navigator.language;
182
+ if (navigator.languages && navigator.languages.length > 0) {
183
+ const firstLanguage = navigator.languages[0];
184
+ if (firstLanguage) return firstLanguage;
185
+ }
186
+ // Legacy fallbacks for older browsers
187
+ const nav = navigator;
188
+ if (nav.userLanguage) return nav.userLanguage;
189
+ if (nav.browserLanguage) return nav.browserLanguage;
190
+ if (nav.systemLanguage) return nav.systemLanguage;
191
+ }
192
+ // Node.js or server-side fallback, or if navigator is not available/empty
193
+ return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';
194
+ };
195
+ function formatDate(value, options = {}) {
196
+ const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
197
+ const { unit = 'datetime-local', locale = getBrowserLocale(), timeZone = systemTimeZone, referenceTime = Date.now() } = options;
198
+ // Handle raw timestamp display
199
+ if (unit === 'unix-timestamp') {
200
+ // Ensure it's in seconds. If it looks like milliseconds, convert.
201
+ const timestamp = value > 1000000000000 ? Math.floor(value / 1000) : value;
202
+ return timestamp.toString();
203
+ }
204
+ if (unit === 'unix-timestamp-ms') {
205
+ // Ensure it's in milliseconds. If it looks like seconds, convert.
206
+ // Use 100 billion as threshold - values < 100B are likely seconds, >= 100B are likely milliseconds
207
+ // This distinguishes between 999999999 (seconds) and 999999999000 (milliseconds)
208
+ const MILLISECONDS_THRESHOLD = 100000000000; // 100 billion
209
+ const timestamp = value < MILLISECONDS_THRESHOLD ? value * 1000 : value;
210
+ return Math.floor(timestamp).toString();
211
+ }
212
+ const date = valueToDate(value);
213
+ // Handle relative time
214
+ if (unit === 'relative-time') {
215
+ return formatRelativeTime(date, referenceTime, locale);
216
+ }
217
+ // Configure Intl.DateTimeFormat options based on unit
218
+ const formatOptions = {
219
+ timeZone
220
+ };
221
+ switch(unit){
222
+ case 'datetime-iso':
223
+ // datetime-iso should ALWAYS show GMT/UTC time
224
+ return date.toISOString();
225
+ case 'datetime-us':
226
+ {
227
+ // datetime-us should ALWAYS show date in US Eastern timezone
228
+ formatOptions.timeZone = 'America/New_York';
229
+ formatOptions.year = 'numeric';
230
+ formatOptions.month = '2-digit';
231
+ formatOptions.day = '2-digit';
232
+ formatOptions.hour = '2-digit';
233
+ formatOptions.minute = '2-digit';
234
+ formatOptions.second = '2-digit';
235
+ formatOptions.hour12 = true; // 12-hour format with AM/PM
236
+ const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
237
+ return formatter.format(date);
238
+ }
239
+ case 'datetime-local':
240
+ // datetime-local should use the browser's local timezone (detected automatically)
241
+ // Don't override timeZone - let it use the detected system timezone
242
+ formatOptions.year = 'numeric';
243
+ formatOptions.month = '2-digit';
244
+ formatOptions.day = '2-digit';
245
+ formatOptions.hour = '2-digit';
246
+ formatOptions.minute = '2-digit';
247
+ formatOptions.second = '2-digit';
248
+ formatOptions.hour12 = false; // 24-hour format
249
+ break;
250
+ case 'date-iso':
251
+ // date-iso should ALWAYS show GMT/UTC date
252
+ return date.toISOString().split('T')[0];
253
+ case 'date-us':
254
+ {
255
+ // date-us should ALWAYS show date in US Eastern timezone
256
+ formatOptions.timeZone = 'America/New_York';
257
+ formatOptions.year = 'numeric';
258
+ formatOptions.month = '2-digit';
259
+ formatOptions.day = '2-digit';
260
+ const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
261
+ return formatter.format(date);
262
+ }
263
+ case 'date-local':
264
+ formatOptions.year = 'numeric';
265
+ formatOptions.month = '2-digit';
266
+ formatOptions.day = '2-digit';
267
+ break;
268
+ case 'time-local':
269
+ formatOptions.hour = '2-digit';
270
+ formatOptions.minute = '2-digit';
271
+ formatOptions.second = '2-digit';
272
+ formatOptions.hour12 = false; // 24-hour format
273
+ break;
274
+ case 'time-iso':
275
+ // time-iso should ALWAYS show GMT/UTC time
276
+ return date.toISOString().split('T')[1].replace('Z', '');
277
+ case 'time-us':
278
+ {
279
+ // time-us should show time in US-East timezone (Eastern Time)
280
+ formatOptions.timeZone = 'America/New_York';
281
+ formatOptions.hour = '2-digit';
282
+ formatOptions.minute = '2-digit';
283
+ formatOptions.second = '2-digit';
284
+ formatOptions.hour12 = true;
285
+ return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
286
+ }
287
+ default:
288
+ {
289
+ // This ensures that all DateUnits are handled at compile time.
290
+ const exhaustive = unit;
291
+ throw new Error(`Unknown date unit: ${exhaustive}`);
292
+ }
293
+ }
294
+ // For all other units, use Intl.DateTimeFormat with the specified locale and options
295
+ const formatter = new Intl.DateTimeFormat(locale, formatOptions);
296
+ return formatter.format(date);
297
+ }