validate-image-type
Version:
Check the image file of a Buffer/Uint8Array that matched expected image MIME-type.
37 lines (36 loc) • 1.16 kB
TypeScript
/// <reference types="node" />
export type ValidateImageTypeOptions = {
/**
* Original file name
* if the `filePath` is temporary random file path, validator use the `originalFilename` instead of `filePath`
*/
originalFilename?: string;
/**
* Allow mime-type lists
* Example ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml']
*/
allowMimeTypes: string[];
};
export type ValidateImageResult = {
ok: boolean;
error?: Error;
};
/**
* Detect the image type of Buffer or Uint8Array
* This check is based on https://github.com/sindresorhus/image-type
*/
export declare function validateBufferMIMEType(buffer: Buffer, options: ValidateImageTypeOptions): Promise<ValidateImageResult>;
/**
* Detect the image type of filePath
* @example
*
* ```
* const validationResult = validateMIMEType("test.png", {
* allowMimeTypes: ['image/jpeg', 'image/gif', 'image/png', 'image/svg+xml']
* });
* if(validationResult) {
* console.error(validationResult)
* }
* ```
*/
export declare function validateMIMEType(filePath: string, options: ValidateImageTypeOptions): Promise<ValidateImageResult>;