Update dependency filesize to v11 (#30380)
* Update dependency filesize to v11 * Update fileSize types Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -7,16 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import {
|
||||
filesize,
|
||||
type FileSizeOptionsArray,
|
||||
type FileSizeOptionsBase,
|
||||
type FileSizeOptionsExponent,
|
||||
type FileSizeOptionsObject,
|
||||
type FileSizeOptionsString,
|
||||
type FileSizeReturnArray,
|
||||
type FileSizeReturnObject,
|
||||
} from "filesize";
|
||||
import { filesize, type FilesizeOptions, type FilesizeReturn } from "filesize";
|
||||
import { type MediaEventContent } from "matrix-js-sdk/src/types";
|
||||
|
||||
import { _t } from "../languageHandler";
|
||||
@@ -27,7 +18,7 @@ export function downloadLabelForFile(content: MediaEventContent, withSize = true
|
||||
if (content.info?.size && withSize) {
|
||||
// If we know the size of the file then add it as human-readable string to the end of the link text
|
||||
// so that the user knows how big a file they are downloading.
|
||||
text += " (" + <string>fileSize(content.info.size, { base: 2, standard: "jedec" }) + ")";
|
||||
text += " (" + fileSize(content.info.size, { base: 2, standard: "jedec" }) + ")";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@@ -83,18 +74,11 @@ export function presentableTextForFile(
|
||||
// it since it is "ugly", users generally aren't aware what it
|
||||
// means and the type of the attachment can usually be inferred
|
||||
// from the file extension.
|
||||
text += " (" + <string>fileSize(content.info.size, { base: 2, standard: "jedec" }) + ")";
|
||||
text += " (" + fileSize(content.info.size, { base: 2, standard: "jedec" }) + ")";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
type FileSizeOptions =
|
||||
| FileSizeOptionsString
|
||||
| FileSizeOptionsBase
|
||||
| FileSizeOptionsArray
|
||||
| FileSizeOptionsExponent
|
||||
| FileSizeOptionsObject;
|
||||
|
||||
/**
|
||||
* wrapper function to set default values for filesize function
|
||||
*
|
||||
@@ -106,15 +90,7 @@ type FileSizeOptions =
|
||||
* exponent: number;
|
||||
* unit: string;}} formatted file size with unit e.g. 12kB, 12KB
|
||||
*/
|
||||
export function fileSize(byteCount: number, options: FileSizeOptionsString | FileSizeOptionsBase): string;
|
||||
export function fileSize(byteCount: number, options: FileSizeOptionsArray): FileSizeReturnArray;
|
||||
export function fileSize(byteCount: number, options: FileSizeOptionsExponent): number;
|
||||
export function fileSize(byteCount: number, options: FileSizeOptionsObject): FileSizeReturnObject;
|
||||
export function fileSize(byteCount: number): string;
|
||||
export function fileSize(
|
||||
byteCount: number,
|
||||
options?: FileSizeOptions,
|
||||
): string | number | FileSizeReturnArray | FileSizeReturnObject {
|
||||
const defaultOption: FileSizeOptions = { base: 2, standard: "jedec", ...options };
|
||||
return filesize(byteCount, defaultOption);
|
||||
export function fileSize<O extends FilesizeOptions>(byteCount: number, options?: O): FilesizeReturn<O> {
|
||||
const defaultOption = { base: 2, standard: "jedec", ...options } as O;
|
||||
return filesize<O>(byteCount, defaultOption);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user