Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use Intl byte formatter #13988

Closed
wants to merge 2 commits into from

Conversation

privatenumber
Copy link
Sponsor Contributor

Description

Use built-in byte formatter. Opened a PR as per #13949 (comment)

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@stackblitz
Copy link

stackblitz bot commented Jul 30, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev
Copy link
Member

Thanks for the PR @privatenumber. As it stands, IMO we should keep the current formatter though. Maybe there is a way to configure it further though:

  • Using B instead of KB for smaller values. This is good, but it makes the sizes harder to read (0.84 kB -> 842.0B)
  • Removing trailing zeros, affecting alignment (1.20 kB -> 1.2KB`)
  • No separation between number and unit (1.29 kB -> 1.29KB)

Current one:
image

This PR:
image

@privatenumber
Copy link
Sponsor Contributor Author

Thanks for the specific feedback.

I believe I managed to address them:

return `${numberFormatter.format(bytes / 1000)} kB`
}
}).format
const formatBytes = (bytes: number) => formatter(bytes / 1000)
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're only showing in kB and opting out of leveraging other units, it kinda begs the question why we need to pass in 3 more NumberFormat options when we can just append kB at the end and call it a day.

I think the real value in using NumberFormat is it converts the value to the appropriate unit, which we don't need here.

I'm also okay with scrapping this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you here. Let's keep the current one for now then. Thanks for sending the PR again, though, I think it was good to explore this option.

@patak-dev
Copy link
Member

Closing for now, see #13988 (comment)

@patak-dev patak-dev closed this Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants