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

Any plans for a file size filter? #79

Closed
xJREB opened this issue Dec 3, 2019 · 5 comments
Closed

Any plans for a file size filter? #79

xJREB opened this issue Dec 3, 2019 · 5 comments

Comments

@xJREB
Copy link
Contributor

xJREB commented Dec 3, 2019

I was wondering if a file size filter would be a welcome addition. We use such a filter in some projects. Maybe we could outsource it here?

This is the function we are currently using:

// Convert a fileSize in bytes to a human readable string
export const fileSizeFilter = (sizeInBytes: number): string => {
  if (sizeInBytes >= 1024 * 1024 * 1024) {
    // GB
    return `${(sizeInBytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
  } else if (sizeInBytes >= 1024 * 1024) {
    // MB
    return `${(sizeInBytes / (1024 * 1024)).toFixed(2)} MB`;
  } else if (sizeInBytes >= 1024) {
    // kb
    return `${Math.round(sizeInBytes / 1024)} kb`;
  }
  // byte
  return `${sizeInBytes} byte`;
};

Feel free to make suggestions for improvement. If you think this is a good idea, I'll happily provide a pull request.

@freearhey
Copy link
Owner

I think it's a great idea 👍

I would only add the ability to change the number of digits after the decimal point. Otherwise, everything looks fine to me.

@freearhey
Copy link
Owner

I just published a beta version of the library with a new filter to npm - v0.9.0-beta.0

Basically it's the same code that you sent me, I just replaced the filter name with a more general bytes and added the ability to set the number of digits after the decimal point globally.

It would be great if you could check out this version and if everything is okay then I will publish a new release.

@xJREB
Copy link
Contributor Author

xJREB commented Dec 10, 2019

Sorry for the late response! The bytes filter worked nicely for me. I think you can publish a non-beta realease with it.

@freearhey
Copy link
Owner

Done. Release v0.9.0 is available for download.

Thanks for your help!

@xJREB
Copy link
Contributor Author

xJREB commented Dec 12, 2019

My pleasure! I may even provide some suggestions for additional filters in the future... 🙃

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

No branches or pull requests

2 participants