Skip to content

Instantly share code, notes, and snippets.

@tinmegali
Created August 16, 2019 21:16
Show Gist options
  • Save tinmegali/a71606e4b849677bef88d647e7e93c89 to your computer and use it in GitHub Desktop.
Save tinmegali/a71606e4b849677bef88d647e7e93c89 to your computer and use it in GitHub Desktop.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'fileIcon'
})
export class FileIconPipe implements PipeTransform {
transform(fileType: string): string {
switch (fileType) {
// images
case 'image/png': {
return 'file-image';
}
case 'image/jpeg': {
return 'file-image';
}
case 'image/bmp': {
return 'file-image';
}
case 'image/svg+xml': {
return 'file-image';
}
case 'image/tiff': {
return 'file-image';
}
// audio
case 'audio/mpeg': {
return 'file-audio';
}
case 'audio/ogg': {
return 'file-audio';
}
case 'audio/wav': {
return 'file-audio';
}
case 'audio/aac': {
return 'file-audio';
}
// video
case 'video/x-msvideo': {
return 'file-video';
}
case 'video/mpeg': {
return 'file-video';
}
case 'video/3gpp': {
return 'file-video';
}
// other
case 'application/pdf': {
return 'file-pdf';
}
case 'application/msword': {
return 'file-word';
}
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {
return 'file-word';
}
default: {
return 'file';
}
}
}
}
import {FileIconPipe} from 'app/shared/file-icon.pipe';
@NgModule({
declarations: [ FileIconPipe],
exports: [FileIconPipe],
})
<fa-icon [icon]="file.fileType | fileIcon"></fa-icon>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment