feat: add pi hole summary integration (#521)
* feat: add pi hole summary integration * feat: add pi hole summary widget * fix: type issues with integrations and integrationIds * feat: add middleware for integrations and improve cache redis channel * feat: add error boundary for widgets * fix: broken lock file * fix: format format issues * fix: typecheck issue * fix: deepsource issues * fix: widget sandbox without error boundary * chore: address pull request feedback * chore: remove todo comment and created issue * fix: format issues * fix: deepsource issue
This commit is contained in:
@@ -3,3 +3,4 @@ export * from "./string";
|
||||
export * from "./cookie";
|
||||
export * from "./array";
|
||||
export * from "./stopwatch";
|
||||
export * from "./number";
|
||||
|
||||
17
packages/common/src/number.ts
Normal file
17
packages/common/src/number.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const ranges = [
|
||||
{ divider: 1e18, suffix: "E" },
|
||||
{ divider: 1e15, suffix: "P" },
|
||||
{ divider: 1e12, suffix: "T" },
|
||||
{ divider: 1e9, suffix: "G" },
|
||||
{ divider: 1e6, suffix: "M" },
|
||||
{ divider: 1e3, suffix: "k" },
|
||||
];
|
||||
|
||||
export const formatNumber = (value: number, decimalPlaces: number) => {
|
||||
for (const range of ranges) {
|
||||
if (value < range.divider) continue;
|
||||
|
||||
return (value / range.divider).toFixed(decimalPlaces) + range.suffix;
|
||||
}
|
||||
return value.toFixed(decimalPlaces);
|
||||
};
|
||||
Reference in New Issue
Block a user