mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-11 13:30:53 +01:00
Add number formatting (#148)
This commit is contained in:
parent
d08d56a718
commit
d37812bd4d
3 changed files with 14 additions and 6 deletions
|
@ -1,16 +1,18 @@
|
|||
import { formatNumber } from "./utils";
|
||||
|
||||
/* The embed "author" text we populate with replies, retweets, and likes unless it's a video */
|
||||
export const getAuthorText = (tweet: APITweet): string | null => {
|
||||
/* Build out reply, retweet, like counts */
|
||||
if (tweet.likes > 0 || tweet.retweets > 0 || tweet.replies > 0) {
|
||||
let authorText = '';
|
||||
if (tweet.replies > 0) {
|
||||
authorText += `${tweet.replies} 💬 `;
|
||||
authorText += `${formatNumber(tweet.replies)} 💬 `;
|
||||
}
|
||||
if (tweet.retweets > 0) {
|
||||
authorText += `${tweet.retweets} 🔁 `;
|
||||
authorText += `${formatNumber(tweet.retweets)} 🔁 `;
|
||||
}
|
||||
if (tweet.likes > 0) {
|
||||
authorText += `${tweet.likes} ❤️ `;
|
||||
authorText += `${formatNumber(tweet.likes)} ❤️ `;
|
||||
}
|
||||
authorText = authorText.trim();
|
||||
|
||||
|
|
|
@ -14,3 +14,7 @@ export const unescapeText = (text: string) => {
|
|||
.replace(/>/g, '>')
|
||||
.replace(/&/g, '&');
|
||||
};
|
||||
|
||||
const numberFormat = new Intl.NumberFormat('en-US');
|
||||
|
||||
export const formatNumber = (num: number) => numberFormat.format(num)
|
|
@ -1,6 +1,6 @@
|
|||
import { Constants } from './constants';
|
||||
import { handleQuote } from './helpers/quote';
|
||||
import { sanitizeText } from './helpers/utils';
|
||||
import { formatNumber, sanitizeText } from './helpers/utils';
|
||||
import { Strings } from './strings';
|
||||
import { getAuthorText } from './helpers/author';
|
||||
import { statusAPI } from './api';
|
||||
|
@ -272,9 +272,11 @@ export const handleStatus = async (
|
|||
});
|
||||
|
||||
/* Finally, add the footer of the poll with # of votes and time left */
|
||||
str += `\n${poll.total_votes} votes · ${poll.time_left_en}`;
|
||||
str += `\n${formatNumber(poll.total_votes)} votes · ${poll.time_left_en}`;
|
||||
|
||||
/* Check if the poll is ongoing and apply low TTL cache control */
|
||||
/* Check if the poll is ongoing and apply low TTL cache control.
|
||||
Yes, checking if this is a string is a hacky way to do this, but
|
||||
it can do it in way less code than actually comparing dates */
|
||||
if (poll.time_left_en !== 'Final results') {
|
||||
cacheControl = Constants.POLL_TWEET_CACHE;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue