2 * Provides helper functions for file handling.
4 * @author Matthias Schmidt
5 * @copyright 2001-2018 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/FileUtil
9 define(['Dictionary', 'StringUtil'], function(Dictionary
, StringUtil
) {
12 var _fileExtensionIconMapping
= Dictionary
.fromObject({
70 * Formats the given filesize.
72 * @param {integer} byte number of bytes
73 * @param {integer} precision number of decimals
74 * @return {string} formatted filesize
76 formatFilesize: function(byte, precision
) {
77 if (precision
=== undefined) {
99 return StringUtil
.formatNumeric(byte, -precision
) + ' ' + symbol
;
103 * Returns the icon name for given filename.
105 * Note: For any file icon name like `fa-file-word`, only `word`
106 * will be returned by this method.
108 * @parsm {string} filename name of file for which icon name will be returned
109 * @return {string} FontAwesome icon name
111 getIconNameByFilename: function(filename
) {
112 var lastDotPosition
= filename
.lastIndexOf('.');
113 if (lastDotPosition
!== false) {
114 var extension
= filename
.substr(lastDotPosition
+ 1);
116 if (_fileExtensionIconMapping
.has(extension
)) {
117 return _fileExtensionIconMapping
.get(extension
);