Files
js/utils/number.ts
T
Jonas Daniels 4837c95a09 feat: add YourFilesSection to DashboardStorage page (#1788)
* feat: add YourFilesSection to DashboardStorage page

* refactor: remove file preview column

* style: add monospace font to file size text

* fix(components): fix YourFilesSection pagination and data fetching

* fix(dropzone): Invalidate pinned files query on file upload

* feat(storage): add file list refetch on upload

* chore(useApi): keep the promise around to avoid multiple fetches

* feat: Add AccountPermissionsV1 to guides and templates
2023-10-18 06:15:24 +00:00

35 lines
867 B
TypeScript

export const toUSD = (value: number) => {
return new Intl.NumberFormat(undefined, {
style: "currency",
currency: "USD",
}).format(value);
};
export const toSize = (value: number | bigint, defaultUnit?: string) => {
if (value === 0 && defaultUnit) {
return `${value}${defaultUnit}`;
}
const formatted = new Intl.NumberFormat("en", {
notation: "compact",
style: "unit",
unit: "byte",
unitDisplay: "narrow",
}).format(value);
// bummer: there is a bug with NumberFormat and it does not support GB
if (formatted.endsWith("BB")) {
return formatted.replace(/BB$/, "GB");
}
return formatted;
};
export const toNumber = (value: number) => {
return new Intl.NumberFormat(undefined).format(value);
};
export const toPercent = (num1: number, num2: number) => {
return Math.round(((num1 / num2) * 100 * 10) / 10);
};