attr-accept icon indicating copy to clipboard operation
attr-accept copied to clipboard

Feature Request: Split into two functions: getMimeType() + validateMimeType()

Open k-funk opened this issue 4 years ago • 1 comments

I'd like to use this same lib not only for validation, but determining which type a given file is as well.

Signatures

function getMimeType(file?: File): { baseType, type } {
  ...
}

function validateMimeType(file?: File, acceptedFiles?: string | string[]): boolean {
  ...
  const { baseType, type } = getMimeType(file)
  ...
}

Sample Usage

const myFile = <a file>

if (!validateMimeType(myFile)) { throw new Error('not a valid file type') }

if (getMimeType(myFile).baseType === 'image') {
  // present preview of the image
} else {
  // present a generic file icon
}

k-funk avatar Oct 19 '21 23:10 k-funk

@k-funk PRs are welcomed, so go ahead.

rolandjitsu avatar Oct 07 '24 20:10 rolandjitsu