getFileAccept()function
Get the accept attribute of a file input for a set of file types, e.g. "image/jpeg,image/png".
getFileAccept(types: FileTypes): string
Tiny helpers for splitting filenames into base name and extension. They exist so callers never need to hand-roll lastIndexOf(".") logic or handle the dotfile edge case themselves.
Things to know:
splitFileExtension(".gitignore") returns [undefined, "gitignore"] — a leading dot only is treated as the extension, not the base name.splitFileExtension("no-ext") returns ["no-ext", undefined]."ts" not ".ts".import { splitFileExtension, getFileExtension, requireFileExtension } from "shelving/util";
splitFileExtension("array.ts"); // ["array", "ts"]
splitFileExtension("archive.tar.gz"); // ["archive.tar", "gz"]
splitFileExtension("no-ext"); // ["no-ext", undefined]
splitFileExtension(".gitignore"); // [undefined, "gitignore"]
splitFileExtension(undefined); // [undefined, undefined]
getFileExtension("index.html"); // "html"
getFileExtension("no-ext"); // undefined
requireFileExtension("style.css"); // "css"
requireFileExtension("no-ext"); // throws RequiredErrorGet the accept attribute of a file input for a set of file types, e.g. "image/jpeg,image/png".
getFileAccept(types: FileTypes): string
Split a filename into its base name and extension in a single pass.
splitFileExtension(file: Nullish<string> = ""): [base: string | undefined, extension: string | undefined]
Get the file extension from a file path, e.g. "md", or return undefined if the input has no extension.
getFileExtension(file: Nullish<string>): string | undefined
Get the file extension from a file path e.g. "tsx", or throw RequiredError if the input has no extension.
requireFileExtension(file: string, caller: AnyCaller = requireFileExtension): string
List of file types in extension: mime format.
{
[extension: string]: string;
}Which camera a file picker opens straight away: "user" is the front (selfie) camera, "environment" the back camera.
"user" | "environment"
Image file types in extension: mime format: JPEG, PNG, WebP, GIF, and AVIF.
IMAGE_TYPES: FileTypes
Video file types in extension: mime format: MP4, QuickTime, and WebM.
VIDEO_TYPES: FileTypes
Media file types in extension: mime format: every type in IMAGE_TYPES and VIDEO_TYPES.
MEDIA_TYPES: FileTypes