@perses-dev/core 0.53.0 → 0.54.0-beta.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 (135) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +3 -3
  2. package/dist/cjs/model/calculations.js +6 -6
  3. package/dist/cjs/model/definitions.js +1 -3
  4. package/dist/cjs/model/folder.js +16 -0
  5. package/dist/cjs/model/index.js +1 -0
  6. package/dist/cjs/model/legend.js +11 -11
  7. package/dist/cjs/model/otlp/index.js +4 -4
  8. package/dist/cjs/model/otlp/trace/v1/trace.js +4 -4
  9. package/dist/cjs/model/resource.js +3 -3
  10. package/dist/cjs/model/roles.js +4 -4
  11. package/dist/cjs/model/time.js +21 -309
  12. package/dist/cjs/model/units/bits.js +14 -6
  13. package/dist/cjs/model/units/bytes.js +16 -6
  14. package/dist/cjs/model/units/currency.js +14 -6
  15. package/dist/cjs/model/units/date.js +4 -4
  16. package/dist/cjs/model/units/decimal.js +13 -6
  17. package/dist/cjs/model/units/formatterCache.js +120 -0
  18. package/dist/cjs/model/units/percent.js +13 -6
  19. package/dist/cjs/model/units/temperature.js +13 -5
  20. package/dist/cjs/model/units/throughput.js +15 -6
  21. package/dist/cjs/model/units/time.js +15 -7
  22. package/dist/cjs/model/units/units.js +18 -18
  23. package/dist/cjs/model/units/utils.js +4 -4
  24. package/dist/cjs/model/variables.js +3 -3
  25. package/dist/cjs/schema/datasource.js +13 -29
  26. package/dist/cjs/schema/display.js +2 -6
  27. package/dist/cjs/schema/duration.js +2 -4
  28. package/dist/cjs/schema/metadata.js +4 -4
  29. package/dist/cjs/schema/panel.js +20 -72
  30. package/dist/cjs/schema/plugin.js +2 -6
  31. package/dist/cjs/schema/role.js +6 -6
  32. package/dist/cjs/schema/rolebinding.js +6 -6
  33. package/dist/cjs/schema/secret.js +5 -5
  34. package/dist/cjs/schema/user.js +5 -5
  35. package/dist/cjs/schema/variable.js +24 -137
  36. package/dist/cjs/utils/fetch.js +5 -5
  37. package/dist/cjs/utils/panel-refs.js +4 -4
  38. package/dist/cjs/utils/regexp.js +3 -3
  39. package/dist/cjs/utils/text.js +7 -7
  40. package/dist/cjs/utils/time-series-data.js +4 -4
  41. package/dist/cjs/utils/transform-data.js +6 -6
  42. package/dist/model/dashboard.d.ts +2 -21
  43. package/dist/model/dashboard.d.ts.map +1 -1
  44. package/dist/model/dashboard.js.map +1 -1
  45. package/dist/model/datasource.d.ts +3 -22
  46. package/dist/model/datasource.d.ts.map +1 -1
  47. package/dist/model/datasource.js +1 -3
  48. package/dist/model/datasource.js.map +1 -1
  49. package/dist/model/definitions.d.ts +1 -12
  50. package/dist/model/definitions.d.ts.map +1 -1
  51. package/dist/model/definitions.js +1 -6
  52. package/dist/model/definitions.js.map +1 -1
  53. package/dist/model/display.d.ts +1 -4
  54. package/dist/model/display.d.ts.map +1 -1
  55. package/dist/model/display.js.map +1 -1
  56. package/dist/model/folder.d.ts +19 -0
  57. package/dist/model/folder.d.ts.map +1 -0
  58. package/dist/model/folder.js +15 -0
  59. package/dist/model/folder.js.map +1 -0
  60. package/dist/model/index.d.ts +1 -0
  61. package/dist/model/index.d.ts.map +1 -1
  62. package/dist/model/index.js +1 -0
  63. package/dist/model/index.js.map +1 -1
  64. package/dist/model/project.d.ts +1 -1
  65. package/dist/model/project.d.ts.map +1 -1
  66. package/dist/model/project.js.map +1 -1
  67. package/dist/model/query.d.ts +1 -0
  68. package/dist/model/query.d.ts.map +1 -1
  69. package/dist/model/query.js.map +1 -1
  70. package/dist/model/resource.d.ts +1 -1
  71. package/dist/model/resource.d.ts.map +1 -1
  72. package/dist/model/resource.js.map +1 -1
  73. package/dist/model/time.d.ts +3 -54
  74. package/dist/model/time.d.ts.map +1 -1
  75. package/dist/model/time.js +2 -299
  76. package/dist/model/time.js.map +1 -1
  77. package/dist/model/units/bits.d.ts.map +1 -1
  78. package/dist/model/units/bits.js +10 -2
  79. package/dist/model/units/bits.js.map +1 -1
  80. package/dist/model/units/bytes.d.ts.map +1 -1
  81. package/dist/model/units/bytes.js +12 -2
  82. package/dist/model/units/bytes.js.map +1 -1
  83. package/dist/model/units/currency.d.ts.map +1 -1
  84. package/dist/model/units/currency.js +10 -2
  85. package/dist/model/units/currency.js.map +1 -1
  86. package/dist/model/units/decimal.d.ts.map +1 -1
  87. package/dist/model/units/decimal.js +9 -2
  88. package/dist/model/units/decimal.js.map +1 -1
  89. package/dist/model/units/formatterCache.d.ts +11 -0
  90. package/dist/model/units/formatterCache.d.ts.map +1 -0
  91. package/dist/model/units/formatterCache.js +104 -0
  92. package/dist/model/units/formatterCache.js.map +1 -0
  93. package/dist/model/units/percent.d.ts.map +1 -1
  94. package/dist/model/units/percent.js +9 -2
  95. package/dist/model/units/percent.js.map +1 -1
  96. package/dist/model/units/temperature.d.ts.map +1 -1
  97. package/dist/model/units/temperature.js +9 -1
  98. package/dist/model/units/temperature.js.map +1 -1
  99. package/dist/model/units/throughput.d.ts.map +1 -1
  100. package/dist/model/units/throughput.js +11 -2
  101. package/dist/model/units/throughput.js.map +1 -1
  102. package/dist/model/units/time.d.ts.map +1 -1
  103. package/dist/model/units/time.js +10 -2
  104. package/dist/model/units/time.js.map +1 -1
  105. package/dist/schema/datasource.d.ts +10 -9
  106. package/dist/schema/datasource.d.ts.map +1 -1
  107. package/dist/schema/datasource.js +2 -14
  108. package/dist/schema/datasource.js.map +1 -1
  109. package/dist/schema/display.d.ts +1 -11
  110. package/dist/schema/display.d.ts.map +1 -1
  111. package/dist/schema/display.js +1 -5
  112. package/dist/schema/display.js.map +1 -1
  113. package/dist/schema/duration.d.ts +1 -2
  114. package/dist/schema/duration.d.ts.map +1 -1
  115. package/dist/schema/duration.js +1 -3
  116. package/dist/schema/duration.js.map +1 -1
  117. package/dist/schema/panel.d.ts +1 -12
  118. package/dist/schema/panel.d.ts.map +1 -1
  119. package/dist/schema/panel.js +1 -53
  120. package/dist/schema/panel.js.map +1 -1
  121. package/dist/schema/plugin.d.ts +2 -13
  122. package/dist/schema/plugin.d.ts.map +1 -1
  123. package/dist/schema/plugin.js +1 -5
  124. package/dist/schema/plugin.js.map +1 -1
  125. package/dist/schema/role.d.ts +4 -4
  126. package/dist/schema/rolebinding.d.ts +4 -4
  127. package/dist/schema/secret.d.ts +70 -70
  128. package/dist/schema/variable.d.ts +1 -91
  129. package/dist/schema/variable.d.ts.map +1 -1
  130. package/dist/schema/variable.js +1 -105
  131. package/dist/schema/variable.js.map +1 -1
  132. package/dist/utils/fetch.js.map +1 -1
  133. package/dist/utils/text.js +4 -4
  134. package/dist/utils/text.js.map +1 -1
  135. package/package.json +3 -2
@@ -10,304 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { sub } from 'date-fns';
14
- const ONE_SECOND_IN_MS = 1000;
15
- const ONE_MINUTE_IN_MS = 60000;
16
- const ONE_HOUR_IN_MS = 3600000;
17
- const ONE_DAY_IN_MS = 86400000; // assuming a day has always 24h
18
- const ONE_WEEK_IN_MS = 604800000; // assuming a week has always 7d
19
- const ONE_YEAR_IN_MS = 31536000000; // assuming a year has always 365d
20
- /**
21
- * Determine whether a given time range is relative
22
- */ export function isRelativeTimeRange(timeRange) {
23
- return timeRange.pastDuration !== undefined;
24
- }
25
- /**
26
- * Determine whether a given time range is absolute
27
- */ export function isAbsoluteTimeRange(timeRange) {
28
- return timeRange.start !== undefined && timeRange.end !== undefined;
29
- }
30
- /**
31
- * Returns an absolute time range from a RelativeTimeRange.
32
- */ export function toAbsoluteTimeRange(timeRange) {
33
- const end = timeRange.end ?? new Date();
34
- return {
35
- start: sub(end, parseDurationString(timeRange.pastDuration)),
36
- end
37
- };
38
- }
39
- export const DURATION_REGEX = /^(?:(\d+)y)?(?:(\d+)w)?(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?(?:(\d+)ms)?$/;
40
- /**
41
- * Parses a DurationString into a Duration object with numeric values that can
42
- * be used to do Date math. Throws if not a valid duration string.
43
- */ export function parseDurationString(durationString) {
44
- const matches = DURATION_REGEX.exec(durationString);
45
- if (matches === null) {
46
- throw new Error(`Invalid duration string '${durationString}'`);
47
- }
48
- return {
49
- years: parseInt(matches[1] ?? '0'),
50
- months: 0,
51
- weeks: parseInt(matches[2] ?? '0'),
52
- days: parseInt(matches[3] ?? '0'),
53
- hours: parseInt(matches[4] ?? '0'),
54
- minutes: parseInt(matches[5] ?? '0'),
55
- seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000
56
- };
57
- }
58
- /**
59
- * Returns true if the given string is a valid DurationString.
60
- */ export function isDurationString(maybeDuration) {
61
- if (maybeDuration === '') return false;
62
- return DURATION_REGEX.test(maybeDuration);
63
- }
64
- export function intervalToPrometheusDuration(timeRange) {
65
- const durationInMs = timeRange.end.valueOf() - timeRange.start.valueOf();
66
- return msToPrometheusDuration(durationInMs);
67
- }
68
- export function msToPrometheusDuration(durationInMs) {
69
- const years = Math.trunc(durationInMs / ONE_YEAR_IN_MS);
70
- if (years > 0) durationInMs -= years * ONE_YEAR_IN_MS;
71
- const weeks = Math.trunc(durationInMs / ONE_WEEK_IN_MS);
72
- if (weeks > 0) durationInMs -= weeks * ONE_WEEK_IN_MS;
73
- const days = Math.trunc(durationInMs / ONE_DAY_IN_MS);
74
- if (days > 0) durationInMs -= days * ONE_DAY_IN_MS;
75
- const hours = Math.trunc(durationInMs / ONE_HOUR_IN_MS);
76
- if (hours > 0) durationInMs -= hours * ONE_HOUR_IN_MS;
77
- const minutes = Math.trunc(durationInMs / ONE_MINUTE_IN_MS);
78
- if (minutes > 0) durationInMs -= minutes * ONE_MINUTE_IN_MS;
79
- return {
80
- years: years,
81
- months: 0,
82
- weeks: weeks,
83
- days: days,
84
- hours: hours,
85
- minutes: minutes,
86
- seconds: durationInMs / 1000
87
- };
88
- }
89
- export function formatDuration(duration) {
90
- const result = [];
91
- if (duration.years) {
92
- result.push(`${duration.years}y`);
93
- }
94
- if (duration.weeks) {
95
- result.push(`${duration.weeks}w`);
96
- }
97
- if (duration.days) {
98
- result.push(`${duration.days}d`);
99
- }
100
- if (duration.hours) {
101
- result.push(`${duration.hours}h`);
102
- }
103
- if (duration.minutes) {
104
- result.push(`${duration.minutes}m`);
105
- }
106
- if (duration.seconds) {
107
- const seconds = Math.trunc(duration.seconds);
108
- if (seconds) {
109
- result.push(`${seconds}s`);
110
- }
111
- const ms = Math.round((duration.seconds - seconds) * 1000);
112
- if (ms) {
113
- result.push(`${ms}ms`);
114
- }
115
- }
116
- return result.join('');
117
- }
118
- const DEFAULT_STEP_MS = 15000;
119
- const ROUNDED_STEP_INTERVALS = [
120
- // max: 0.015s
121
- {
122
- maxMs: 15,
123
- roundedStepMs: 10,
124
- display: '0.01s'
125
- },
126
- // max: 0.035s
127
- {
128
- maxMs: 35,
129
- roundedStepMs: 20,
130
- display: '0.02s'
131
- },
132
- // max: 0.075s
133
- {
134
- maxMs: 75,
135
- roundedStepMs: 50,
136
- display: '0.05s'
137
- },
138
- // max: 0.15s
139
- {
140
- maxMs: 150,
141
- roundedStepMs: 100,
142
- display: '0.1s'
143
- },
144
- // max: 0.35s
145
- {
146
- maxMs: 350,
147
- roundedStepMs: 200,
148
- display: '0.2s'
149
- },
150
- // max: 0.75s
151
- {
152
- maxMs: 750,
153
- roundedStepMs: 500,
154
- display: '0.5s'
155
- },
156
- // max: 1.5s
157
- {
158
- maxMs: ONE_SECOND_IN_MS * 1.5,
159
- roundedStepMs: ONE_SECOND_IN_MS,
160
- display: '1s'
161
- },
162
- // max: 3.5s
163
- {
164
- maxMs: ONE_SECOND_IN_MS * 3.5,
165
- roundedStepMs: ONE_SECOND_IN_MS * 2,
166
- display: '2s'
167
- },
168
- // max: 7.5s
169
- {
170
- maxMs: ONE_SECOND_IN_MS * 7.5,
171
- roundedStepMs: ONE_SECOND_IN_MS * 5,
172
- display: '5s'
173
- },
174
- // max: 12.5s
175
- {
176
- maxMs: ONE_SECOND_IN_MS * 12.5,
177
- roundedStepMs: ONE_SECOND_IN_MS * 10,
178
- display: '10s'
179
- },
180
- // max: 17.5s
181
- {
182
- maxMs: ONE_SECOND_IN_MS * 17.5,
183
- roundedStepMs: ONE_SECOND_IN_MS * 15,
184
- display: '15s'
185
- },
186
- // max: 25s
187
- {
188
- maxMs: ONE_SECOND_IN_MS * 25,
189
- roundedStepMs: ONE_SECOND_IN_MS * 20,
190
- display: '20s'
191
- },
192
- // max: 45s
193
- {
194
- maxMs: ONE_SECOND_IN_MS * 45,
195
- roundedStepMs: ONE_SECOND_IN_MS * 30,
196
- display: '30s'
197
- },
198
- // max: 1.5m
199
- {
200
- maxMs: ONE_MINUTE_IN_MS * 1.5,
201
- roundedStepMs: ONE_MINUTE_IN_MS,
202
- display: '1m'
203
- },
204
- // max: 3.5m
205
- {
206
- maxMs: ONE_MINUTE_IN_MS * 3.5,
207
- roundedStepMs: ONE_MINUTE_IN_MS * 2,
208
- display: '2m'
209
- },
210
- // max: 7.5m
211
- {
212
- maxMs: ONE_MINUTE_IN_MS * 7.5,
213
- roundedStepMs: ONE_MINUTE_IN_MS * 5,
214
- display: '5m'
215
- },
216
- // max: 12.5m
217
- {
218
- maxMs: ONE_MINUTE_IN_MS * 12.5,
219
- roundedStepMs: ONE_MINUTE_IN_MS * 10,
220
- display: '10m'
221
- },
222
- // max: 12.5m
223
- {
224
- maxMs: ONE_MINUTE_IN_MS * 12.5,
225
- roundedStepMs: ONE_MINUTE_IN_MS * 15,
226
- display: '15m'
227
- },
228
- // max: 25m
229
- {
230
- maxMs: ONE_MINUTE_IN_MS * 25,
231
- roundedStepMs: ONE_MINUTE_IN_MS * 20,
232
- display: '20m'
233
- },
234
- // max: 45m
235
- {
236
- maxMs: ONE_MINUTE_IN_MS * 45,
237
- roundedStepMs: ONE_MINUTE_IN_MS * 30,
238
- display: '30m'
239
- },
240
- // max: 1.5h
241
- {
242
- maxMs: ONE_HOUR_IN_MS * 1.5,
243
- roundedStepMs: ONE_HOUR_IN_MS,
244
- display: '1h'
245
- },
246
- // max: 2.5h
247
- {
248
- maxMs: ONE_HOUR_IN_MS * 2.5,
249
- roundedStepMs: ONE_HOUR_IN_MS * 2,
250
- display: '2h'
251
- },
252
- // max: 4.5h
253
- {
254
- maxMs: ONE_HOUR_IN_MS * 4.5,
255
- roundedStepMs: ONE_HOUR_IN_MS * 3,
256
- display: '3h'
257
- },
258
- // max: 9h
259
- {
260
- maxMs: ONE_HOUR_IN_MS * 9,
261
- roundedStepMs: ONE_HOUR_IN_MS * 6,
262
- display: '6h'
263
- },
264
- // max: 1d
265
- {
266
- maxMs: ONE_DAY_IN_MS,
267
- roundedStepMs: ONE_HOUR_IN_MS * 12,
268
- display: '12h'
269
- },
270
- // max: 1w
271
- {
272
- maxMs: ONE_WEEK_IN_MS,
273
- roundedStepMs: ONE_DAY_IN_MS,
274
- display: '1d'
275
- },
276
- // max: 3w
277
- {
278
- maxMs: ONE_WEEK_IN_MS * 3,
279
- roundedStepMs: ONE_WEEK_IN_MS,
280
- display: '1w'
281
- },
282
- // max: 6w
283
- {
284
- maxMs: ONE_WEEK_IN_MS * 6,
285
- roundedStepMs: ONE_DAY_IN_MS * 30,
286
- display: '30d'
287
- },
288
- // max: 2y
289
- {
290
- maxMs: ONE_YEAR_IN_MS * 2,
291
- roundedStepMs: ONE_YEAR_IN_MS,
292
- display: '1y'
293
- }
294
- ];
295
- /**
296
- * Round interval to clearer increments
297
- */ export function roundStepInterval(stepMs) {
298
- for (const { maxMs, roundedStepMs } of ROUNDED_STEP_INTERVALS){
299
- if (stepMs < maxMs) {
300
- return roundedStepMs;
301
- }
302
- }
303
- return DEFAULT_STEP_MS;
304
- }
305
- /**
306
- * Gets a suggested step/interval size for a time range based on the width of a visual component.
307
- */ export function getSuggestedStepMs(timeRange, width) {
308
- const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();
309
- const stepMs = Math.floor(queryRangeMs / width);
310
- return roundStepInterval(stepMs);
311
- }
13
+ // 1. Runtime code like functions and consts
14
+ export { intervalToDuration as intervalToPrometheusDuration, formatDuration, parseDurationString, isRelativeTimeRange, isAbsoluteTimeRange, toAbsoluteTimeRange, roundStepInterval, getSuggestedStepMs, DURATION_REGEX } from '@perses-dev/spec';
312
15
 
313
16
  //# sourceMappingURL=time.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 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 { Duration, sub } from 'date-fns';\n\nconst ONE_SECOND_IN_MS = 1000;\nconst ONE_MINUTE_IN_MS = 60000;\nconst ONE_HOUR_IN_MS = 3600000;\nconst ONE_DAY_IN_MS = 86400000; // assuming a day has always 24h\nconst ONE_WEEK_IN_MS = 604800000; // assuming a week has always 7d\nconst ONE_YEAR_IN_MS = 31536000000; // assuming a year has always 365d\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nexport const DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\nexport function intervalToPrometheusDuration(timeRange: AbsoluteTimeRange): Duration {\n const durationInMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n return msToPrometheusDuration(durationInMs);\n}\n\nexport function msToPrometheusDuration(durationInMs: number): Duration {\n const years = Math.trunc(durationInMs / ONE_YEAR_IN_MS);\n if (years > 0) durationInMs -= years * ONE_YEAR_IN_MS;\n const weeks = Math.trunc(durationInMs / ONE_WEEK_IN_MS);\n if (weeks > 0) durationInMs -= weeks * ONE_WEEK_IN_MS;\n const days = Math.trunc(durationInMs / ONE_DAY_IN_MS);\n if (days > 0) durationInMs -= days * ONE_DAY_IN_MS;\n const hours = Math.trunc(durationInMs / ONE_HOUR_IN_MS);\n if (hours > 0) durationInMs -= hours * ONE_HOUR_IN_MS;\n const minutes = Math.trunc(durationInMs / ONE_MINUTE_IN_MS);\n if (minutes > 0) durationInMs -= minutes * ONE_MINUTE_IN_MS;\n\n return {\n years: years,\n months: 0,\n weeks: weeks,\n days: days,\n hours: hours,\n minutes: minutes,\n seconds: durationInMs / 1000,\n };\n}\n\nexport function formatDuration(duration: Duration): DurationString {\n const result: string[] = [];\n if (duration.years) {\n result.push(`${duration.years}y`);\n }\n if (duration.weeks) {\n result.push(`${duration.weeks}w`);\n }\n if (duration.days) {\n result.push(`${duration.days}d`);\n }\n if (duration.hours) {\n result.push(`${duration.hours}h`);\n }\n if (duration.minutes) {\n result.push(`${duration.minutes}m`);\n }\n if (duration.seconds) {\n const seconds = Math.trunc(duration.seconds);\n if (seconds) {\n result.push(`${seconds}s`);\n }\n const ms = Math.round((duration.seconds - seconds) * 1000);\n if (ms) {\n result.push(`${ms}ms`);\n }\n }\n return result.join('') as DurationString;\n}\n\nconst DEFAULT_STEP_MS = 15000;\n\nconst ROUNDED_STEP_INTERVALS = [\n // max: 0.015s\n { maxMs: 15, roundedStepMs: 10, display: '0.01s' },\n // max: 0.035s\n { maxMs: 35, roundedStepMs: 20, display: '0.02s' },\n // max: 0.075s\n { maxMs: 75, roundedStepMs: 50, display: '0.05s' },\n // max: 0.15s\n { maxMs: 150, roundedStepMs: 100, display: '0.1s' },\n // max: 0.35s\n { maxMs: 350, roundedStepMs: 200, display: '0.2s' },\n // max: 0.75s\n { maxMs: 750, roundedStepMs: 500, display: '0.5s' },\n // max: 1.5s\n { maxMs: ONE_SECOND_IN_MS * 1.5, roundedStepMs: ONE_SECOND_IN_MS, display: '1s' },\n // max: 3.5s\n { maxMs: ONE_SECOND_IN_MS * 3.5, roundedStepMs: ONE_SECOND_IN_MS * 2, display: '2s' },\n // max: 7.5s\n { maxMs: ONE_SECOND_IN_MS * 7.5, roundedStepMs: ONE_SECOND_IN_MS * 5, display: '5s' },\n // max: 12.5s\n { maxMs: ONE_SECOND_IN_MS * 12.5, roundedStepMs: ONE_SECOND_IN_MS * 10, display: '10s' },\n // max: 17.5s\n { maxMs: ONE_SECOND_IN_MS * 17.5, roundedStepMs: ONE_SECOND_IN_MS * 15, display: '15s' },\n // max: 25s\n { maxMs: ONE_SECOND_IN_MS * 25, roundedStepMs: ONE_SECOND_IN_MS * 20, display: '20s' },\n // max: 45s\n { maxMs: ONE_SECOND_IN_MS * 45, roundedStepMs: ONE_SECOND_IN_MS * 30, display: '30s' },\n // max: 1.5m\n { maxMs: ONE_MINUTE_IN_MS * 1.5, roundedStepMs: ONE_MINUTE_IN_MS, display: '1m' },\n // max: 3.5m\n { maxMs: ONE_MINUTE_IN_MS * 3.5, roundedStepMs: ONE_MINUTE_IN_MS * 2, display: '2m' },\n // max: 7.5m\n { maxMs: ONE_MINUTE_IN_MS * 7.5, roundedStepMs: ONE_MINUTE_IN_MS * 5, display: '5m' },\n // max: 12.5m\n { maxMs: ONE_MINUTE_IN_MS * 12.5, roundedStepMs: ONE_MINUTE_IN_MS * 10, display: '10m' },\n // max: 12.5m\n { maxMs: ONE_MINUTE_IN_MS * 12.5, roundedStepMs: ONE_MINUTE_IN_MS * 15, display: '15m' },\n // max: 25m\n { maxMs: ONE_MINUTE_IN_MS * 25, roundedStepMs: ONE_MINUTE_IN_MS * 20, display: '20m' },\n // max: 45m\n { maxMs: ONE_MINUTE_IN_MS * 45, roundedStepMs: ONE_MINUTE_IN_MS * 30, display: '30m' },\n // max: 1.5h\n { maxMs: ONE_HOUR_IN_MS * 1.5, roundedStepMs: ONE_HOUR_IN_MS, display: '1h' },\n // max: 2.5h\n { maxMs: ONE_HOUR_IN_MS * 2.5, roundedStepMs: ONE_HOUR_IN_MS * 2, display: '2h' },\n // max: 4.5h\n { maxMs: ONE_HOUR_IN_MS * 4.5, roundedStepMs: ONE_HOUR_IN_MS * 3, display: '3h' },\n // max: 9h\n { maxMs: ONE_HOUR_IN_MS * 9, roundedStepMs: ONE_HOUR_IN_MS * 6, display: '6h' },\n // max: 1d\n { maxMs: ONE_DAY_IN_MS, roundedStepMs: ONE_HOUR_IN_MS * 12, display: '12h' },\n // max: 1w\n { maxMs: ONE_WEEK_IN_MS, roundedStepMs: ONE_DAY_IN_MS, display: '1d' },\n // max: 3w\n { maxMs: ONE_WEEK_IN_MS * 3, roundedStepMs: ONE_WEEK_IN_MS, display: '1w' },\n // max: 6w\n { maxMs: ONE_WEEK_IN_MS * 6, roundedStepMs: ONE_DAY_IN_MS * 30, display: '30d' },\n // max: 2y\n { maxMs: ONE_YEAR_IN_MS * 2, roundedStepMs: ONE_YEAR_IN_MS, display: '1y' },\n];\n\n/**\n * Round interval to clearer increments\n */\nexport function roundStepInterval(stepMs: number): number {\n for (const { maxMs, roundedStepMs } of ROUNDED_STEP_INTERVALS) {\n if (stepMs < maxMs) {\n return roundedStepMs;\n }\n }\n return DEFAULT_STEP_MS;\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number): number {\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n const stepMs = Math.floor(queryRangeMs / width);\n return roundStepInterval(stepMs);\n}\n"],"names":["sub","ONE_SECOND_IN_MS","ONE_MINUTE_IN_MS","ONE_HOUR_IN_MS","ONE_DAY_IN_MS","ONE_WEEK_IN_MS","ONE_YEAR_IN_MS","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","intervalToPrometheusDuration","durationInMs","valueOf","msToPrometheusDuration","Math","trunc","formatDuration","duration","result","push","ms","round","join","DEFAULT_STEP_MS","ROUNDED_STEP_INTERVALS","maxMs","roundedStepMs","display","roundStepInterval","stepMs","getSuggestedStepMs","width","queryRangeMs","floor"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAmBA,GAAG,QAAQ,WAAW;AAEzC,MAAMC,mBAAmB;AACzB,MAAMC,mBAAmB;AACzB,MAAMC,iBAAiB;AACvB,MAAMC,gBAAgB,UAAU,gCAAgC;AAChE,MAAMC,iBAAiB,WAAW,gCAAgC;AAClE,MAAMC,iBAAiB,aAAa,kCAAkC;AAmBtE;;CAEC,GACD,OAAO,SAASC,oBAAoBC,SAAyB;IAC3D,OAAO,AAACA,UAAgCC,YAAY,KAAKC;AAC3D;AAEA;;CAEC,GACD,OAAO,SAASC,oBAAoBH,SAAyB;IAC3D,OAAO,AAACA,UAAgCI,KAAK,KAAKF,aAAa,AAACF,UAAgCK,GAAG,KAAKH;AAC1G;AAEA;;CAEC,GACD,OAAO,SAASI,oBAAoBN,SAA4B;IAC9D,MAAMK,MAAML,UAAUK,GAAG,IAAI,IAAIE;IAEjC,OAAO;QACLH,OAAOZ,IAAIa,KAAKG,oBAAoBR,UAAUC,YAAY;QAC1DI;IACF;AACF;AAiBA,OAAO,MAAMI,iBAAiB,mFAAmF;AAEjH;;;CAGC,GACD,OAAO,SAASD,oBAAoBE,cAAsB;IACxD,MAAMC,UAAUF,eAAeG,IAAI,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E,MAAMC,eAAe/C,UAAUK,GAAG,CAACsB,OAAO,KAAK3B,UAAUI,KAAK,CAACuB,OAAO;IACtE,MAAMiB,SAASf,KAAKmB,KAAK,CAACD,eAAeD;IACzC,OAAOH,kBAAkBC;AAC3B"}
1
+ {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 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// 1. Runtime code like functions and consts\nexport {\n intervalToDuration as intervalToPrometheusDuration, //It has been renamed in spec\n formatDuration,\n parseDurationString,\n isRelativeTimeRange,\n isAbsoluteTimeRange,\n toAbsoluteTimeRange,\n roundStepInterval,\n getSuggestedStepMs,\n DURATION_REGEX,\n} from '@perses-dev/spec';\n\n// 2. Types (Compile-time only)\nexport type {\n UnixTimeMs,\n DateTimeFormat,\n AbsoluteTimeRange,\n RelativeTimeRange,\n TimeRangeValue,\n DurationString,\n} from '@perses-dev/spec';\n"],"names":["intervalToDuration","intervalToPrometheusDuration","formatDuration","parseDurationString","isRelativeTimeRange","isAbsoluteTimeRange","toAbsoluteTimeRange","roundStepInterval","getSuggestedStepMs","DURATION_REGEX"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,4CAA4C;AAC5C,SACEA,sBAAsBC,4BAA4B,EAClDC,cAAc,EACdC,mBAAmB,EACnBC,mBAAmB,EACnBC,mBAAmB,EACnBC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,QACT,mBAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"bits.d.ts","sourceRoot":"","sources":["../../../src/model/units/bits.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAmBtD,KAAK,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAI/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CASnE,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAa,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAmDjH"}
1
+ {"version":3,"file":"bits.d.ts","sourceRoot":"","sources":["../../../src/model/units/bits.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBtD,KAAK,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAI/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CASnE,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAa,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CA4DjH"}
@@ -13,6 +13,7 @@
13
13
  import numbro from 'numbro';
14
14
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
15
  import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
16
+ import { getFormatterFromCache } from './formatterCache';
16
17
  /**
17
18
  * We support both SI (decimal) and IEC (binary) units for bits:
18
19
  *
@@ -59,8 +60,15 @@ export function formatBits(bits, { unit = 'bits', shortValues, decimalPlaces })
59
60
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
60
61
  }
61
62
  }
62
- const formatter = Intl.NumberFormat('en-US', formatterOptions);
63
- return formatter.format(bits) + ' bits';
63
+ const key = [
64
+ formatterOptions.style,
65
+ formatterOptions.useGrouping,
66
+ formatterOptions.maximumSignificantDigits,
67
+ decimalPlaces,
68
+ shortValues,
69
+ unit
70
+ ];
71
+ return `${getFormatterFromCache(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;
64
72
  }
65
73
  // If we're showing the shorten value, we use numbro.
66
74
  // numbro is able to add units like Kb, Mb, Gb, etc. correctly.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/bits.ts"],"sourcesContent":["// Copyright 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, shouldShortenValues } from './utils';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bits:\n *\n * SI/decimal (unit: 'decbits'):\n * 1 Kb = 1000 bits (1000^1 bits)\n * 1 Mb = 1,000,000 bits (1000^2 bits)\n * etc.\n *\n * IEC/binary (unit: 'bits'):\n * 1 Kib = 1024 bits (1024^1 bits)\n * 1 Mib = 1,048,576 bits (1024^2 bits)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BitsUnit = 'bits' | 'decbits';\n\nexport type BitsFormatOptions = {\n unit?: BitsUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\n\nexport const BITS_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bits',\n decimalPlaces: true,\n shortValues: true,\n};\n\nexport const BITS_UNIT_CONFIG: Readonly<Record<BitsUnit, UnitConfig>> = {\n bits: {\n group: 'Bits',\n label: 'Bits (IEC)',\n },\n decbits: {\n group: 'Bits',\n label: 'Bits (SI)',\n },\n};\n\nexport function formatBits(bits: number, { unit = 'bits', shortValues, decimalPlaces }: BitsFormatOptions): string {\n const isDecimal = unit === 'decbits';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bits) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(bits) + ' bits';\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like Kb, Mb, Gb, etc. correctly.\n const formatted = numbro(bits).format({\n output: 'byte', // numbro uses 'byte' output for bit formatting\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n\n // Replace byte units with bit units\n return formatted\n .replace(/KB/g, 'Kb')\n .replace(/MB/g, 'Mb')\n .replace(/GB/g, 'Gb')\n .replace(/TB/g, 'Tb')\n .replace(/PB/g, 'Pb')\n .replace(/EB/g, 'Eb')\n .replace(/KiB/g, 'Kib')\n .replace(/MiB/g, 'Mib')\n .replace(/GiB/g, 'Gib')\n .replace(/TiB/g, 'Tib')\n .replace(/PiB/g, 'Pib')\n .replace(/EiB/g, 'Eib');\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DEFAULT_NUMBRO_MANTISSA","BITS_GROUP_CONFIG","label","decimalPlaces","shortValues","BITS_UNIT_CONFIG","bits","group","decbits","formatBits","unit","isDecimal","threshold","Math","abs","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format","formatted","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa","replace"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAUhC,OAAO,MAAMC,oB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,OAAO,MACfA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ;AACrB"}
1
+ {"version":3,"sources":["../../../src/model/units/bits.ts"],"sourcesContent":["// Copyright 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, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bits:\n *\n * SI/decimal (unit: 'decbits'):\n * 1 Kb = 1000 bits (1000^1 bits)\n * 1 Mb = 1,000,000 bits (1000^2 bits)\n * etc.\n *\n * IEC/binary (unit: 'bits'):\n * 1 Kib = 1024 bits (1024^1 bits)\n * 1 Mib = 1,048,576 bits (1024^2 bits)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BitsUnit = 'bits' | 'decbits';\n\nexport type BitsFormatOptions = {\n unit?: BitsUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\n\nexport const BITS_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bits',\n decimalPlaces: true,\n shortValues: true,\n};\n\nexport const BITS_UNIT_CONFIG: Readonly<Record<BitsUnit, UnitConfig>> = {\n bits: {\n group: 'Bits',\n label: 'Bits (IEC)',\n },\n decbits: {\n group: 'Bits',\n label: 'Bits (SI)',\n },\n};\n\nexport function formatBits(bits: number, { unit = 'bits', shortValues, decimalPlaces }: BitsFormatOptions): string {\n const isDecimal = unit === 'decbits';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bits) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return `${getFormatterFromCache(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like Kb, Mb, Gb, etc. correctly.\n const formatted = numbro(bits).format({\n output: 'byte', // numbro uses 'byte' output for bit formatting\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n\n // Replace byte units with bit units\n return formatted\n .replace(/KB/g, 'Kb')\n .replace(/MB/g, 'Mb')\n .replace(/GB/g, 'Gb')\n .replace(/TB/g, 'Tb')\n .replace(/PB/g, 'Pb')\n .replace(/EB/g, 'Eb')\n .replace(/KiB/g, 'Kib')\n .replace(/MiB/g, 'Mib')\n .replace(/GiB/g, 'Gib')\n .replace(/TiB/g, 'Tib')\n .replace(/PiB/g, 'Pib')\n .replace(/EiB/g, 'Eib');\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","DEFAULT_NUMBRO_MANTISSA","BITS_GROUP_CONFIG","label","decimalPlaces","shortValues","BITS_UNIT_CONFIG","bits","group","decbits","formatBits","unit","isDecimal","threshold","Math","abs","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key","formatted","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa","replace"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAUhC,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AAEF,OAAO,MAAMC,mBAA2D;IACtEC,MAAM;QACJC,OAAO;QACPL,OAAO;IACT;IACAM,SAAS;QACPD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,WAAWH,IAAY,EAAE,EAAEI,OAAO,MAAM,EAAEN,WAAW,EAAED,aAAa,EAAqB;IACvG,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACb,oBAAoBM,gBAAgBS,KAAKC,GAAG,CAACR,QAAQM,WAAW;QACnE,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AS,CAAC;AAmBtD,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CASrE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAc,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAsCrH"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBtD,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CASrE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAc,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAiDrH"}
@@ -13,6 +13,7 @@
13
13
  import numbro from 'numbro';
14
14
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
15
  import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
16
+ import { getFormatterFromCache } from './formatterCache';
16
17
  /**
17
18
  * We support both SI (decimal) and IEC (binary) units for bytes:
18
19
  *
@@ -61,8 +62,17 @@ export function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces
61
62
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
62
63
  }
63
64
  }
64
- const formatter = Intl.NumberFormat('en-US', formatterOptions);
65
- return formatter.format(bytes);
65
+ const key = [
66
+ formatterOptions.style,
67
+ formatterOptions.unit,
68
+ formatterOptions.unitDisplay,
69
+ formatterOptions.useGrouping,
70
+ formatterOptions.maximumSignificantDigits,
71
+ decimalPlaces,
72
+ shortValues,
73
+ unit
74
+ ];
75
+ return getFormatterFromCache(key, 'bytes', formatterOptions, 'en-US')(bytes);
66
76
  }
67
77
  // If we're showing the shorten value, we use numbro.
68
78
  // numbro is able to add units like KB, MB, GB, etc. correctly.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 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, shouldShortenValues } from './utils';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bytes:\n *\n * SI/decimal (unit: 'decbytes'):\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n *\n * IEC/binary (unit: 'bytes'):\n * 1 KiB = 1024 bytes (1024^1 bytes)\n * 1 MiB = 1,048,576 bytes (1024^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BytesUnit = 'bytes' | 'decbytes';\n\nexport type BytesFormatOptions = {\n unit?: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes (IEC)',\n },\n decbytes: {\n group: 'Bytes',\n label: 'Bytes (SI)',\n },\n};\n\nexport function formatBytes(bytes: number, { unit = 'bytes', shortValues, decimalPlaces }: BytesFormatOptions): string {\n const isDecimal = unit === 'decbytes';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(bytes);\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like KB, MB, GB, etc. correctly.\n return numbro(bytes).format({\n output: 'byte',\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DEFAULT_NUMBRO_MANTISSA","BYTES_GROUP_CONFIG","label","decimalPlaces","shortValues","BYTES_UNIT_CONFIG","bytes","group","decbytes","formatBytes","unit","isDecimal","threshold","Math","abs","formatterOptions","style","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAShC,OAAO,MAAMC,qBAAsC;IACjDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,oBAA6D;IACxEC,OAAO;QACLC,OAAO;QACPL,OAAO;IACT;IACAM,UAAU;QACRD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,YAAYH,KAAa,EAAE,EAAEI,OAAO,OAAO,EAAEN,WAAW,EAAED,aAAa,EAAsB;IAC3G,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACZ,oBAAoBK,gBAAgBS,KAAKC,GAAG,CAACR,SAASM,WAAW;QACpE,MAAMG,mBAA6C;YACjDC,OAAO;YACPN,MAAM;YACNO,aAAa;YACbC,aAAa;QACf;QAEA,IAAIrB,iBAAiBM,gBAAgB;YACnCY,iBAAiBI,qBAAqB,GAAGrB,mBAAmBK;YAC5DY,iBAAiBK,qBAAqB,GAAGtB,mBAAmBK;QAC9D,OAAO;YACL,2FAA2F;YAC3F,IAAIJ,oBAAoBK,cAAc;gBACpCW,iBAAiBM,wBAAwB,GAAGzB;YAC9C;QACF;QACA,MAAM0B,YAAYC,KAAKC,YAAY,CAAC,SAAST;QAC7C,OAAOO,UAAUG,MAAM,CAACnB;IAC1B;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,OAAOX,OAAOW,OAAOmB,MAAM,CAAC;QAC1BC,QAAQ;QACRC,MAAMhB,YAAY,YAAY;QAC9BiB,gBAAgB;QAChBC,UAAUhC,iBAAiBM,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC8B,cAAc,CAACjC,iBAAiBM;QAChC,wEAAwE;QACxE4B,kBAAkB,CAAClC,iBAAiBM;IACtC;AACF"}
1
+ {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 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, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bytes:\n *\n * SI/decimal (unit: 'decbytes'):\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n *\n * IEC/binary (unit: 'bytes'):\n * 1 KiB = 1024 bytes (1024^1 bytes)\n * 1 MiB = 1,048,576 bytes (1024^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BytesUnit = 'bytes' | 'decbytes';\n\nexport type BytesFormatOptions = {\n unit?: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes (IEC)',\n },\n decbytes: {\n group: 'Bytes',\n label: 'Bytes (SI)',\n },\n};\n\nexport function formatBytes(bytes: number, { unit = 'bytes', shortValues, decimalPlaces }: BytesFormatOptions): string {\n const isDecimal = unit === 'decbytes';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.unit,\n formatterOptions.unitDisplay,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return getFormatterFromCache(key, 'bytes', formatterOptions, 'en-US')(bytes);\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like KB, MB, GB, etc. correctly.\n return numbro(bytes).format({\n output: 'byte',\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","DEFAULT_NUMBRO_MANTISSA","BYTES_GROUP_CONFIG","label","decimalPlaces","shortValues","BYTES_UNIT_CONFIG","bytes","group","decbytes","formatBytes","unit","isDecimal","threshold","Math","abs","formatterOptions","style","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAShC,OAAO,MAAMC,qBAAsC;IACjDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,oBAA6D;IACxEC,OAAO;QACLC,OAAO;QACPL,OAAO;IACT;IACAM,UAAU;QACRD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,YAAYH,KAAa,EAAE,EAAEI,OAAO,OAAO,EAAEN,WAAW,EAAED,aAAa,EAAsB;IAC3G,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACb,oBAAoBM,gBAAgBS,KAAKC,GAAG,CAACR,SAASM,WAAW;QACpE,MAAMG,mBAA6C;YACjDC,OAAO;YACPN,MAAM;YACNO,aAAa;YACbC,aAAa;QACf;QAEA,IAAItB,iBAAiBO,gBAAgB;YACnCY,iBAAiBI,qBAAqB,GAAGtB,mBAAmBM;YAC5DY,iBAAiBK,qBAAqB,GAAGvB,mBAAmBM;QAC9D,OAAO;YACL,2FAA2F;YAC3F,IAAIL,oBAAoBM,cAAc;gBACpCW,iBAAiBM,wBAAwB,GAAG1B;YAC9C;QACF;QAEA,MAAM2B,MAAM;YACVP,iBAAiBC,KAAK;YACtBD,iBAAiBL,IAAI;YACrBK,iBAAiBE,WAAW;YAC5BF,iBAAiBG,WAAW;YAC5BH,iBAAiBM,wBAAwB;YACzClB;YACAC;YACAM;SACD;QAED,OAAOX,sBAAsBuB,KAAK,SAASP,kBAAkB,SAAST;IACxE;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,OAAOZ,OAAOY,OAAOiB,MAAM,CAAC;QAC1BC,QAAQ;QACRC,MAAMd,YAAY,YAAY;QAC9Be,gBAAgB;QAChBC,UAAU/B,iBAAiBO,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC4B,cAAc,CAAChC,iBAAiBO;QAChC,wEAAwE;QACxE0B,kBAAkB,CAACjC,iBAAiBO;IACtC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/model/units/currency.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAKtD,KAAK,aAAa,GACd,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AACV,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAGF,eAAO,MAAM,qBAAqB,EAAE,eAGnC,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CA6D5E,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,qBAAqB,GAAG,MAAM,CAgBpG"}
1
+ {"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/model/units/currency.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAMtD,KAAK,aAAa,GACd,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AACV,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAGF,eAAO,MAAM,qBAAqB,EAAE,eAGnC,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CA6D5E,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,qBAAqB,GAAG,MAAM,CAwBpG"}
@@ -13,6 +13,7 @@
13
13
  import { toUpper } from 'lodash';
14
14
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
15
  import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
16
+ import { getFormatterFromCache } from './formatterCache';
16
17
  const CURRENCY_GROUP = 'Currency';
17
18
  export const CURRENCY_GROUP_CONFIG = {
18
19
  label: 'Currency',
@@ -92,8 +93,15 @@ export function formatCurrency(value, { unit, decimalPlaces }) {
92
93
  } else {
93
94
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
94
95
  }
95
- const formatter = Intl.NumberFormat('en-US', formatterOptions);
96
- return formatter.format(value);
96
+ const key = [
97
+ formatterOptions.style,
98
+ formatterOptions.currency,
99
+ formatterOptions.currencyDisplay,
100
+ formatterOptions.maximumSignificantDigits,
101
+ decimalPlaces,
102
+ unit
103
+ ];
104
+ return getFormatterFromCache(key, 'currency', formatterOptions, 'en-US')(value);
97
105
  }
98
106
 
99
107
  //# sourceMappingURL=currency.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/currency.ts"],"sourcesContent":["// Copyright 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 { toUpper } from 'lodash';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\n// See Intl.supportedValuesOf(\"currency\") for valid options, key names will\n// be converted to uppercase to match the expectation of Intl.NumberFormat\ntype CurrencyUnits =\n | 'aud'\n | 'cad'\n | 'chf'\n | 'cny'\n | 'eur'\n | 'gbp'\n | 'hkd'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'nok'\n | 'nzd'\n | 'sek'\n | 'sgd'\n | 'usd';\nexport type CurrencyFormatOptions = {\n unit: CurrencyUnits;\n decimalPlaces?: number;\n};\n\nconst CURRENCY_GROUP = 'Currency';\nexport const CURRENCY_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Currency',\n decimalPlaces: true,\n};\nexport const CURRENCY_UNIT_CONFIG: Readonly<Record<CurrencyUnits, UnitConfig>> = {\n aud: {\n group: CURRENCY_GROUP,\n label: 'Australian Dollar (A$)',\n },\n cad: {\n group: CURRENCY_GROUP,\n label: 'Canadian Dollar (CA$)',\n },\n chf: {\n group: CURRENCY_GROUP,\n label: 'Swiss Franc (CHF)',\n },\n cny: {\n group: CURRENCY_GROUP,\n label: 'Renminbi (CN¥)',\n },\n eur: {\n group: CURRENCY_GROUP,\n label: 'Euro (€)',\n },\n gbp: {\n group: CURRENCY_GROUP,\n label: 'Pound (£)',\n },\n hkd: {\n group: CURRENCY_GROUP,\n label: 'Hong Kong Dollar (HK$)',\n },\n inr: {\n group: CURRENCY_GROUP,\n label: 'Indian Rupee (₹)',\n },\n jpy: {\n group: CURRENCY_GROUP,\n label: 'Yen (¥)',\n },\n krw: {\n group: CURRENCY_GROUP,\n label: 'South Korean Won (₩)',\n },\n nok: {\n group: CURRENCY_GROUP,\n label: 'Norwegian Krone (NOK)',\n },\n nzd: {\n group: CURRENCY_GROUP,\n label: 'New Zealand Dollar (NZ$)',\n },\n sek: {\n group: CURRENCY_GROUP,\n label: 'Swedish Krona (SEK)',\n },\n sgd: {\n group: CURRENCY_GROUP,\n label: 'Singapore Dollar (S$)',\n },\n usd: {\n group: CURRENCY_GROUP,\n label: 'US Dollar ($)',\n },\n};\n\nexport function formatCurrency(value: number, { unit, decimalPlaces }: CurrencyFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'currency',\n currency: toUpper(unit),\n currencyDisplay: 'symbol',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["toUpper","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","CURRENCY_GROUP","CURRENCY_GROUP_CONFIG","label","decimalPlaces","CURRENCY_UNIT_CONFIG","aud","group","cad","chf","cny","eur","gbp","hkd","inr","jpy","krw","nok","nzd","sek","sgd","usd","formatCurrency","value","unit","formatterOptions","style","currency","currencyDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,QAAQ,SAAS;AACjC,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAyB/D,MAAMC,iBAAiB;AACvB,OAAO,MAAMC,wBAAyC;IACpDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,OAAO,MAAMC,uBAAoE;IAC/EC,KAAK;QACHC,OAAON;QACPE,OAAO;IACT;IACAK,KAAK;QACHD,OAAON;QACPE,OAAO;IACT;IACAM,KAAK;QACHF,OAAON;QACPE,OAAO;IACT;IACAO,KAAK;QACHH,OAAON;QACPE,OAAO;IACT;IACAQ,KAAK;QACHJ,OAAON;QACPE,OAAO;IACT;IACAS,KAAK;QACHL,OAAON;QACPE,OAAO;IACT;IACAU,KAAK;QACHN,OAAON;QACPE,OAAO;IACT;IACAW,KAAK;QACHP,OAAON;QACPE,OAAO;IACT;IACAY,KAAK;QACHR,OAAON;QACPE,OAAO;IACT;IACAa,KAAK;QACHT,OAAON;QACPE,OAAO;IACT;IACAc,KAAK;QACHV,OAAON;QACPE,OAAO;IACT;IACAe,KAAK;QACHX,OAAON;QACPE,OAAO;IACT;IACAgB,KAAK;QACHZ,OAAON;QACPE,OAAO;IACT;IACAiB,KAAK;QACHb,OAAON;QACPE,OAAO;IACT;IACAkB,KAAK;QACHd,OAAON;QACPE,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASmB,eAAeC,KAAa,EAAE,EAAEC,IAAI,EAAEpB,aAAa,EAAyB;IAC1F,MAAMqB,mBAA6C;QACjDC,OAAO;QACPC,UAAU9B,QAAQ2B;QAClBI,iBAAiB;IACnB;IAEA,IAAI7B,iBAAiBK,gBAAgB;QACnCqB,iBAAiBI,qBAAqB,GAAG7B,mBAAmBI;QAC5DqB,iBAAiBK,qBAAqB,GAAG9B,mBAAmBI;IAC9D,OAAO;QACLqB,iBAAiBM,wBAAwB,GAAGjC;IAC9C;IAEA,MAAMkC,YAAYC,KAAKC,YAAY,CAAC,SAAST;IAC7C,OAAOO,UAAUG,MAAM,CAACZ;AAC1B"}
1
+ {"version":3,"sources":["../../../src/model/units/currency.ts"],"sourcesContent":["// Copyright 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 { toUpper } from 'lodash';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n// See Intl.supportedValuesOf(\"currency\") for valid options, key names will\n// be converted to uppercase to match the expectation of Intl.NumberFormat\ntype CurrencyUnits =\n | 'aud'\n | 'cad'\n | 'chf'\n | 'cny'\n | 'eur'\n | 'gbp'\n | 'hkd'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'nok'\n | 'nzd'\n | 'sek'\n | 'sgd'\n | 'usd';\nexport type CurrencyFormatOptions = {\n unit: CurrencyUnits;\n decimalPlaces?: number;\n};\n\nconst CURRENCY_GROUP = 'Currency';\nexport const CURRENCY_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Currency',\n decimalPlaces: true,\n};\nexport const CURRENCY_UNIT_CONFIG: Readonly<Record<CurrencyUnits, UnitConfig>> = {\n aud: {\n group: CURRENCY_GROUP,\n label: 'Australian Dollar (A$)',\n },\n cad: {\n group: CURRENCY_GROUP,\n label: 'Canadian Dollar (CA$)',\n },\n chf: {\n group: CURRENCY_GROUP,\n label: 'Swiss Franc (CHF)',\n },\n cny: {\n group: CURRENCY_GROUP,\n label: 'Renminbi (CN¥)',\n },\n eur: {\n group: CURRENCY_GROUP,\n label: 'Euro (€)',\n },\n gbp: {\n group: CURRENCY_GROUP,\n label: 'Pound (£)',\n },\n hkd: {\n group: CURRENCY_GROUP,\n label: 'Hong Kong Dollar (HK$)',\n },\n inr: {\n group: CURRENCY_GROUP,\n label: 'Indian Rupee (₹)',\n },\n jpy: {\n group: CURRENCY_GROUP,\n label: 'Yen (¥)',\n },\n krw: {\n group: CURRENCY_GROUP,\n label: 'South Korean Won (₩)',\n },\n nok: {\n group: CURRENCY_GROUP,\n label: 'Norwegian Krone (NOK)',\n },\n nzd: {\n group: CURRENCY_GROUP,\n label: 'New Zealand Dollar (NZ$)',\n },\n sek: {\n group: CURRENCY_GROUP,\n label: 'Swedish Krona (SEK)',\n },\n sgd: {\n group: CURRENCY_GROUP,\n label: 'Singapore Dollar (S$)',\n },\n usd: {\n group: CURRENCY_GROUP,\n label: 'US Dollar ($)',\n },\n};\n\nexport function formatCurrency(value: number, { unit, decimalPlaces }: CurrencyFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'currency',\n currency: toUpper(unit),\n currencyDisplay: 'symbol',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.currency,\n formatterOptions.currencyDisplay,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n unit,\n ];\n\n return getFormatterFromCache(key, 'currency', formatterOptions, 'en-US')(value);\n}\n"],"names":["toUpper","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","getFormatterFromCache","CURRENCY_GROUP","CURRENCY_GROUP_CONFIG","label","decimalPlaces","CURRENCY_UNIT_CONFIG","aud","group","cad","chf","cny","eur","gbp","hkd","inr","jpy","krw","nok","nzd","sek","sgd","usd","formatCurrency","value","unit","formatterOptions","style","currency","currencyDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,QAAQ,SAAS;AACjC,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAC/D,SAASC,qBAAqB,QAAQ,mBAAmB;AAyBzD,MAAMC,iBAAiB;AACvB,OAAO,MAAMC,wBAAyC;IACpDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,OAAO,MAAMC,uBAAoE;IAC/EC,KAAK;QACHC,OAAON;QACPE,OAAO;IACT;IACAK,KAAK;QACHD,OAAON;QACPE,OAAO;IACT;IACAM,KAAK;QACHF,OAAON;QACPE,OAAO;IACT;IACAO,KAAK;QACHH,OAAON;QACPE,OAAO;IACT;IACAQ,KAAK;QACHJ,OAAON;QACPE,OAAO;IACT;IACAS,KAAK;QACHL,OAAON;QACPE,OAAO;IACT;IACAU,KAAK;QACHN,OAAON;QACPE,OAAO;IACT;IACAW,KAAK;QACHP,OAAON;QACPE,OAAO;IACT;IACAY,KAAK;QACHR,OAAON;QACPE,OAAO;IACT;IACAa,KAAK;QACHT,OAAON;QACPE,OAAO;IACT;IACAc,KAAK;QACHV,OAAON;QACPE,OAAO;IACT;IACAe,KAAK;QACHX,OAAON;QACPE,OAAO;IACT;IACAgB,KAAK;QACHZ,OAAON;QACPE,OAAO;IACT;IACAiB,KAAK;QACHb,OAAON;QACPE,OAAO;IACT;IACAkB,KAAK;QACHd,OAAON;QACPE,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASmB,eAAeC,KAAa,EAAE,EAAEC,IAAI,EAAEpB,aAAa,EAAyB;IAC1F,MAAMqB,mBAA6C;QACjDC,OAAO;QACPC,UAAU/B,QAAQ4B;QAClBI,iBAAiB;IACnB;IAEA,IAAI9B,iBAAiBM,gBAAgB;QACnCqB,iBAAiBI,qBAAqB,GAAG9B,mBAAmBK;QAC5DqB,iBAAiBK,qBAAqB,GAAG/B,mBAAmBK;IAC9D,OAAO;QACLqB,iBAAiBM,wBAAwB,GAAGlC;IAC9C;IAEA,MAAMmC,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,QAAQ;QACzBF,iBAAiBG,eAAe;QAChCH,iBAAiBM,wBAAwB;QACzC3B;QACAoB;KACD;IAED,OAAOxB,sBAAsBgC,KAAK,YAAYP,kBAAkB,SAASF;AAC3E"}
@@ -1 +1 @@
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,KAAK,WAAW,GAAG,SAAS,CAAC;AAC7B,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CAqBzG"}
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,WAAW,GAAG,SAAS,CAAC;AAC7B,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CA4BzG"}
@@ -11,6 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
+ import { getFormatterFromCache } from './formatterCache';
14
15
  import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
15
16
  export const DECIMAL_GROUP_CONFIG = {
16
17
  label: 'Decimal',
@@ -39,8 +40,14 @@ export function formatDecimal(value, { shortValues, decimalPlaces }) {
39
40
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
40
41
  }
41
42
  }
42
- const formatter = Intl.NumberFormat('en-US', formatterOptions);
43
- return formatter.format(value);
43
+ const key = [
44
+ formatterOptions.style,
45
+ formatterOptions.useGrouping,
46
+ formatterOptions.notation,
47
+ formatterOptions.maximumSignificantDigits,
48
+ decimalPlaces
49
+ ];
50
+ return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);
44
51
  }
45
52
 
46
53
  //# sourceMappingURL=decimal.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 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, shouldShortenValues } from './utils';\n\ntype DecimalUnit = 'decimal';\nexport type DecimalFormatOptions = {\n unit?: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,+BAA+B;AAC/B,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,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAQpF,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,WAAW,EAAED,aAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIZ,oBAAoBI,cAAc;QACpCM,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIf,iBAAiBK,gBAAgB;QACnCO,iBAAiBI,qBAAqB,GAAGf,mBAAmBI;QAC5DO,iBAAiBK,qBAAqB,GAAGhB,mBAAmBI;IAC9D,OAAO;QACL,IAAIH,oBAAoBI,cAAc;YACpCM,iBAAiBM,wBAAwB,GAAGnB;QAC9C;IACF;IAEA,MAAMoB,YAAYC,KAAKC,YAAY,CAAC,SAAST;IAC7C,OAAOO,UAAUG,MAAM,CAACX;AAC1B"}
1
+ {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 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 { getFormatterFromCache } from './formatterCache';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype DecimalUnit = 'decimal';\nexport type DecimalFormatOptions = {\n unit?: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.notation,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n ];\n\n return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,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,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAQpF,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,WAAW,EAAED,aAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIZ,oBAAoBI,cAAc;QACpCM,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIf,iBAAiBK,gBAAgB;QACnCO,iBAAiBI,qBAAqB,GAAGf,mBAAmBI;QAC5DO,iBAAiBK,qBAAqB,GAAGhB,mBAAmBI;IAC9D,OAAO;QACL,IAAIH,oBAAoBI,cAAc;YACpCM,iBAAiBM,wBAAwB,GAAGpB;QAC9C;IACF;IAEA,MAAMqB,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,WAAW;QAC5BF,iBAAiBG,QAAQ;QACzBH,iBAAiBM,wBAAwB;QACzCb;KACD;IAED,OAAON,sBAAsBoB,KAAK,WAAWP,kBAAkB,SAASD;AAC1E"}
@@ -0,0 +1,11 @@
1
+ type FormatFn = (value: number | bigint) => string;
2
+ type InputType = 'time' | 'temperature' | 'bytes' | 'bits' | 'decimal' | 'currency' | 'percent' | 'throughput';
3
+ type Locals = 'en-US' | 'en-GB';
4
+ export declare function getFormatterFromCache(key: Array<string | number | boolean | undefined>, inputType: InputType, formatterOptions: Intl.NumberFormatOptions, locals?: Locals): FormatFn;
5
+ export interface IFormatterStats {
6
+ countCacheItems: (inputType: InputType | 'all') => number;
7
+ getKeys: (inputType: InputType) => string[];
8
+ }
9
+ export declare const getFormatterStats: () => IFormatterStats;
10
+ export {};
11
+ //# sourceMappingURL=formatterCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatterCache.d.ts","sourceRoot":"","sources":["../../../src/model/units/formatterCache.ts"],"names":[],"mappings":"AAaA,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AACnD,KAAK,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,CAAC;AAC/G,KAAK,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAqChC,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EACjD,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,IAAI,CAAC,mBAAmB,EAC1C,MAAM,GAAE,MAAgB,GACvB,QAAQ,CAcV;AAGD,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,KAAK,KAAK,MAAM,CAAC;IAC1D,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,MAAM,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,iBAAiB,QAAO,eAcpC,CAAC"}