Skip to content

Commit

Permalink
* helpers: support for converting bytes of str without ends "B".
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Dec 13, 2024
1 parent d651f55 commit 3f73bb3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/helpers/src/format-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export function formatBytes(size: number, fixed = 2, unit?: keyof typeof BYTE_UN
export const convertBytes = (str: string) => {
const pattern = /^[0-9]*(B|KB|MB|GB|TB)$/;
str = str.toUpperCase();
if (!str.endsWith('B')) {
str += 'B';
}
const matchRes = str.match(pattern);
if (!matchRes) {
return 0;
Expand Down

0 comments on commit 3f73bb3

Please sign in to comment.