mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Convert formatSize to ts
This commit is contained in:
parent
4ce7634201
commit
a3460d8c2a
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseMessageTile} from "./BaseMessageTile.js";
|
import {BaseMessageTile} from "./BaseMessageTile.js";
|
||||||
import {formatSize} from "../../../../../utils/formatSize.js";
|
import {formatSize} from "../../../../../utils/formatSize";
|
||||||
import {SendStatus} from "../../../../../matrix/room/sending/PendingEvent.js";
|
import {SendStatus} from "../../../../../matrix/room/sending/PendingEvent.js";
|
||||||
|
|
||||||
export class FileTile extends BaseMessageTile {
|
export class FileTile extends BaseMessageTile {
|
||||||
|
@ -14,7 +14,8 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function formatSize(size, decimals = 2) {
|
|
||||||
|
export function formatSize(size: number, decimals: number = 2): string | undefined {
|
||||||
if (Number.isSafeInteger(size)) {
|
if (Number.isSafeInteger(size)) {
|
||||||
const base = Math.min(3, Math.floor(Math.log(size) / Math.log(1024)));
|
const base = Math.min(3, Math.floor(Math.log(size) / Math.log(1024)));
|
||||||
const formattedSize = Math.round(size / Math.pow(1024, base)).toFixed(decimals);
|
const formattedSize = Math.round(size / Math.pow(1024, base)).toFixed(decimals);
|
Loading…
Reference in New Issue
Block a user