@perses-dev/components 0.15.0 → 0.17.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.
- package/dist/LineChart/LineChart.d.ts +3 -2
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +6 -16
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +18 -0
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +35 -9
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts +13 -0
- package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js +28 -0
- package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +5 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +50 -0
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts +13 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js +26 -0
- package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +13 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js +36 -0
- package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -0
- package/dist/OptionsEditorLayout/index.d.ts +5 -0
- package/dist/OptionsEditorLayout/index.d.ts.map +1 -0
- package/dist/OptionsEditorLayout/index.js +18 -0
- package/dist/OptionsEditorLayout/index.js.map +1 -0
- package/dist/Tooltip/SeriesInfo.d.ts +1 -0
- package/dist/Tooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/Tooltip/SeriesInfo.js +3 -3
- package/dist/Tooltip/SeriesInfo.js.map +1 -1
- package/dist/Tooltip/Tooltip.d.ts +2 -1
- package/dist/Tooltip/Tooltip.d.ts.map +1 -1
- package/dist/Tooltip/Tooltip.js +2 -2
- package/dist/Tooltip/Tooltip.js.map +1 -1
- package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/Tooltip/TooltipContent.js +2 -1
- package/dist/Tooltip/TooltipContent.js.map +1 -1
- package/dist/Tooltip/focused-series.d.ts +4 -3
- package/dist/Tooltip/focused-series.d.ts.map +1 -1
- package/dist/Tooltip/focused-series.js +6 -3
- package/dist/Tooltip/focused-series.js.map +1 -1
- package/dist/Tooltip/focused-series.test.js +20 -2
- package/dist/Tooltip/focused-series.test.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.d.ts +8 -0
- package/dist/UnitSelector/UnitSelector.d.ts.map +1 -0
- package/dist/UnitSelector/UnitSelector.js +112 -0
- package/dist/UnitSelector/UnitSelector.js.map +1 -0
- package/dist/UnitSelector/UnitSelector.test.d.ts +2 -0
- package/dist/UnitSelector/UnitSelector.test.d.ts.map +1 -0
- package/dist/UnitSelector/UnitSelector.test.js +211 -0
- package/dist/UnitSelector/UnitSelector.test.js.map +1 -0
- package/dist/UnitSelector/index.d.ts +2 -0
- package/dist/UnitSelector/index.d.ts.map +1 -0
- package/dist/UnitSelector/index.js +15 -0
- package/dist/UnitSelector/index.js.map +1 -0
- package/dist/YAxisLabel.d.ts +8 -0
- package/dist/YAxisLabel.d.ts.map +1 -0
- package/dist/YAxisLabel.js +39 -0
- package/dist/YAxisLabel.js.map +1 -0
- package/dist/cjs/LineChart/LineChart.js +5 -15
- package/dist/cjs/LineChart/utils.js +23 -1
- package/dist/cjs/OptionsEditorLayout/OptionsEditorColumn.js +32 -0
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +61 -0
- package/dist/cjs/OptionsEditorLayout/OptionsEditorGrid.js +29 -0
- package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +40 -0
- package/dist/cjs/OptionsEditorLayout/index.js +31 -0
- package/dist/cjs/Tooltip/SeriesInfo.js +3 -3
- package/dist/cjs/Tooltip/Tooltip.js +2 -2
- package/dist/cjs/Tooltip/TooltipContent.js +2 -1
- package/dist/cjs/Tooltip/focused-series.js +6 -3
- package/dist/cjs/Tooltip/focused-series.test.js +20 -2
- package/dist/cjs/UnitSelector/UnitSelector.js +118 -0
- package/dist/cjs/UnitSelector/UnitSelector.test.js +218 -0
- package/dist/cjs/UnitSelector/index.js +28 -0
- package/dist/cjs/YAxisLabel.js +45 -0
- package/dist/cjs/index.js +5 -2
- package/dist/cjs/model/units/bytes.js +60 -0
- package/dist/cjs/model/units/constants.js +23 -0
- package/dist/cjs/model/units/decimal.js +67 -0
- package/dist/cjs/model/units/index.js +30 -0
- package/dist/cjs/model/units/percent.js +64 -0
- package/dist/cjs/model/units/time.js +138 -0
- package/dist/cjs/model/units/types.js +28 -0
- package/dist/cjs/model/units/units.js +104 -0
- package/dist/cjs/utils/component-ids.js +31 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/model/units/bytes.d.ts +12 -0
- package/dist/model/units/bytes.d.ts.map +1 -0
- package/dist/model/units/bytes.js +48 -0
- package/dist/model/units/bytes.js.map +1 -0
- package/dist/model/units/constants.d.ts +2 -0
- package/dist/model/units/constants.d.ts.map +1 -0
- package/dist/model/units/constants.js +17 -0
- package/dist/model/units/constants.js.map +1 -0
- package/dist/model/units/decimal.d.ts +24 -0
- package/dist/model/units/decimal.d.ts.map +1 -0
- package/dist/model/units/decimal.js +59 -0
- package/dist/model/units/decimal.js.map +1 -0
- package/dist/model/units/index.d.ts +4 -0
- package/dist/model/units/index.d.ts.map +1 -0
- package/dist/model/units/index.js +17 -0
- package/dist/model/units/index.js.map +1 -0
- package/dist/model/units/percent.d.ts +12 -0
- package/dist/model/units/percent.d.ts.map +1 -0
- package/dist/model/units/percent.js +51 -0
- package/dist/model/units/percent.js.map +1 -0
- package/dist/model/units/time.d.ts +11 -0
- package/dist/model/units/time.d.ts.map +1 -0
- package/dist/model/units/time.js +125 -0
- package/dist/model/units/time.js.map +1 -0
- package/dist/model/units/types.d.ts +38 -0
- package/dist/model/units/types.d.ts.map +1 -0
- package/dist/model/units/types.js +22 -0
- package/dist/model/units/types.js.map +1 -0
- package/dist/model/units/units.d.ts +40 -0
- package/dist/model/units/units.d.ts.map +1 -0
- package/dist/model/units/units.js +83 -0
- package/dist/model/units/units.js.map +1 -0
- package/dist/utils/component-ids.d.ts +8 -0
- package/dist/utils/component-ids.d.ts.map +1 -0
- package/dist/utils/component-ids.js +27 -0
- package/dist/utils/component-ids.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/cjs/model/units.js +0 -203
- package/dist/model/units.d.ts +0 -36
- package/dist/model/units.d.ts.map +0 -1
- package/dist/model/units.js +0 -196
- package/dist/model/units.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/component-ids.ts"],"sourcesContent":["// Copyright 2022 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 { useRef } from 'react';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var useIdValue: number;\n}\n\n/**\n * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.\n */\nexport function useId(prefix: string) {\n if (globalThis.useIdValue === undefined) {\n globalThis.useIdValue = 0;\n }\n\n const id = useRef<string | undefined>(undefined);\n if (id.current === undefined) {\n id.current = `${prefix}-${globalThis.useIdValue++}`;\n }\n return id.current;\n}\n"],"names":["useRef","useId","prefix","globalThis","useIdValue","undefined","id","current"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAQ,OAAO,CAAC;AAO/B;;CAEC,GACD,OAAO,SAASC,KAAK,CAACC,MAAc,EAAE;IACpC,IAAIC,UAAU,CAACC,UAAU,KAAKC,SAAS,EAAE;QACvCF,UAAU,CAACC,UAAU,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED,MAAME,EAAE,GAAGN,MAAM,CAAqBK,SAAS,CAAC,AAAC;IACjD,IAAIC,EAAE,CAACC,OAAO,KAAKF,SAAS,EAAE;QAC5BC,EAAE,CAACC,OAAO,GAAG,CAAC,EAAEL,MAAM,CAAC,CAAC,EAAEC,UAAU,CAACC,UAAU,EAAE,CAAC,CAAC,CAAC;IACtD,CAAC;IACD,OAAOE,EAAE,CAACC,OAAO,CAAC;AACpB,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
package/dist/utils/index.js
CHANGED
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './combine-sx';\nexport * from './theme-gen';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './combine-sx';\nexport * from './theme-gen';\nexport * from './component-ids';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Common UI components used across Perses features",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@mui/x-date-pickers": "^5.0.0-beta.1",
|
|
36
|
-
"@perses-dev/core": "^0.
|
|
36
|
+
"@perses-dev/core": "^0.17.0",
|
|
37
37
|
"date-fns": "^2.28.0",
|
|
38
38
|
"echarts": "^5.3.3",
|
|
39
39
|
"lodash-es": "^4.17.21",
|
package/dist/cjs/model/units.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
function _export(target, all) {
|
|
18
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: all[name]
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
_export(exports, {
|
|
24
|
-
DEFAULT_DECIMAL_PLACES: ()=>DEFAULT_DECIMAL_PLACES,
|
|
25
|
-
formatValue: ()=>formatValue,
|
|
26
|
-
abbreviateLargeNumber: ()=>abbreviateLargeNumber,
|
|
27
|
-
formatNumber: ()=>formatNumber
|
|
28
|
-
});
|
|
29
|
-
const _dateFns = require("date-fns");
|
|
30
|
-
const _mathjs = require("../utils/mathjs");
|
|
31
|
-
const DEFAULT_DECIMAL_PLACES = 2;
|
|
32
|
-
function formatValue(value, unitOptions) {
|
|
33
|
-
if (unitOptions === undefined) {
|
|
34
|
-
return value.toString();
|
|
35
|
-
}
|
|
36
|
-
if (isDecimalUnit(unitOptions)) {
|
|
37
|
-
return formatDecimal(value, unitOptions);
|
|
38
|
-
}
|
|
39
|
-
if (isTimeUnit(unitOptions)) {
|
|
40
|
-
return formatTime(value, unitOptions);
|
|
41
|
-
}
|
|
42
|
-
if (isPercentUnit(unitOptions)) {
|
|
43
|
-
return formatPercent(value, unitOptions);
|
|
44
|
-
}
|
|
45
|
-
if (isBytesUnit(unitOptions)) {
|
|
46
|
-
var _decimal_places;
|
|
47
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
48
|
-
return formatBytes(value, decimals);
|
|
49
|
-
}
|
|
50
|
-
const exhaustive = unitOptions;
|
|
51
|
-
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
52
|
-
}
|
|
53
|
-
/* Time Unit Conversion */ const timeUnitKinds = [
|
|
54
|
-
'Milliseconds',
|
|
55
|
-
'Seconds',
|
|
56
|
-
'Minutes',
|
|
57
|
-
'Hours',
|
|
58
|
-
'Days',
|
|
59
|
-
'Weeks',
|
|
60
|
-
'Months',
|
|
61
|
-
'Years'
|
|
62
|
-
];
|
|
63
|
-
const timeUnitKindsSet = new Set(timeUnitKinds);
|
|
64
|
-
function isTimeUnit(unitOptions) {
|
|
65
|
-
return timeUnitKindsSet.has(unitOptions.kind);
|
|
66
|
-
}
|
|
67
|
-
function formatTime(value, unitOptions) {
|
|
68
|
-
// Create a Duration from the value based on what time unit it is
|
|
69
|
-
const duration = {};
|
|
70
|
-
switch(unitOptions.kind){
|
|
71
|
-
case 'Milliseconds':
|
|
72
|
-
duration.seconds = value / 1000;
|
|
73
|
-
break;
|
|
74
|
-
case 'Seconds':
|
|
75
|
-
duration.seconds = value;
|
|
76
|
-
break;
|
|
77
|
-
case 'Minutes':
|
|
78
|
-
duration.minutes = value;
|
|
79
|
-
break;
|
|
80
|
-
case 'Hours':
|
|
81
|
-
duration.hours = value;
|
|
82
|
-
break;
|
|
83
|
-
case 'Days':
|
|
84
|
-
duration.days = value;
|
|
85
|
-
break;
|
|
86
|
-
case 'Weeks':
|
|
87
|
-
duration.weeks = value;
|
|
88
|
-
break;
|
|
89
|
-
case 'Months':
|
|
90
|
-
duration.months = value;
|
|
91
|
-
break;
|
|
92
|
-
case 'Years':
|
|
93
|
-
duration.years = value;
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
{
|
|
97
|
-
const exhaustive = unitOptions.kind;
|
|
98
|
-
throw new Error(`Unknown time unit type ${exhaustive}`);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
// Find the largest whole time unit we can display the value in and use it
|
|
102
|
-
const ms = (0, _dateFns.milliseconds)(duration);
|
|
103
|
-
const seconds = ms / 1000;
|
|
104
|
-
if (seconds < 1) {
|
|
105
|
-
return `${ms.toFixed()} milliseconds`;
|
|
106
|
-
}
|
|
107
|
-
const minutes = seconds / 60;
|
|
108
|
-
if (minutes < 1) {
|
|
109
|
-
return `${seconds.toFixed()} seconds`;
|
|
110
|
-
}
|
|
111
|
-
const hours = minutes / 60;
|
|
112
|
-
if (hours < 1) {
|
|
113
|
-
return `${minutes.toFixed()} minutes`;
|
|
114
|
-
}
|
|
115
|
-
const days = hours / 24;
|
|
116
|
-
if (days < 1) {
|
|
117
|
-
return `${hours.toFixed()} hours`;
|
|
118
|
-
}
|
|
119
|
-
const weeks = days / 7;
|
|
120
|
-
if (weeks < 1) {
|
|
121
|
-
return `${days.toFixed()} days`;
|
|
122
|
-
}
|
|
123
|
-
const years = weeks / 52;
|
|
124
|
-
if (years < 1) {
|
|
125
|
-
return `${weeks.toFixed()} weeks`;
|
|
126
|
-
}
|
|
127
|
-
return `${years.toFixed()} years`;
|
|
128
|
-
}
|
|
129
|
-
/* Percent Unit Conversion */ const percentUnitKinds = [
|
|
130
|
-
'Percent',
|
|
131
|
-
'PercentDecimal',
|
|
132
|
-
'%'
|
|
133
|
-
];
|
|
134
|
-
const percentUnitKindsSet = new Set(percentUnitKinds);
|
|
135
|
-
function isPercentUnit(unitOptions) {
|
|
136
|
-
return percentUnitKindsSet.has(unitOptions.kind);
|
|
137
|
-
}
|
|
138
|
-
function formatPercent(value, unitOptions) {
|
|
139
|
-
var _decimal_places;
|
|
140
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
141
|
-
if (unitOptions.kind === 'PercentDecimal') {
|
|
142
|
-
value = value * 100;
|
|
143
|
-
}
|
|
144
|
-
return value.toFixed(decimals) + '%';
|
|
145
|
-
}
|
|
146
|
-
/* Decimal Unit Conversion */ const decimalUnitKinds = [
|
|
147
|
-
'Decimal'
|
|
148
|
-
];
|
|
149
|
-
const decimalUnitKindsSet = new Set(decimalUnitKinds);
|
|
150
|
-
function isDecimalUnit(unitOptions) {
|
|
151
|
-
return decimalUnitKindsSet.has(unitOptions.kind);
|
|
152
|
-
}
|
|
153
|
-
function formatDecimal(value, unitOptions) {
|
|
154
|
-
var _decimal_places;
|
|
155
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
156
|
-
if (unitOptions.abbreviate === true) {
|
|
157
|
-
return abbreviateLargeNumber(value, decimals);
|
|
158
|
-
}
|
|
159
|
-
const formatParams = {
|
|
160
|
-
style: 'decimal',
|
|
161
|
-
minimumFractionDigits: 0,
|
|
162
|
-
maximumFractionDigits: decimals,
|
|
163
|
-
useGrouping: true
|
|
164
|
-
};
|
|
165
|
-
const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);
|
|
166
|
-
return decimalFormatter.format(value);
|
|
167
|
-
}
|
|
168
|
-
function abbreviateLargeNumber(num, decimals = 2) {
|
|
169
|
-
const modifier = (n)=>(0, _mathjs.round)(n, decimals);
|
|
170
|
-
return formatNumber(num, modifier);
|
|
171
|
-
}
|
|
172
|
-
function formatNumber(num, modifier) {
|
|
173
|
-
const fn = modifier !== null && modifier !== void 0 ? modifier : Math.round;
|
|
174
|
-
return num >= 1e12 ? fn(num / 1e12) + 'T' : num >= 1e9 ? fn(num / 1e9) + 'B' : num >= 1e6 ? fn(num / 1e6) + 'M' : num >= 1e3 ? fn(num / 1e3) + 'K' : num.toString();
|
|
175
|
-
}
|
|
176
|
-
/* Bytes Unit Conversion */ const bytesUnitKinds = [
|
|
177
|
-
'Bytes'
|
|
178
|
-
];
|
|
179
|
-
const bytesUnitKindsSet = new Set(bytesUnitKinds);
|
|
180
|
-
function isBytesUnit(unitOptions) {
|
|
181
|
-
return bytesUnitKindsSet.has(unitOptions.kind);
|
|
182
|
-
}
|
|
183
|
-
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
|
|
184
|
-
function formatBytes(bytes, decimals = 2) {
|
|
185
|
-
if (bytes === 0) return '0 Bytes';
|
|
186
|
-
const k = 1024;
|
|
187
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
188
|
-
const sizes = [
|
|
189
|
-
'Bytes',
|
|
190
|
-
'KB',
|
|
191
|
-
'MB',
|
|
192
|
-
'GB',
|
|
193
|
-
'TB',
|
|
194
|
-
'PB',
|
|
195
|
-
'EB',
|
|
196
|
-
'ZB',
|
|
197
|
-
'YB'
|
|
198
|
-
];
|
|
199
|
-
// Math.max(0, ...) ensures that we don't return -1 as a value for the index.
|
|
200
|
-
// Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
|
|
201
|
-
const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
|
|
202
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
203
|
-
}
|
package/dist/model/units.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_DECIMAL_PLACES = 2;
|
|
2
|
-
export declare type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;
|
|
3
|
-
export declare function formatValue(value: number, unitOptions?: UnitOptions): string;
|
|
4
|
-
declare const timeUnitKinds: readonly ["Milliseconds", "Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", "Years"];
|
|
5
|
-
declare type TimeUnitOptions = {
|
|
6
|
-
kind: typeof timeUnitKinds[number];
|
|
7
|
-
};
|
|
8
|
-
declare const percentUnitKinds: readonly ["Percent", "PercentDecimal", "%"];
|
|
9
|
-
declare type PercentUnitOptions = {
|
|
10
|
-
kind: typeof percentUnitKinds[number];
|
|
11
|
-
decimal_places?: number;
|
|
12
|
-
};
|
|
13
|
-
declare const decimalUnitKinds: readonly ["Decimal"];
|
|
14
|
-
declare type DecimalUnitOptions = {
|
|
15
|
-
kind: typeof decimalUnitKinds[number];
|
|
16
|
-
decimal_places?: number;
|
|
17
|
-
abbreviate?: boolean;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Takes large numbers and abbreviates them with the appropriate suffix
|
|
21
|
-
* 10123 -> 10.123k
|
|
22
|
-
* 1000000 -> 1M
|
|
23
|
-
*/
|
|
24
|
-
export declare function abbreviateLargeNumber(num: number, decimals?: number): string;
|
|
25
|
-
/**
|
|
26
|
-
* Takes large numbers, rounds and abbreviates them with the appropriate suffix
|
|
27
|
-
* Add modifier to run on output value prior to unit being added (defaults to rounding)
|
|
28
|
-
*/
|
|
29
|
-
export declare function formatNumber(num: number, modifier?: (n: number) => number): string;
|
|
30
|
-
declare const bytesUnitKinds: readonly ["Bytes"];
|
|
31
|
-
declare type BytesUnitOptions = {
|
|
32
|
-
kind: typeof bytesUnitKinds[number];
|
|
33
|
-
decimal_places?: number;
|
|
34
|
-
};
|
|
35
|
-
export {};
|
|
36
|
-
//# sourceMappingURL=units.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/model/units.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAwB5E;AAGD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AAGnH,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AA4EF,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AAGrE,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAiBF,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAG9C,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAuBF;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,UAG9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAYlF;AAGD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAG1C,aAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
|
package/dist/model/units.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
import { milliseconds } from 'date-fns';
|
|
14
|
-
import { round } from '../utils/mathjs';
|
|
15
|
-
export const DEFAULT_DECIMAL_PLACES = 2;
|
|
16
|
-
export function formatValue(value, unitOptions) {
|
|
17
|
-
if (unitOptions === undefined) {
|
|
18
|
-
return value.toString();
|
|
19
|
-
}
|
|
20
|
-
if (isDecimalUnit(unitOptions)) {
|
|
21
|
-
return formatDecimal(value, unitOptions);
|
|
22
|
-
}
|
|
23
|
-
if (isTimeUnit(unitOptions)) {
|
|
24
|
-
return formatTime(value, unitOptions);
|
|
25
|
-
}
|
|
26
|
-
if (isPercentUnit(unitOptions)) {
|
|
27
|
-
return formatPercent(value, unitOptions);
|
|
28
|
-
}
|
|
29
|
-
if (isBytesUnit(unitOptions)) {
|
|
30
|
-
var _decimal_places;
|
|
31
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
32
|
-
return formatBytes(value, decimals);
|
|
33
|
-
}
|
|
34
|
-
const exhaustive = unitOptions;
|
|
35
|
-
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
36
|
-
}
|
|
37
|
-
/* Time Unit Conversion */ const timeUnitKinds = [
|
|
38
|
-
'Milliseconds',
|
|
39
|
-
'Seconds',
|
|
40
|
-
'Minutes',
|
|
41
|
-
'Hours',
|
|
42
|
-
'Days',
|
|
43
|
-
'Weeks',
|
|
44
|
-
'Months',
|
|
45
|
-
'Years'
|
|
46
|
-
];
|
|
47
|
-
const timeUnitKindsSet = new Set(timeUnitKinds);
|
|
48
|
-
function isTimeUnit(unitOptions) {
|
|
49
|
-
return timeUnitKindsSet.has(unitOptions.kind);
|
|
50
|
-
}
|
|
51
|
-
function formatTime(value, unitOptions) {
|
|
52
|
-
// Create a Duration from the value based on what time unit it is
|
|
53
|
-
const duration = {};
|
|
54
|
-
switch(unitOptions.kind){
|
|
55
|
-
case 'Milliseconds':
|
|
56
|
-
duration.seconds = value / 1000;
|
|
57
|
-
break;
|
|
58
|
-
case 'Seconds':
|
|
59
|
-
duration.seconds = value;
|
|
60
|
-
break;
|
|
61
|
-
case 'Minutes':
|
|
62
|
-
duration.minutes = value;
|
|
63
|
-
break;
|
|
64
|
-
case 'Hours':
|
|
65
|
-
duration.hours = value;
|
|
66
|
-
break;
|
|
67
|
-
case 'Days':
|
|
68
|
-
duration.days = value;
|
|
69
|
-
break;
|
|
70
|
-
case 'Weeks':
|
|
71
|
-
duration.weeks = value;
|
|
72
|
-
break;
|
|
73
|
-
case 'Months':
|
|
74
|
-
duration.months = value;
|
|
75
|
-
break;
|
|
76
|
-
case 'Years':
|
|
77
|
-
duration.years = value;
|
|
78
|
-
break;
|
|
79
|
-
default:
|
|
80
|
-
{
|
|
81
|
-
const exhaustive = unitOptions.kind;
|
|
82
|
-
throw new Error(`Unknown time unit type ${exhaustive}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Find the largest whole time unit we can display the value in and use it
|
|
86
|
-
const ms = milliseconds(duration);
|
|
87
|
-
const seconds = ms / 1000;
|
|
88
|
-
if (seconds < 1) {
|
|
89
|
-
return `${ms.toFixed()} milliseconds`;
|
|
90
|
-
}
|
|
91
|
-
const minutes = seconds / 60;
|
|
92
|
-
if (minutes < 1) {
|
|
93
|
-
return `${seconds.toFixed()} seconds`;
|
|
94
|
-
}
|
|
95
|
-
const hours = minutes / 60;
|
|
96
|
-
if (hours < 1) {
|
|
97
|
-
return `${minutes.toFixed()} minutes`;
|
|
98
|
-
}
|
|
99
|
-
const days = hours / 24;
|
|
100
|
-
if (days < 1) {
|
|
101
|
-
return `${hours.toFixed()} hours`;
|
|
102
|
-
}
|
|
103
|
-
const weeks = days / 7;
|
|
104
|
-
if (weeks < 1) {
|
|
105
|
-
return `${days.toFixed()} days`;
|
|
106
|
-
}
|
|
107
|
-
const years = weeks / 52;
|
|
108
|
-
if (years < 1) {
|
|
109
|
-
return `${weeks.toFixed()} weeks`;
|
|
110
|
-
}
|
|
111
|
-
return `${years.toFixed()} years`;
|
|
112
|
-
}
|
|
113
|
-
/* Percent Unit Conversion */ const percentUnitKinds = [
|
|
114
|
-
'Percent',
|
|
115
|
-
'PercentDecimal',
|
|
116
|
-
'%'
|
|
117
|
-
];
|
|
118
|
-
const percentUnitKindsSet = new Set(percentUnitKinds);
|
|
119
|
-
function isPercentUnit(unitOptions) {
|
|
120
|
-
return percentUnitKindsSet.has(unitOptions.kind);
|
|
121
|
-
}
|
|
122
|
-
function formatPercent(value, unitOptions) {
|
|
123
|
-
var _decimal_places;
|
|
124
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
125
|
-
if (unitOptions.kind === 'PercentDecimal') {
|
|
126
|
-
value = value * 100;
|
|
127
|
-
}
|
|
128
|
-
return value.toFixed(decimals) + '%';
|
|
129
|
-
}
|
|
130
|
-
/* Decimal Unit Conversion */ const decimalUnitKinds = [
|
|
131
|
-
'Decimal'
|
|
132
|
-
];
|
|
133
|
-
const decimalUnitKindsSet = new Set(decimalUnitKinds);
|
|
134
|
-
function isDecimalUnit(unitOptions) {
|
|
135
|
-
return decimalUnitKindsSet.has(unitOptions.kind);
|
|
136
|
-
}
|
|
137
|
-
function formatDecimal(value, unitOptions) {
|
|
138
|
-
var _decimal_places;
|
|
139
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
140
|
-
if (unitOptions.abbreviate === true) {
|
|
141
|
-
return abbreviateLargeNumber(value, decimals);
|
|
142
|
-
}
|
|
143
|
-
const formatParams = {
|
|
144
|
-
style: 'decimal',
|
|
145
|
-
minimumFractionDigits: 0,
|
|
146
|
-
maximumFractionDigits: decimals,
|
|
147
|
-
useGrouping: true
|
|
148
|
-
};
|
|
149
|
-
const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);
|
|
150
|
-
return decimalFormatter.format(value);
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Takes large numbers and abbreviates them with the appropriate suffix
|
|
154
|
-
* 10123 -> 10.123k
|
|
155
|
-
* 1000000 -> 1M
|
|
156
|
-
*/ export function abbreviateLargeNumber(num, decimals = 2) {
|
|
157
|
-
const modifier = (n)=>round(n, decimals);
|
|
158
|
-
return formatNumber(num, modifier);
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Takes large numbers, rounds and abbreviates them with the appropriate suffix
|
|
162
|
-
* Add modifier to run on output value prior to unit being added (defaults to rounding)
|
|
163
|
-
*/ export function formatNumber(num, modifier) {
|
|
164
|
-
const fn = modifier !== null && modifier !== void 0 ? modifier : Math.round;
|
|
165
|
-
return num >= 1e12 ? fn(num / 1e12) + 'T' : num >= 1e9 ? fn(num / 1e9) + 'B' : num >= 1e6 ? fn(num / 1e6) + 'M' : num >= 1e3 ? fn(num / 1e3) + 'K' : num.toString();
|
|
166
|
-
}
|
|
167
|
-
/* Bytes Unit Conversion */ const bytesUnitKinds = [
|
|
168
|
-
'Bytes'
|
|
169
|
-
];
|
|
170
|
-
const bytesUnitKindsSet = new Set(bytesUnitKinds);
|
|
171
|
-
function isBytesUnit(unitOptions) {
|
|
172
|
-
return bytesUnitKindsSet.has(unitOptions.kind);
|
|
173
|
-
}
|
|
174
|
-
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
|
|
175
|
-
function formatBytes(bytes, decimals = 2) {
|
|
176
|
-
if (bytes === 0) return '0 Bytes';
|
|
177
|
-
const k = 1024;
|
|
178
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
179
|
-
const sizes = [
|
|
180
|
-
'Bytes',
|
|
181
|
-
'KB',
|
|
182
|
-
'MB',
|
|
183
|
-
'GB',
|
|
184
|
-
'TB',
|
|
185
|
-
'PB',
|
|
186
|
-
'EB',
|
|
187
|
-
'ZB',
|
|
188
|
-
'YB'
|
|
189
|
-
];
|
|
190
|
-
// Math.max(0, ...) ensures that we don't return -1 as a value for the index.
|
|
191
|
-
// Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
|
|
192
|
-
const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
|
|
193
|
-
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
//# sourceMappingURL=units.js.map
|
package/dist/model/units.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/units.ts"],"sourcesContent":["// Copyright 2022 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, milliseconds } from 'date-fns';\nimport { round } from '../utils/mathjs';\n\nexport const DEFAULT_DECIMAL_PLACES = 2;\n\nexport type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;\n\nexport function formatValue(value: number, unitOptions?: UnitOptions): string {\n if (unitOptions === undefined) {\n return value.toString();\n }\n\n if (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isBytesUnit(unitOptions)) {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n return formatBytes(value, decimals);\n }\n\n const exhaustive: never = unitOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\n/* Time Unit Conversion */\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\nconst timeUnitKindsSet = new Set<string>(timeUnitKinds);\n\ntype TimeUnitOptions = {\n kind: typeof timeUnitKinds[number];\n};\n\nfunction isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions {\n return timeUnitKindsSet.has(unitOptions.kind);\n}\n\nfunction formatTime(value: number, unitOptions: TimeUnitOptions): string {\n // Create a Duration from the value based on what time unit it is\n const duration: Duration = {};\n switch (unitOptions.kind) {\n case 'Milliseconds':\n duration.seconds = value / 1000;\n break;\n case 'Seconds':\n duration.seconds = value;\n break;\n case 'Minutes':\n duration.minutes = value;\n break;\n case 'Hours':\n duration.hours = value;\n break;\n case 'Days':\n duration.days = value;\n break;\n case 'Weeks':\n duration.weeks = value;\n break;\n case 'Months':\n duration.months = value;\n break;\n case 'Years':\n duration.years = value;\n break;\n default: {\n const exhaustive: never = unitOptions.kind;\n throw new Error(`Unknown time unit type ${exhaustive}`);\n }\n }\n\n // Find the largest whole time unit we can display the value in and use it\n const ms = milliseconds(duration);\n const seconds = ms / 1000;\n if (seconds < 1) {\n return `${ms.toFixed()} milliseconds`;\n }\n\n const minutes = seconds / 60;\n if (minutes < 1) {\n return `${seconds.toFixed()} seconds`;\n }\n\n const hours = minutes / 60;\n if (hours < 1) {\n return `${minutes.toFixed()} minutes`;\n }\n\n const days = hours / 24;\n if (days < 1) {\n return `${hours.toFixed()} hours`;\n }\n\n const weeks = days / 7;\n if (weeks < 1) {\n return `${days.toFixed()} days`;\n }\n\n const years = weeks / 52;\n if (years < 1) {\n return `${weeks.toFixed()} weeks`;\n }\n\n return `${years.toFixed()} years`;\n}\n\n/* Percent Unit Conversion */\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\nconst percentUnitKindsSet = new Set<string>(percentUnitKinds);\n\ntype PercentUnitOptions = {\n kind: typeof percentUnitKinds[number];\n decimal_places?: number;\n};\n\nfunction isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions {\n return percentUnitKindsSet.has(unitOptions.kind);\n}\n\nfunction formatPercent(value: number, unitOptions: PercentUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n if (unitOptions.kind === 'PercentDecimal') {\n value = value * 100;\n }\n\n return value.toFixed(decimals) + '%';\n}\n\n/* Decimal Unit Conversion */\nconst decimalUnitKinds = ['Decimal'] as const;\nconst decimalUnitKindsSet = new Set<string>(decimalUnitKinds);\n\ntype DecimalUnitOptions = {\n kind: typeof decimalUnitKinds[number];\n decimal_places?: number;\n abbreviate?: boolean;\n};\n\nfunction isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions {\n return decimalUnitKindsSet.has(unitOptions.kind);\n}\n\nfunction formatDecimal(value: number, unitOptions: DecimalUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n if (unitOptions.abbreviate === true) {\n return abbreviateLargeNumber(value, decimals);\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: 0,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);\n return decimalFormatter.format(value);\n}\n\n/**\n * Takes large numbers and abbreviates them with the appropriate suffix\n * 10123 -> 10.123k\n * 1000000 -> 1M\n */\nexport function abbreviateLargeNumber(num: number, decimals = 2) {\n const modifier = (n: number) => round(n, decimals);\n return formatNumber(num, modifier);\n}\n\n/**\n * Takes large numbers, rounds and abbreviates them with the appropriate suffix\n * Add modifier to run on output value prior to unit being added (defaults to rounding)\n */\nexport function formatNumber(num: number, modifier?: (n: number) => number): string {\n const fn = modifier ?? Math.round;\n\n return num >= 1e12\n ? fn(num / 1e12) + 'T'\n : num >= 1e9\n ? fn(num / 1e9) + 'B'\n : num >= 1e6\n ? fn(num / 1e6) + 'M'\n : num >= 1e3\n ? fn(num / 1e3) + 'K'\n : num.toString();\n}\n\n/* Bytes Unit Conversion */\nconst bytesUnitKinds = ['Bytes'] as const;\nconst bytesUnitKindsSet = new Set<string>(bytesUnitKinds);\n\ntype BytesUnitOptions = {\n kind: typeof bytesUnitKinds[number];\n decimal_places?: number;\n};\n\nfunction isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions {\n return bytesUnitKindsSet.has(unitOptions.kind);\n}\n\n// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828\nfunction formatBytes(bytes: number, decimals = 2) {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1024;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n // Math.max(0, ...) ensures that we don't return -1 as a value for the index.\n // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.\n const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];\n}\n"],"names":["milliseconds","round","DEFAULT_DECIMAL_PLACES","formatValue","value","unitOptions","undefined","toString","isDecimalUnit","formatDecimal","isTimeUnit","formatTime","isPercentUnit","formatPercent","isBytesUnit","decimals","decimal_places","formatBytes","exhaustive","Error","timeUnitKinds","timeUnitKindsSet","Set","has","kind","duration","seconds","minutes","hours","days","weeks","months","years","ms","toFixed","percentUnitKinds","percentUnitKindsSet","decimalUnitKinds","decimalUnitKindsSet","abbreviate","abbreviateLargeNumber","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","decimalFormatter","Intl","NumberFormat","format","num","modifier","n","formatNumber","fn","Math","bytesUnitKinds","bytesUnitKindsSet","bytes","k","dm","sizes","i","max","floor","log","parseFloat","pow"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAmBA,YAAY,QAAQ,UAAU,CAAC;AAClD,SAASC,KAAK,QAAQ,iBAAiB,CAAC;AAExC,OAAO,MAAMC,sBAAsB,GAAG,CAAC,CAAC;AAIxC,OAAO,SAASC,WAAW,CAACC,KAAa,EAAEC,WAAyB,EAAU;IAC5E,IAAIA,WAAW,KAAKC,SAAS,EAAE;QAC7B,OAAOF,KAAK,CAACG,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED,IAAIC,aAAa,CAACH,WAAW,CAAC,EAAE;QAC9B,OAAOI,aAAa,CAACL,KAAK,EAAEC,WAA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