Skip to content

Commit 9232a22

Browse files
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>
1 parent 45a2fd9 commit 9232a22

3 files changed

Lines changed: 11 additions & 35 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
"emojibase-regex": "15.3.2",
118118
"escape-html": "^1.0.3",
119119
"file-saver": "^2.0.5",
120-
"filesize": "10.1.6",
120+
"filesize": "11.0.2",
121121
"github-markdown-css": "^5.5.1",
122122
"glob-to-regexp": "^0.4.1",
123123
"highlight.js": "^11.3.1",

src/utils/FileUtils.ts

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
77
Please 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";
2011
import { type MediaEventContent } from "matrix-js-sdk/src/types";
2112

2213
import { _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
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8108,10 +8108,10 @@ filelist@^1.0.4:
81088108
dependencies:
81098109
minimatch "^5.0.1"
81108110

8111-
filesize@10.1.6:
8112-
version "10.1.6"
8113-
resolved "https://registry.yarnpkg.com/filesize/-/filesize-10.1.6.tgz#31194da825ac58689c0bce3948f33ce83aabd361"
8114-
integrity sha512-sJslQKU2uM33qH5nqewAwVB2QgR6w1aMNsYUp3aN5rMRyXEwJGmZvaWzeJFNTOXWlHQyBFCWrdj3fV/fsTOX8w==
8111+
filesize@11.0.2:
8112+
version "11.0.2"
8113+
resolved "https://registry.yarnpkg.com/filesize/-/filesize-11.0.2.tgz#b7771e3836812582ad74b8a10d6eb0dc58c1ceda"
8114+
integrity sha512-s/iAeeWLk5BschUIpmdrF8RA8lhFZ/xDZgKw1Tan72oGws1/dFGB06nYEiyyssWUfjKNQTNRlrwMVjO9/hvXDw==
81158115

81168116
fill-range@^7.1.1:
81178117
version "7.1.1"

0 commit comments

Comments
 (0)