"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Function loads a file from the given URL and returns
 * it as a File.
 *
 * @param urlString
 * @param fileName
 * @returns File
 */
function dataURLToFile(urlString, fileName) {
    var imageArr = atob(urlString);
    var n = imageArr.length;
    var u8arr = new Uint8Array(n);
    while (n--) {
        u8arr[n] = imageArr.charCodeAt(n);
    }
    return new File([u8arr], fileName, { type: "image/png" });
}
exports.dataURLToFile = dataURLToFile;
/**
 * Function takes a file and returns it as a base64 variant of the
 * file.
 *
 * @param File
 * @returns Promise<any> base64 file representation
 */
function getBase64FromFile(file) {
    return new Promise(function (resolve, reject) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () { return resolve(reader.result); };
        reader.onerror = function (error) { return reject(error); };
    });
}
exports.getBase64FromFile = getBase64FromFile;
/**
 * Function returns the file type of the given file.
 *
 * @param file File
 * @returns string file extension
 */
function getFileExtensionFromFile(file) {
    var array = file.name.split(".");
    return array[array.length - 1].toLowerCase();
}
exports.getFileExtensionFromFile = getFileExtensionFromFile;
/**
 * Function verifies whether a given file extension is
 * a supported image file type for the image compression.
 * Supported types are jpeg, jpg and png.
 *
 * @param fileExtension
 * @returns Boolean
 */
function isImageFile(fileExtension) {
    var allowedImageFileExtensions = ["jpg", "jpeg", "png"];
    return allowedImageFileExtensions.indexOf(fileExtension.toLowerCase()) !== -1;
}
exports.isImageFile = isImageFile;
//# sourceMappingURL=Files.js.map