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:
renovate[bot]
2025-07-29 11:15:11 +01:00
committed by GitHub
parent 45a2fd9d63
commit 9232a220dc
3 changed files with 11 additions and 35 deletions

View File

@@ -117,7 +117,7 @@
"emojibase-regex": "15.3.2", "emojibase-regex": "15.3.2",
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"filesize": "10.1.6", "filesize": "11.0.2",
"github-markdown-css": "^5.5.1", "github-markdown-css": "^5.5.1",
"glob-to-regexp": "^0.4.1", "glob-to-regexp": "^0.4.1",
"highlight.js": "^11.3.1", "highlight.js": "^11.3.1",

View File

@@ -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. Please see LICENSE files in the repository root for full details.
*/ */
import { import { filesize, type FilesizeOptions, type FilesizeReturn } from "filesize";
filesize,
type FileSizeOptionsArray,
type FileSizeOptionsBase,
type FileSizeOptionsExponent,
type FileSizeOptionsObject,
type FileSizeOptionsString,
type FileSizeReturnArray,
type FileSizeReturnObject,
} from "filesize";
import { type MediaEventContent } from "matrix-js-sdk/src/types"; import { type MediaEventContent } from "matrix-js-sdk/src/types";
import { _t } from "../languageHandler"; import { _t } from "../languageHandler";
@@ -27,7 +18,7 @@ export function downloadLabelForFile(content: MediaEventContent, withSize = true
if (content.info?.size && withSize) { 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 // 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. // 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; return text;
} }
@@ -83,18 +74,11 @@ export function presentableTextForFile(
// it since it is "ugly", users generally aren't aware what it // it since it is "ugly", users generally aren't aware what it
// means and the type of the attachment can usually be inferred // means and the type of the attachment can usually be inferred
// from the file extension. // 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; return text;
} }
type FileSizeOptions =
| FileSizeOptionsString
| FileSizeOptionsBase
| FileSizeOptionsArray
| FileSizeOptionsExponent
| FileSizeOptionsObject;
/** /**
* wrapper function to set default values for filesize function * wrapper function to set default values for filesize function
* *
@@ -106,15 +90,7 @@ type FileSizeOptions =
* exponent: number; * exponent: number;
* unit: string;}} formatted file size with unit e.g. 12kB, 12KB * unit: string;}} formatted file size with unit e.g. 12kB, 12KB
*/ */
export function fileSize(byteCount: number, options: FileSizeOptionsString | FileSizeOptionsBase): string; export function fileSize<O extends FilesizeOptions>(byteCount: number, options?: O): FilesizeReturn<O> {
export function fileSize(byteCount: number, options: FileSizeOptionsArray): FileSizeReturnArray; const defaultOption = { base: 2, standard: "jedec", ...options } as O;
export function fileSize(byteCount: number, options: FileSizeOptionsExponent): number; return filesize<O>(byteCount, defaultOption);
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);
} }

View File

@@ -8108,10 +8108,10 @@ filelist@^1.0.4:
dependencies: dependencies:
minimatch "^5.0.1" minimatch "^5.0.1"
filesize@10.1.6: filesize@11.0.2:
version "10.1.6" version "11.0.2"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-10.1.6.tgz#31194da825ac58689c0bce3948f33ce83aabd361" resolved "https://registry.yarnpkg.com/filesize/-/filesize-11.0.2.tgz#b7771e3836812582ad74b8a10d6eb0dc58c1ceda"
integrity sha512-sJslQKU2uM33qH5nqewAwVB2QgR6w1aMNsYUp3aN5rMRyXEwJGmZvaWzeJFNTOXWlHQyBFCWrdj3fV/fsTOX8w== integrity sha512-s/iAeeWLk5BschUIpmdrF8RA8lhFZ/xDZgKw1Tan72oGws1/dFGB06nYEiyyssWUfjKNQTNRlrwMVjO9/hvXDw==
fill-range@^7.1.1: fill-range@^7.1.1:
version "7.1.1" version "7.1.1"