UNPKG

validate-image-type

Version:

Check the image file of a Buffer/Uint8Array that matched expected image MIME-type.

35 lines 716 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.imageType = void 0; const supportedImageTypes = [ "jpg", "png", "gif", "webp", "flif", "cr2", "tif", "bmp", "jxr", "psd", "ico", "bpg", "jp2", "jpm", "jpx", "heic", "cur", "dcm", "avif" ]; const imageExts = new Set(supportedImageTypes); const imageType = async (buffer) => { const { fileTypeFromBuffer } = await import("file-type"); const ret = await fileTypeFromBuffer(buffer); if (!ret) { return null; } return imageExts.has(ret.ext) ? ret.mime : null; }; exports.imageType = imageType; //# sourceMappingURL=image-type.js.map