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

Format returned storage bytes to human-readable digits #1038

Open
kasodon opened this issue Nov 28, 2022 · 0 comments
Open

Format returned storage bytes to human-readable digits #1038

kasodon opened this issue Nov 28, 2022 · 0 comments

Comments

@kasodon
Copy link

kasodon commented Nov 28, 2022

When calling the 'view_account' method, the returned account storage bytes should be parsed to a readable format.

I used a custom solution for a near-todo-app I'm currently working on. Here's it:
`formatNearBytes(b) {
const units = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];

let l = 0,
  n = parseInt(b, 10) || 0;

while (n >= 1024 && ++l) {
  n = n / 1024;
}

return n.toFixed(n < 10 && l > 0 ? 1 : 0) + " " + units[l];

}`

IMO, this should be native to the near-api-js format.ts lib

@github-project-automation github-project-automation bot moved this to Backlog 🥶 in DevRel Jun 10, 2024
@thisisjoshford thisisjoshford removed this from DevRel Oct 31, 2024
@github-project-automation github-project-automation bot moved this to NEW❗ in DevTools Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: NEW❗
Development

No branches or pull requests

1 participant