Render like count textually.

This commit is contained in:
FireMasterK 2021-05-31 03:36:35 +05:30
parent ee74fd5b62
commit 783246abcd
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58
2 changed files with 17 additions and 1 deletions

View file

@ -63,7 +63,7 @@
</div>
<p>{{ comment.commentText }}</p>
<div>
<b>{{ comment.likeCount }}</b>
<b>{{ numberFormat(comment.likeCount) }}</b>
&nbsp;
<font-awesome-icon icon="thumbs-up"></font-awesome-icon>
&nbsp;

View file

@ -33,6 +33,22 @@ const mixin = {
return str;
},
numberFormat(num) {
const digits = 2;
const si = [
{ value: 1, symbol: "" },
{ value: 1E3, symbol: "k" },
{ value: 1E6, symbol: "M" },
{ value: 1E9, symbol: "B" }
];
const rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
for (var i = si.length - 1; i > 0; i--) {
if (num >= si[i].value) {
break;
}
}
return (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol;
},
fetchJson: function (url, options) {
return fetch(url, options).then(response => {
return response.json();