@perses-dev/core 0.39.0 → 0.40.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 (119) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +6 -2
  2. package/dist/cjs/constants/dialog.js +3 -1
  3. package/dist/cjs/constants/index.js +11 -9
  4. package/dist/cjs/index.js +12 -10
  5. package/dist/cjs/model/calculations.js +61 -49
  6. package/dist/cjs/model/index.js +28 -26
  7. package/dist/cjs/model/legend.js +39 -19
  8. package/dist/cjs/model/resource.js +9 -0
  9. package/dist/cjs/model/time-series-queries.js +3 -1
  10. package/dist/cjs/model/time.js +147 -64
  11. package/dist/cjs/model/units/bytes.js +26 -20
  12. package/dist/cjs/model/units/constants.js +3 -1
  13. package/dist/cjs/model/units/decimal.js +20 -14
  14. package/dist/cjs/model/units/index.js +13 -11
  15. package/dist/cjs/model/units/percent.js +21 -15
  16. package/dist/cjs/model/units/time.js +68 -60
  17. package/dist/cjs/model/units/types.js +3 -1
  18. package/dist/cjs/model/units/units.js +67 -43
  19. package/dist/cjs/model/units/utils.js +13 -7
  20. package/dist/cjs/model/variables.js +16 -3
  21. package/dist/cjs/utils/event.js +3 -1
  22. package/dist/cjs/utils/fetch.js +12 -4
  23. package/dist/cjs/utils/index.js +17 -14
  24. package/dist/cjs/utils/is-empty-object.js +3 -1
  25. package/dist/cjs/utils/mathjs.js +3 -1
  26. package/dist/cjs/utils/memo.js +10 -6
  27. package/dist/cjs/utils/panel-refs.js +9 -3
  28. package/dist/cjs/utils/text.js +33 -21
  29. package/dist/cjs/utils/time-series-data.js +21 -11
  30. package/dist/cjs/utils/types.js +16 -0
  31. package/dist/constants/dashboard-defaults.js.map +1 -1
  32. package/dist/constants/dialog.js.map +1 -1
  33. package/dist/constants/index.js.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/model/calculations.d.ts +9 -8
  36. package/dist/model/calculations.d.ts.map +1 -1
  37. package/dist/model/calculations.js +46 -45
  38. package/dist/model/calculations.js.map +1 -1
  39. package/dist/model/datasource.d.ts +19 -3
  40. package/dist/model/datasource.d.ts.map +1 -1
  41. package/dist/model/datasource.js.map +1 -1
  42. package/dist/model/display.d.ts +1 -1
  43. package/dist/model/display.d.ts.map +1 -1
  44. package/dist/model/display.js.map +1 -1
  45. package/dist/model/index.js.map +1 -1
  46. package/dist/model/legend.d.ts +6 -6
  47. package/dist/model/legend.js +9 -9
  48. package/dist/model/legend.js.map +1 -1
  49. package/dist/model/panels.d.ts +5 -2
  50. package/dist/model/panels.d.ts.map +1 -1
  51. package/dist/model/panels.js.map +1 -1
  52. package/dist/model/resource.d.ts +3 -2
  53. package/dist/model/resource.d.ts.map +1 -1
  54. package/dist/model/resource.js +3 -1
  55. package/dist/model/resource.js.map +1 -1
  56. package/dist/model/thresholds.d.ts +2 -2
  57. package/dist/model/thresholds.d.ts.map +1 -1
  58. package/dist/model/thresholds.js.map +1 -1
  59. package/dist/model/time-series-queries.js.map +1 -1
  60. package/dist/model/time.d.ts +3 -0
  61. package/dist/model/time.d.ts.map +1 -1
  62. package/dist/model/time.js +115 -55
  63. package/dist/model/time.js.map +1 -1
  64. package/dist/model/units/bytes.d.ts +8 -8
  65. package/dist/model/units/bytes.d.ts.map +1 -1
  66. package/dist/model/units/bytes.js +16 -16
  67. package/dist/model/units/bytes.js.map +1 -1
  68. package/dist/model/units/constants.js.map +1 -1
  69. package/dist/model/units/decimal.d.ts +8 -8
  70. package/dist/model/units/decimal.d.ts.map +1 -1
  71. package/dist/model/units/decimal.js +12 -12
  72. package/dist/model/units/decimal.js.map +1 -1
  73. package/dist/model/units/index.js.map +1 -1
  74. package/dist/model/units/percent.d.ts +7 -7
  75. package/dist/model/units/percent.d.ts.map +1 -1
  76. package/dist/model/units/percent.js +12 -12
  77. package/dist/model/units/percent.js.map +1 -1
  78. package/dist/model/units/time.d.ts +15 -15
  79. package/dist/model/units/time.d.ts.map +1 -1
  80. package/dist/model/units/time.js +56 -56
  81. package/dist/model/units/time.js.map +1 -1
  82. package/dist/model/units/types.d.ts +14 -5
  83. package/dist/model/units/types.d.ts.map +1 -1
  84. package/dist/model/units/types.js.map +1 -1
  85. package/dist/model/units/units.d.ts +30 -30
  86. package/dist/model/units/units.d.ts.map +1 -1
  87. package/dist/model/units/units.js +31 -31
  88. package/dist/model/units/units.js.map +1 -1
  89. package/dist/model/units/utils.d.ts +2 -2
  90. package/dist/model/units/utils.d.ts.map +1 -1
  91. package/dist/model/units/utils.js +4 -4
  92. package/dist/model/units/utils.js.map +1 -1
  93. package/dist/model/variables.d.ts +25 -7
  94. package/dist/model/variables.d.ts.map +1 -1
  95. package/dist/model/variables.js +3 -0
  96. package/dist/model/variables.js.map +1 -1
  97. package/dist/test/setup-tests.js.map +1 -1
  98. package/dist/utils/event.js.map +1 -1
  99. package/dist/utils/fetch.js.map +1 -1
  100. package/dist/utils/index.d.ts +2 -1
  101. package/dist/utils/index.d.ts.map +1 -1
  102. package/dist/utils/index.js +2 -1
  103. package/dist/utils/index.js.map +1 -1
  104. package/dist/utils/is-empty-object.js.map +1 -1
  105. package/dist/utils/mathjs.js.map +1 -1
  106. package/dist/utils/memo.js +2 -2
  107. package/dist/utils/memo.js.map +1 -1
  108. package/dist/utils/panel-refs.js.map +1 -1
  109. package/dist/utils/text.d.ts +5 -5
  110. package/dist/utils/text.d.ts.map +1 -1
  111. package/dist/utils/text.js +17 -17
  112. package/dist/utils/text.js.map +1 -1
  113. package/dist/utils/time-series-data.js +6 -6
  114. package/dist/utils/time-series-data.js.map +1 -1
  115. package/dist/utils/types.d.ts +2 -0
  116. package/dist/utils/types.d.ts.map +1 -0
  117. package/dist/utils/types.js +15 -0
  118. package/dist/utils/types.js.map +1 -0
  119. package/package.json +5 -4
@@ -21,15 +21,44 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- isRelativeTimeRange: ()=>isRelativeTimeRange,
25
- isAbsoluteTimeRange: ()=>isAbsoluteTimeRange,
26
- toAbsoluteTimeRange: ()=>toAbsoluteTimeRange,
27
- parseDurationString: ()=>parseDurationString,
28
- isDurationString: ()=>isDurationString,
29
- roundStepInterval: ()=>roundStepInterval,
30
- getSuggestedStepMs: ()=>getSuggestedStepMs
24
+ isRelativeTimeRange: function() {
25
+ return isRelativeTimeRange;
26
+ },
27
+ isAbsoluteTimeRange: function() {
28
+ return isAbsoluteTimeRange;
29
+ },
30
+ toAbsoluteTimeRange: function() {
31
+ return toAbsoluteTimeRange;
32
+ },
33
+ parseDurationString: function() {
34
+ return parseDurationString;
35
+ },
36
+ isDurationString: function() {
37
+ return isDurationString;
38
+ },
39
+ intervalToPrometheusDuration: function() {
40
+ return intervalToPrometheusDuration;
41
+ },
42
+ msToPrometheusDuration: function() {
43
+ return msToPrometheusDuration;
44
+ },
45
+ formatDuration: function() {
46
+ return formatDuration;
47
+ },
48
+ roundStepInterval: function() {
49
+ return roundStepInterval;
50
+ },
51
+ getSuggestedStepMs: function() {
52
+ return getSuggestedStepMs;
53
+ }
31
54
  });
32
- const _dateFns = require("date-fns");
55
+ const _datefns = require("date-fns");
56
+ const ONE_SECOND_IN_MS = 1000;
57
+ const ONE_MINUTE_IN_MS = 60000;
58
+ const ONE_HOUR_IN_MS = 3600000;
59
+ const ONE_DAY_IN_MS = 86400000; // assuming a day has always 24h
60
+ const ONE_WEEK_IN_MS = 604800000; // assuming a week has always 7d
61
+ const ONE_YEAR_IN_MS = 31536000000; // assuming a year has always 365d
33
62
  function isRelativeTimeRange(timeRange) {
34
63
  return timeRange.pastDuration !== undefined;
35
64
  }
@@ -37,10 +66,10 @@ function isAbsoluteTimeRange(timeRange) {
37
66
  return timeRange.start !== undefined && timeRange.end !== undefined;
38
67
  }
39
68
  function toAbsoluteTimeRange(timeRange) {
40
- var _end;
41
- const end = (_end = timeRange.end) !== null && _end !== void 0 ? _end : new Date();
69
+ var _timeRange_end;
70
+ const end = (_timeRange_end = timeRange.end) !== null && _timeRange_end !== void 0 ? _timeRange_end : new Date();
42
71
  return {
43
- start: (0, _dateFns.sub)(end, parseDurationString(timeRange.pastDuration)),
72
+ start: (0, _datefns.sub)(end, parseDurationString(timeRange.pastDuration)),
44
73
  end
45
74
  };
46
75
  }
@@ -50,21 +79,75 @@ function parseDurationString(durationString) {
50
79
  if (matches === null) {
51
80
  throw new Error(`Invalid duration string '${durationString}'`);
52
81
  }
53
- var ref, ref1, ref2, ref3, ref4, ref5, ref6;
82
+ var _matches_, _matches_1, _matches_2, _matches_3, _matches_4, _matches_5, _matches_6;
54
83
  return {
55
- years: parseInt((ref = matches[1]) !== null && ref !== void 0 ? ref : '0'),
84
+ years: parseInt((_matches_ = matches[1]) !== null && _matches_ !== void 0 ? _matches_ : '0'),
56
85
  months: 0,
57
- weeks: parseInt((ref1 = matches[2]) !== null && ref1 !== void 0 ? ref1 : '0'),
58
- days: parseInt((ref2 = matches[3]) !== null && ref2 !== void 0 ? ref2 : '0'),
59
- hours: parseInt((ref3 = matches[4]) !== null && ref3 !== void 0 ? ref3 : '0'),
60
- minutes: parseInt((ref4 = matches[5]) !== null && ref4 !== void 0 ? ref4 : '0'),
61
- seconds: parseInt((ref5 = matches[6]) !== null && ref5 !== void 0 ? ref5 : '0') + parseInt((ref6 = matches[7]) !== null && ref6 !== void 0 ? ref6 : '0') / 1000
86
+ weeks: parseInt((_matches_1 = matches[2]) !== null && _matches_1 !== void 0 ? _matches_1 : '0'),
87
+ days: parseInt((_matches_2 = matches[3]) !== null && _matches_2 !== void 0 ? _matches_2 : '0'),
88
+ hours: parseInt((_matches_3 = matches[4]) !== null && _matches_3 !== void 0 ? _matches_3 : '0'),
89
+ minutes: parseInt((_matches_4 = matches[5]) !== null && _matches_4 !== void 0 ? _matches_4 : '0'),
90
+ seconds: parseInt((_matches_5 = matches[6]) !== null && _matches_5 !== void 0 ? _matches_5 : '0') + parseInt((_matches_6 = matches[7]) !== null && _matches_6 !== void 0 ? _matches_6 : '0') / 1000
62
91
  };
63
92
  }
64
93
  function isDurationString(maybeDuration) {
65
94
  if (maybeDuration === '') return false;
66
95
  return DURATION_REGEX.test(maybeDuration);
67
96
  }
97
+ function intervalToPrometheusDuration(timeRange) {
98
+ const durationInMs = timeRange.end.valueOf() - timeRange.start.valueOf();
99
+ return msToPrometheusDuration(durationInMs);
100
+ }
101
+ function msToPrometheusDuration(durationInMs) {
102
+ const years = Math.trunc(durationInMs / ONE_YEAR_IN_MS);
103
+ if (years > 0) durationInMs -= years * ONE_YEAR_IN_MS;
104
+ const weeks = Math.trunc(durationInMs / ONE_WEEK_IN_MS);
105
+ if (weeks > 0) durationInMs -= weeks * ONE_WEEK_IN_MS;
106
+ const days = Math.trunc(durationInMs / ONE_DAY_IN_MS);
107
+ if (days > 0) durationInMs -= days * ONE_DAY_IN_MS;
108
+ const hours = Math.trunc(durationInMs / ONE_HOUR_IN_MS);
109
+ if (hours > 0) durationInMs -= hours * ONE_HOUR_IN_MS;
110
+ const minutes = Math.trunc(durationInMs / ONE_MINUTE_IN_MS);
111
+ if (minutes > 0) durationInMs -= minutes * ONE_MINUTE_IN_MS;
112
+ return {
113
+ years: years,
114
+ months: 0,
115
+ weeks: weeks,
116
+ days: days,
117
+ hours: hours,
118
+ minutes: minutes,
119
+ seconds: durationInMs / 1000
120
+ };
121
+ }
122
+ function formatDuration(duration) {
123
+ const result = [];
124
+ if (duration.years) {
125
+ result.push(`${duration.years}y`);
126
+ }
127
+ if (duration.weeks) {
128
+ result.push(`${duration.weeks}w`);
129
+ }
130
+ if (duration.days) {
131
+ result.push(`${duration.days}d`);
132
+ }
133
+ if (duration.hours) {
134
+ result.push(`${duration.hours}h`);
135
+ }
136
+ if (duration.minutes) {
137
+ result.push(`${duration.minutes}m`);
138
+ }
139
+ if (duration.seconds) {
140
+ const seconds = Math.trunc(duration.seconds);
141
+ if (seconds) {
142
+ result.push(`${seconds}s`);
143
+ }
144
+ const ms = (duration.seconds - seconds) * 1000;
145
+ if (ms) {
146
+ result.push(`${ms}ms`);
147
+ }
148
+ }
149
+ return result.join('');
150
+ }
68
151
  const DEFAULT_STEP_MS = 15000;
69
152
  const ROUNDED_STEP_INTERVALS = [
70
153
  // max: 0.015s
@@ -105,140 +188,140 @@ const ROUNDED_STEP_INTERVALS = [
105
188
  },
106
189
  // max: 1.5s
107
190
  {
108
- maxMs: 1500,
109
- roundedStepMs: 1000,
191
+ maxMs: ONE_SECOND_IN_MS * 1.5,
192
+ roundedStepMs: ONE_SECOND_IN_MS,
110
193
  display: '1s'
111
194
  },
112
195
  // max: 3.5s
113
196
  {
114
- maxMs: 3500,
115
- roundedStepMs: 2000,
197
+ maxMs: ONE_SECOND_IN_MS * 3.5,
198
+ roundedStepMs: ONE_SECOND_IN_MS * 2,
116
199
  display: '2s'
117
200
  },
118
201
  // max: 7.5s
119
202
  {
120
- maxMs: 7500,
121
- roundedStepMs: 5000,
203
+ maxMs: ONE_SECOND_IN_MS * 7.5,
204
+ roundedStepMs: ONE_SECOND_IN_MS * 5,
122
205
  display: '5s'
123
206
  },
124
207
  // max: 12.5s
125
208
  {
126
- maxMs: 12500,
127
- roundedStepMs: 10000,
209
+ maxMs: ONE_SECOND_IN_MS * 12.5,
210
+ roundedStepMs: ONE_SECOND_IN_MS * 10,
128
211
  display: '10s'
129
212
  },
130
213
  // max: 17.5s
131
214
  {
132
- maxMs: 17500,
133
- roundedStepMs: 15000,
215
+ maxMs: ONE_SECOND_IN_MS * 17.5,
216
+ roundedStepMs: ONE_SECOND_IN_MS * 15,
134
217
  display: '15s'
135
218
  },
136
219
  // max: 25s
137
220
  {
138
- maxMs: 25000,
139
- roundedStepMs: 20000,
221
+ maxMs: ONE_SECOND_IN_MS * 25,
222
+ roundedStepMs: ONE_SECOND_IN_MS * 20,
140
223
  display: '20s'
141
224
  },
142
225
  // max: 45s
143
226
  {
144
- maxMs: 45000,
145
- roundedStepMs: 30000,
227
+ maxMs: ONE_SECOND_IN_MS * 45,
228
+ roundedStepMs: ONE_SECOND_IN_MS * 30,
146
229
  display: '30s'
147
230
  },
148
231
  // max: 1.5m
149
232
  {
150
- maxMs: 90000,
151
- roundedStepMs: 60000,
233
+ maxMs: ONE_MINUTE_IN_MS * 1.5,
234
+ roundedStepMs: ONE_MINUTE_IN_MS,
152
235
  display: '1m'
153
236
  },
154
237
  // max: 3.5m
155
238
  {
156
- maxMs: 210000,
157
- roundedStepMs: 120000,
239
+ maxMs: ONE_MINUTE_IN_MS * 3.5,
240
+ roundedStepMs: ONE_MINUTE_IN_MS * 2,
158
241
  display: '2m'
159
242
  },
160
243
  // max: 7.5m
161
244
  {
162
- maxMs: 450000,
163
- roundedStepMs: 300000,
245
+ maxMs: ONE_MINUTE_IN_MS * 7.5,
246
+ roundedStepMs: ONE_MINUTE_IN_MS * 5,
164
247
  display: '5m'
165
248
  },
166
249
  // max: 12.5m
167
250
  {
168
- maxMs: 750000,
169
- roundedStepMs: 600000,
251
+ maxMs: ONE_MINUTE_IN_MS * 12.5,
252
+ roundedStepMs: ONE_MINUTE_IN_MS * 10,
170
253
  display: '10m'
171
254
  },
172
255
  // max: 12.5m
173
256
  {
174
- maxMs: 1050000,
175
- roundedStepMs: 900000,
257
+ maxMs: ONE_MINUTE_IN_MS * 12.5,
258
+ roundedStepMs: ONE_MINUTE_IN_MS * 15,
176
259
  display: '15m'
177
260
  },
178
261
  // max: 25m
179
262
  {
180
- maxMs: 1500000,
181
- roundedStepMs: 1200000,
263
+ maxMs: ONE_MINUTE_IN_MS * 25,
264
+ roundedStepMs: ONE_MINUTE_IN_MS * 20,
182
265
  display: '20m'
183
266
  },
184
267
  // max: 45m
185
268
  {
186
- maxMs: 2700000,
187
- roundedStepMs: 1800000,
269
+ maxMs: ONE_MINUTE_IN_MS * 45,
270
+ roundedStepMs: ONE_MINUTE_IN_MS * 30,
188
271
  display: '30m'
189
272
  },
190
273
  // max: 1.5h
191
274
  {
192
- maxMs: 5400000,
193
- roundedStepMs: 3600000,
275
+ maxMs: ONE_HOUR_IN_MS * 1.5,
276
+ roundedStepMs: ONE_HOUR_IN_MS,
194
277
  display: '1h'
195
278
  },
196
279
  // max: 2.5h
197
280
  {
198
- maxMs: 9000000,
199
- roundedStepMs: 7200000,
281
+ maxMs: ONE_HOUR_IN_MS * 2.5,
282
+ roundedStepMs: ONE_HOUR_IN_MS * 2,
200
283
  display: '2h'
201
284
  },
202
285
  // max: 4.5h
203
286
  {
204
- maxMs: 16200000,
205
- roundedStepMs: 10800000,
287
+ maxMs: ONE_HOUR_IN_MS * 4.5,
288
+ roundedStepMs: ONE_HOUR_IN_MS * 3,
206
289
  display: '3h'
207
290
  },
208
291
  // max: 9h
209
292
  {
210
- maxMs: 32400000,
211
- roundedStepMs: 21600000,
293
+ maxMs: ONE_HOUR_IN_MS * 9,
294
+ roundedStepMs: ONE_HOUR_IN_MS * 6,
212
295
  display: '6h'
213
296
  },
214
297
  // max: 1d
215
298
  {
216
- maxMs: 86400000,
217
- roundedStepMs: 43200000,
299
+ maxMs: ONE_DAY_IN_MS,
300
+ roundedStepMs: ONE_HOUR_IN_MS * 12,
218
301
  display: '12h'
219
302
  },
220
303
  // max: 1w
221
304
  {
222
- maxMs: 604800000,
223
- roundedStepMs: 86400000,
305
+ maxMs: ONE_WEEK_IN_MS,
306
+ roundedStepMs: ONE_DAY_IN_MS,
224
307
  display: '1d'
225
308
  },
226
309
  // max: 3w
227
310
  {
228
- maxMs: 1814400000,
229
- roundedStepMs: 604800000,
311
+ maxMs: ONE_WEEK_IN_MS * 3,
312
+ roundedStepMs: ONE_WEEK_IN_MS,
230
313
  display: '1w'
231
314
  },
232
315
  // max: 6w
233
316
  {
234
- maxMs: 3628800000,
235
- roundedStepMs: 2592000000,
317
+ maxMs: ONE_WEEK_IN_MS * 6,
318
+ roundedStepMs: ONE_DAY_IN_MS * 30,
236
319
  display: '30d'
237
320
  },
238
321
  // max: 2y
239
322
  {
240
- maxMs: 63072000000,
241
- roundedStepMs: 31536000000,
323
+ maxMs: ONE_YEAR_IN_MS * 2,
324
+ roundedStepMs: ONE_YEAR_IN_MS,
242
325
  display: '1y'
243
326
  }
244
327
  ];
@@ -21,14 +21,20 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- BYTES_GROUP_CONFIG: ()=>BYTES_GROUP_CONFIG,
25
- BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
26
- formatBytes: ()=>formatBytes
24
+ BYTES_GROUP_CONFIG: function() {
25
+ return BYTES_GROUP_CONFIG;
26
+ },
27
+ BYTES_UNIT_CONFIG: function() {
28
+ return BYTES_UNIT_CONFIG;
29
+ },
30
+ formatBytes: function() {
31
+ return formatBytes;
32
+ }
27
33
  });
28
- const _numbro = /*#__PURE__*/ _interopRequireDefault(require("numbro"));
34
+ const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
29
35
  const _constants = require("./constants");
30
36
  const _utils = require("./utils");
31
- function _interopRequireDefault(obj) {
37
+ function _interop_require_default(obj) {
32
38
  return obj && obj.__esModule ? obj : {
33
39
  default: obj
34
40
  };
@@ -40,51 +46,51 @@ function _interopRequireDefault(obj) {
40
46
  * 1 MB = 1,000,000 bytes (1000^2 bytes)
41
47
  * etc.
42
48
  */ const DEFAULT_NUMBRO_MANTISSA = 2;
43
- const bytesUnitKinds = [
44
- 'Bytes'
49
+ const bytesUnits = [
50
+ 'bytes'
45
51
  ];
46
52
  const BYTES_GROUP_CONFIG = {
47
53
  label: 'Bytes',
48
- decimal_places: true,
49
- abbreviate: true
54
+ decimalPlaces: true,
55
+ shortValues: true
50
56
  };
51
57
  const BYTES_UNIT_CONFIG = {
52
- Bytes: {
58
+ bytes: {
53
59
  group: 'Bytes',
54
60
  label: 'Bytes'
55
61
  }
56
62
  };
57
- function formatBytes(bytes, { abbreviate , decimal_places }) {
63
+ function formatBytes(bytes, { shortValues , decimalPlaces }) {
58
64
  // If we're showing the entire value, we can use Intl.NumberFormat.
59
- if (!(0, _utils.shouldAbbreviate)(abbreviate) || Math.abs(bytes) < 1000) {
65
+ if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bytes) < 1000) {
60
66
  const formatterOptions = {
61
67
  style: 'unit',
62
68
  unit: 'byte',
63
69
  unitDisplay: 'long',
64
70
  useGrouping: true
65
71
  };
66
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
67
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
68
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
72
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
73
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
74
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
69
75
  } else {
70
76
  // This can happen if bytes is between -1000 and 1000
71
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
77
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
72
78
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
73
79
  }
74
80
  }
75
81
  const formatter = Intl.NumberFormat('en-US', formatterOptions);
76
82
  return formatter.format(bytes);
77
83
  }
78
- // If we're showing the "abbreviated" value, we use numbro.
84
+ // If we're showing the shorten value, we use numbro.
79
85
  // numbro is able to add units like KB, MB, GB, etc. correctly.
80
86
  return (0, _numbro.default)(bytes).format({
81
87
  output: 'byte',
82
88
  base: 'decimal',
83
89
  spaceSeparated: true,
84
- mantissa: (0, _utils.hasDecimalPlaces)(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
90
+ mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
85
91
  // trimMantissa trims trailing 0s
86
- trimMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places),
92
+ trimMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces),
87
93
  // optionalMantissa excludes all the decimal places if they're all zeros
88
- optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places)
94
+ optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces)
89
95
  });
90
96
  }
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", {
18
18
  });
19
19
  Object.defineProperty(exports, "MAX_SIGNIFICANT_DIGITS", {
20
20
  enumerable: true,
21
- get: ()=>MAX_SIGNIFICANT_DIGITS
21
+ get: function() {
22
+ return MAX_SIGNIFICANT_DIGITS;
23
+ }
22
24
  });
23
25
  const MAX_SIGNIFICANT_DIGITS = 3;
@@ -21,39 +21,45 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- DECIMAL_GROUP_CONFIG: ()=>DECIMAL_GROUP_CONFIG,
25
- DECIMAL_UNIT_CONFIG: ()=>DECIMAL_UNIT_CONFIG,
26
- formatDecimal: ()=>formatDecimal
24
+ DECIMAL_GROUP_CONFIG: function() {
25
+ return DECIMAL_GROUP_CONFIG;
26
+ },
27
+ DECIMAL_UNIT_CONFIG: function() {
28
+ return DECIMAL_UNIT_CONFIG;
29
+ },
30
+ formatDecimal: function() {
31
+ return formatDecimal;
32
+ }
27
33
  });
28
34
  const _constants = require("./constants");
29
35
  const _utils = require("./utils");
30
- const decimalUnitKinds = [
31
- 'Decimal'
36
+ const decimalUnits = [
37
+ 'decimal'
32
38
  ];
33
39
  const DECIMAL_GROUP_CONFIG = {
34
40
  label: 'Decimal',
35
- decimal_places: true,
36
- abbreviate: true
41
+ decimalPlaces: true,
42
+ shortValues: true
37
43
  };
38
44
  const DECIMAL_UNIT_CONFIG = {
39
- Decimal: {
45
+ decimal: {
40
46
  group: 'Decimal',
41
47
  label: 'Decimal'
42
48
  }
43
49
  };
44
- function formatDecimal(value, { abbreviate , decimal_places }) {
50
+ function formatDecimal(value, { shortValues , decimalPlaces }) {
45
51
  const formatterOptions = {
46
52
  style: 'decimal',
47
53
  useGrouping: true
48
54
  };
49
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
55
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
50
56
  formatterOptions.notation = 'compact';
51
57
  }
52
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
53
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
54
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
58
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
59
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
60
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
55
61
  } else {
56
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
62
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
57
63
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
58
64
  }
59
65
  }
@@ -14,18 +14,20 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./utils"), exports);
18
- _exportStar(require("./units"), exports);
19
- _exportStar(require("./constants"), exports);
20
- _exportStar(require("./types"), exports);
21
- function _exportStar(from, to) {
17
+ _export_star(require("./utils"), exports);
18
+ _export_star(require("./units"), exports);
19
+ _export_star(require("./constants"), exports);
20
+ _export_star(require("./types"), exports);
21
+ function _export_star(from, to) {
22
22
  Object.keys(from).forEach(function(k) {
23
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
24
- enumerable: true,
25
- get: function() {
26
- return from[k];
27
- }
28
- });
23
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
24
+ Object.defineProperty(to, k, {
25
+ enumerable: true,
26
+ get: function() {
27
+ return from[k];
28
+ }
29
+ });
30
+ }
29
31
  });
30
32
  return from;
31
33
  }
@@ -21,28 +21,34 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- PERCENT_GROUP_CONFIG: ()=>PERCENT_GROUP_CONFIG,
25
- PERCENT_UNIT_CONFIG: ()=>PERCENT_UNIT_CONFIG,
26
- formatPercent: ()=>formatPercent
24
+ PERCENT_GROUP_CONFIG: function() {
25
+ return PERCENT_GROUP_CONFIG;
26
+ },
27
+ PERCENT_UNIT_CONFIG: function() {
28
+ return PERCENT_UNIT_CONFIG;
29
+ },
30
+ formatPercent: function() {
31
+ return formatPercent;
32
+ }
27
33
  });
28
34
  const _constants = require("./constants");
29
35
  const _utils = require("./utils");
30
- const percentUnitKinds = [
31
- 'Percent',
32
- 'PercentDecimal',
36
+ const percentUnits = [
37
+ 'percent',
38
+ 'percent-decimal',
33
39
  '%'
34
40
  ];
35
41
  const PERCENT_GROUP_CONFIG = {
36
- label: 'Percent',
37
- decimal_places: true
42
+ label: 'percent',
43
+ decimalPlaces: true
38
44
  };
39
45
  const PERCENT_GROUP = 'Percent';
40
46
  const PERCENT_UNIT_CONFIG = {
41
- Percent: {
47
+ percent: {
42
48
  group: PERCENT_GROUP,
43
49
  label: 'Percent (0-100)'
44
50
  },
45
- PercentDecimal: {
51
+ 'percent-decimal': {
46
52
  group: PERCENT_GROUP,
47
53
  label: 'Percent (0.0-1.0)'
48
54
  },
@@ -54,19 +60,19 @@ const PERCENT_UNIT_CONFIG = {
54
60
  label: '%'
55
61
  }
56
62
  };
57
- function formatPercent(value, { kind , decimal_places }) {
63
+ function formatPercent(value, { unit , decimalPlaces }) {
58
64
  const formatterOptions = {
59
65
  style: 'percent',
60
66
  useGrouping: true
61
67
  };
62
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
63
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
64
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
68
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
69
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
70
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
65
71
  } else {
66
72
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
67
73
  }
68
74
  // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
69
- if (kind === 'Percent') {
75
+ if (unit === 'percent') {
70
76
  value = value / 100;
71
77
  }
72
78
  const formatter = Intl.NumberFormat('en-US', formatterOptions);