tipoArquivo
This commit is contained in:
parent
e87d0a0239
commit
eae585645d
5 changed files with 51 additions and 5 deletions
|
|
@ -1,6 +1,8 @@
|
|||
type tiposArquivo = "imagem" | "documento" | "vídeo" | "outros"
|
||||
|
||||
export const extensoes: {
|
||||
ext: string
|
||||
tipo: "imagem" | "documento" | "vídeo"
|
||||
tipo: tiposArquivo
|
||||
mime: string
|
||||
}[] = [
|
||||
{
|
||||
|
|
@ -154,3 +156,22 @@ export const extensoes: {
|
|||
mime: "video/mpeg",
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* Função que retorna o tipo do arquivo
|
||||
* @param nomeArquivo
|
||||
* @returns
|
||||
*/
|
||||
export const tipoArquivo = (
|
||||
nomeArquivo: string | null | undefined,
|
||||
): tiposArquivo => {
|
||||
// extenssão do arquivo
|
||||
const extArquivo = String(nomeArquivo || "")
|
||||
.toLocaleLowerCase()
|
||||
.split(".")
|
||||
.pop()
|
||||
// procura a extensão do arquivo na lista de extensões
|
||||
const extensao = extensoes.find((extensao) => extensao.ext === extArquivo)
|
||||
// retorna o tipo do arquivo
|
||||
return extensao?.tipo || "outros"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue