@brizy/media-gallery
Version:
33 lines (32 loc) • 1.3 kB
JavaScript
export var formatSizeUnits = function(bytes) {
if (bytes >= 1073741824) {
return "".concat((bytes / 1073741824).toFixed(2), " GB");
} else if (bytes >= 1048576) {
return "".concat((bytes / 1048576).toFixed(2), " MB");
} else if (bytes >= 1024) {
return "".concat((bytes / 1024).toFixed(2), " KB");
} else if (bytes > 1) {
return "".concat(bytes, " bytes");
} else if (bytes == 1) {
return "".concat(bytes, " byte");
} else {
return "0 bytes";
}
};
export var getDimensions = function(param) {
var width = param.width, height = param.height;
return width && height ? "".concat(width, " x ").concat(height, " px") : undefined;
};
export var getFileName = function(fileName) {
var fileParts = fileName.split(".");
return fileParts.length > 1 ? fileParts.slice(0, fileParts.length - 1).join(".") : undefined;
};
export var getExtension = function(fileName) {
var fileParts = fileName.split(".");
return fileParts.length > 1 ? fileParts[fileParts.length - 1] : undefined;
};
export var getExtensionByUrl = function(url) {
var search = new URL(url).search;
var extension = new URLSearchParams(search).get("fm");
return extension !== null && extension !== void 0 ? extension : undefined;
};