Convert formatSize to ts

This commit is contained in:
RMidhunSuresh 2021-11-16 14:44:16 +05:30
parent 4ce7634201
commit a3460d8c2a
2 changed files with 3 additions and 2 deletions

View file

@ -16,7 +16,7 @@ limitations under the License.
*/
import {BaseMessageTile} from "./BaseMessageTile.js";
import {formatSize} from "../../../../../utils/formatSize.js";
import {formatSize} from "../../../../../utils/formatSize";
import {SendStatus} from "../../../../../matrix/room/sending/PendingEvent.js";
export class FileTile extends BaseMessageTile {

View file

@ -14,7 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
export function formatSize(size, decimals = 2) {
export function formatSize(size: number, decimals: number = 2): string | undefined {
if (Number.isSafeInteger(size)) {
const base = Math.min(3, Math.floor(Math.log(size) / Math.log(1024)));
const formattedSize = Math.round(size / Math.pow(1024, base)).toFixed(decimals);