Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
k-funk opened this issue Oct 19, 2021 · 0 comments

Comments

@k-funk
Copy link

k-funk commented Oct 19, 2021

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant