Add stats for nerds (#2453)

Co-authored-by: David Luzar <luzar.david@gmail.com>
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Lipis 2020-12-07 18:35:16 +02:00 committed by GitHub
parent 5cdb9bd2ed
commit dd993adc5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 361 additions and 33 deletions

View file

@ -133,6 +133,9 @@ export const debounce = <T extends any[]>(
fn(...lastArgs);
}
};
ret.cancel = () => {
clearTimeout(handle);
};
return ret;
};
@ -336,3 +339,23 @@ export const withBatchedUpdates = <
((event) => {
unstable_batchedUpdates(func as TFunction, event);
}) as TFunction;
//https://stackoverflow.com/a/9462382/8418
export const nFormatter = (num: number, digits: number): string => {
const si = [
{ value: 1, symbol: "b" },
{ value: 1e3, symbol: "k" },
{ value: 1e6, symbol: "M" },
{ value: 1e9, symbol: "G" },
];
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
let index;
for (index = si.length - 1; index > 0; index--) {
if (num >= si[index].value) {
break;
}
}
return (
(num / si[index].value).toFixed(digits).replace(rx, "$1") + si[index].symbol
);
};