@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
23 lines • 716 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatFileSize = formatFileSize;
const MAX_MEGA_BYTES = 500;
function formatFileSize(file) {
if (!file.size) {
return null;
}
const megaBytes = file.size / (1024 * 1024);
if (megaBytes <= MAX_MEGA_BYTES) {
return formatter.format(megaBytes);
}
return `> ${MAX_MEGA_BYTES} MB`;
}
const formatter = new Intl.NumberFormat("nb-NO", {
style: "unit",
unit: "megabyte",
minimumFractionDigits: 2,
maximumFractionDigits: 2,
// @ts-expect-error - Looks like roundingMode hasn't been added to TypeScript yet
roundingMode: "ceil",
});
//# sourceMappingURL=format-file-size.js.map