@@ -7,16 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
77Please see LICENSE files in the repository root for full details.
88*/
99
10- import {
11- filesize ,
12- type FileSizeOptionsArray ,
13- type FileSizeOptionsBase ,
14- type FileSizeOptionsExponent ,
15- type FileSizeOptionsObject ,
16- type FileSizeOptionsString ,
17- type FileSizeReturnArray ,
18- type FileSizeReturnObject ,
19- } from "filesize" ;
10+ import { filesize , type FilesizeOptions , type FilesizeReturn } from "filesize" ;
2011import { type MediaEventContent } from "matrix-js-sdk/src/types" ;
2112
2213import { _t } from "../languageHandler" ;
@@ -27,7 +18,7 @@ export function downloadLabelForFile(content: MediaEventContent, withSize = true
2718 if ( content . info ?. size && withSize ) {
2819 // If we know the size of the file then add it as human-readable string to the end of the link text
2920 // so that the user knows how big a file they are downloading.
30- text += " (" + < string > fileSize ( content . info . size , { base : 2 , standard : "jedec" } ) + ")" ;
21+ text += " (" + fileSize ( content . info . size , { base : 2 , standard : "jedec" } ) + ")" ;
3122 }
3223 return text ;
3324}
@@ -83,18 +74,11 @@ export function presentableTextForFile(
8374 // it since it is "ugly", users generally aren't aware what it
8475 // means and the type of the attachment can usually be inferred
8576 // from the file extension.
86- text += " (" + < string > fileSize ( content . info . size , { base : 2 , standard : "jedec" } ) + ")" ;
77+ text += " (" + fileSize ( content . info . size , { base : 2 , standard : "jedec" } ) + ")" ;
8778 }
8879 return text ;
8980}
9081
91- type FileSizeOptions =
92- | FileSizeOptionsString
93- | FileSizeOptionsBase
94- | FileSizeOptionsArray
95- | FileSizeOptionsExponent
96- | FileSizeOptionsObject ;
97-
9882/**
9983 * wrapper function to set default values for filesize function
10084 *
@@ -106,15 +90,7 @@ type FileSizeOptions =
10690 * exponent: number;
10791 * unit: string;}} formatted file size with unit e.g. 12kB, 12KB
10892 */
109- export function fileSize ( byteCount : number , options : FileSizeOptionsString | FileSizeOptionsBase ) : string ;
110- export function fileSize ( byteCount : number , options : FileSizeOptionsArray ) : FileSizeReturnArray ;
111- export function fileSize ( byteCount : number , options : FileSizeOptionsExponent ) : number ;
112- export function fileSize ( byteCount : number , options : FileSizeOptionsObject ) : FileSizeReturnObject ;
113- export function fileSize ( byteCount : number ) : string ;
114- export function fileSize (
115- byteCount : number ,
116- options ?: FileSizeOptions ,
117- ) : string | number | FileSizeReturnArray | FileSizeReturnObject {
118- const defaultOption : FileSizeOptions = { base : 2 , standard : "jedec" , ...options } ;
119- return filesize ( byteCount , defaultOption ) ;
93+ export function fileSize < O extends FilesizeOptions > ( byteCount : number , options ?: O ) : FilesizeReturn < O > {
94+ const defaultOption = { base : 2 , standard : "jedec" , ...options } as O ;
95+ return filesize < O > ( byteCount , defaultOption ) ;
12096}
0 commit comments