Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'dart:math';
5 :
6 : import 'package:material_ui/material_ui.dart';
7 :
8 : extension IntExt on int {
9 0 : IconData toIcon() => IconData(this, fontFamily: 'MaterialIcons');
10 :
11 0 : String toByteSize() {
12 : const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
13 0 : if (this == 0) return '0 B';
14 0 : final i = (log(this) / log(1024)).floor();
15 0 : return '${(this / pow(1024, i)).toStringAsFixed(2)} ${sizes[i]}';
16 : }
17 : }
|