Skip to content

Commit

Permalink
add format bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
thoriqazzikraa committed Jan 23, 2024
1 parent f0ec19e commit 7270640
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion function/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ function convertNum(number) {
return scaled.toFixed(1) + suffix
}

module.exports = { convertNum, convertSec, convertMs }
function formatBytes(bytes, decimals = 2) {
if (!+bytes) return "0 Bytes"
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
const i = Math.floor(Math.log(bytes) / Math.log(k))
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`
}

module.exports = { convertNum, convertSec, convertMs, formatBytes }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrape-websitee",
"version": "1.0.60",
"version": "1.0.61",
"description": "Website Scraping",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 7270640

Please sign in to comment.