@adonisjs/bodyparser
Version:
BodyParser middleware for AdonisJS http server to read and parse request body
39 lines (38 loc) • 1.06 kB
TypeScript
import { type MultipartFile } from '../file.ts';
/**
* Validates the file extension against a list of allowed extensions
*/
export declare class ExtensionValidator {
#private;
/**
* Whether the file has been validated
*/
validated: boolean;
/**
* Update the expected file extensions
*/
get extensions(): string[] | undefined;
set extensions(extnames: string[] | undefined);
/**
* Creates a new ExtensionValidator instance
*
* @param file - The multipart file to validate
*/
constructor(file: MultipartFile);
/**
* Validates the file extension against the list of allowed extensions.
* During streaming, validation waits until the extension is detected.
*
* @example
* ```ts
* const validator = new ExtensionValidator(file)
* validator.extensions = ['jpg', 'png', 'gif']
* validator.validate()
*
* if (!file.isValid) {
* console.log(file.errors) // Extension validation errors
* }
* ```
*/
validate(): void;
}