@spaced-out/ui-design-system
Version:
Sense UI components library
60 lines (54 loc) • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.uuid = exports.range = exports.convertFileSize = void 0;
const uuid = () => {
let dt = new Date().getTime();
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const r = (dt + Math.random() * 16) % 16 | 0;
dt = Math.floor(dt / 16);
return (c === 'x' ? r : r & 0x3 | 0x8).toString(16);
});
};
exports.uuid = uuid;
const range = (start, end) => {
const length = end - start + 1;
return Array.from({
length
}, (_, i) => start + i);
};
exports.range = range;
const convertFileSize = function () {
let fileSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
let sizeInBytes = fileSize;
// Check if the file size is less than 1024
if (sizeInBytes < 0) {
sizeInBytes = Math.abs(sizeInBytes);
}
// Handle the case where the file size is 0 or negative
if (sizeInBytes <= 0) {
return '0 B';
}
// Check if the file size is less than 1024
if (sizeInBytes < 1024) {
// Return the file size in bytes
return sizeInBytes.toString() + ' B';
}
// Check if the file size is less than 1048576
else if (sizeInBytes < 1048576) {
// Return the file size in KB
return (sizeInBytes / 1024).toFixed(1) + ' KB';
}
// Check if the file size is less than 1073741824
else if (sizeInBytes < 1073741824) {
// Return the file size in MB
return (sizeInBytes / 1048576).toFixed(1) + ' MB';
}
// Otherwise, the file size is greater than or equal to 1073741824
else {
// Return the file size in GB
return (sizeInBytes / 1073741824).toFixed(1) + ' GB';
}
};
exports.convertFileSize = convertFileSize;