Skip to content

Commit

Permalink
use intl formatter if available
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Sep 12, 2022
1 parent 62af2c4 commit 7e181cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "canvacord",
"version": "5.4.6",
"version": "5.4.7",
"description": "Powerful image manipulation package for beginners.",
"main": "index.js",
"types": "typings/index.d.ts",
Expand Down Expand Up @@ -53,7 +53,7 @@
},
"homepage": "https://canvacord.js.org",
"dependencies": {
"@napi-rs/canvas": "^0.1.26",
"@napi-rs/canvas": "^0.1.29",
"@skyra/gifenc": "^1.0.0",
"chalk": "^5.0.1",
"moment": "^2.29.4",
Expand Down
29 changes: 17 additions & 12 deletions plugins/abbrev.js
@@ -1,19 +1,24 @@
module.exports = num => {
if (!num || isNaN(num)) return "0";
if (typeof num === "string") num = parseInt(num);
let decPlaces = Math.pow(10, 1);
var abbrev = ["K", "M", "B", "T"];
for (var i = abbrev.length - 1; i >= 0; i--) {
var size = Math.pow(10, (i + 1) * 3);
if (size <= num) {
num = Math.round((num * decPlaces) / size) / decPlaces;
if (num == 1000 && i < abbrev.length - 1) {
num = 1;
i++;

if (typeof Intl !== "undefined") {
return new Intl.NumberFormat("en", { notation: "compact" }).format(num);
} else {
let decPlaces = Math.pow(10, 1);
var abbrev = ["K", "M", "B", "T"];
for (var i = abbrev.length - 1; i >= 0; i--) {
var size = Math.pow(10, (i + 1) * 3);
if (size <= num) {
num = Math.round((num * decPlaces) / size) / decPlaces;
if (num == 1000 && i < abbrev.length - 1) {
num = 1;
i++;
}
num += abbrev[i];
break;
}
num += abbrev[i];
break;
}
return `${num}`;
}
return `${num}`;
};

0 comments on commit 7e181cb

Please sign in to comment.