Created
March 28, 2020 16:20
-
-
Save Akeri/04b11a911fbabac166cd7cce929bde03 to your computer and use it in GitHub Desktop.
AngularJS Filter to transform MIME type to FontAwesome 4 icon class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ngapp') | |
/** | |
* Transform MIME type to FontAwesome 4 icon class | |
*/ | |
.filter('mime2fa', function () { | |
const iconClasses = { | |
// Media | |
'image': 'fa-file-image-o', | |
'audio': 'fa-file-audio-o', | |
'video': 'fa-file-video-o', | |
// Documents | |
'application/pdf': 'fa-file-pdf-o', | |
'application/msword': 'fa-file-word-o', | |
'application/vnd.ms-word': 'fa-file-word-o', | |
'application/vnd.oasis.opendocument.text': 'fa-file-word-o', | |
'application/vnd.openxmlformats-officedocument.wordprocessingml': 'fa-file-word-o', | |
'application/vnd.ms-excel': 'fa-file-excel-o', | |
'application/vnd.openxmlformats-officedocument.spreadsheetml': 'fa-file-excel-o', | |
'application/vnd.oasis.opendocument.spreadsheet': 'fa-file-excel-o', | |
'application/vnd.ms-powerpoint': 'fa-file-powerpoint-o', | |
'application/vnd.openxmlformats-officedocument.presentationml': 'fa-file-powerpoint-o', | |
'application/vnd.oasis.opendocument.presentation': 'fa-file-powerpoint-o', | |
'text/plain': 'fa-file-text-o', | |
'text/html': 'fa-file-code-o', | |
'application/json': 'fa-file-code-o', | |
// Archives | |
'application/gzip': 'fa-file-archive-o', | |
'application/zip': 'fa-file-archive-o' | |
}; | |
return function (mimeType) { | |
let fa = 'file-o'; | |
for (let key in iconClasses) { | |
if (iconClasses.hasOwnProperty(key) && mimeType.search(key) === 0) { | |
fa = iconClasses[key]; | |
} | |
} | |
return `fa ${fa}`; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example