@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
25 lines (24 loc) • 1.11 kB
TypeScript
import type { TFileValidator } from '../../shared-types';
export interface IValidateFileOptions {
allowedFormats?: string[];
maxFileSize?: string | number;
formatErrorMessage?: string;
sizeErrorMessage?: string;
onFileValidation?: TFileValidator;
}
/** Apply `{formats}` / `{maxSize}` placeholders to a user-supplied message, falling back to the default. */
export declare function applyErrorTemplate(template: string | undefined | null, fallback: string, placeholders: Record<string, string>): string;
/**
* Run the shared validation pipeline (format → size → user callback).
* Returns the first error string, or `null` if the file is accepted.
*
* The `onFileValidation` callback is called last and can veto an otherwise-valid file.
*/
export declare function validateFile(file: File, options: IValidateFileOptions): string | null;
/** Detect whether a file (or an item with `.file` and `.attributes.targetFilename`) is an image. */
export declare function isImageFileLike(input: {
file?: File | null;
attributes?: {
targetFilename?: string;
};
}): boolean;