@oslokommune/punkt-elements
Version:
Komponentbiblioteket til Punkt, et designsystem laget av Oslo Origo
31 lines (30 loc) • 1.56 kB
TypeScript
/**
* Normalize an `allowedFormats` value (array or undefined) to lowercase, trimmed, non-empty tokens.
*/
export declare function normalizeAllowedFormats(formats: string[] | undefined | null): string[];
/**
* Parse a native `accept` attribute value (comma-separated) into normalized tokens.
*/
export declare function parseAcceptTokens(accept: string | undefined | null): string[];
/**
* Return `true` when a file matches one of the normalized allowed-format tokens.
* Supports plain extensions (`'pdf'`, `'.pdf'`), exact MIME types (`'application/pdf'`),
* and wildcards (`'image/*'`).
*/
export declare function matchesAllowedFormat(token: string, fileExtension: string, fileMimeType: string): boolean;
/**
* Check whether a `File` matches any of the allowed formats.
* An empty list is treated as "accept everything".
*/
export declare function isFileAllowed(file: File, allowedFormats: string[]): boolean;
/**
* Build a `accept=""` string from allowed formats, falling back to an explicit accept when provided.
*/
export declare function resolveAcceptAttribute(explicitAccept: string | undefined, allowedFormats: string[] | undefined): string;
/** Human-readable token for the "Format: …" help line. */
export declare function formatTokenForDisplay(token: string): string;
/**
* Produce the "Format: PDF, JPG, …" list used under the drop zone.
* Falls back to `accept` tokens when `allowedFormats` is empty.
*/
export declare function getSupportedFormatsText(allowedFormats: string[] | undefined, accept: string | undefined): string;