fxtwitter-docker/src/helpers/linkFixer.ts
2022-08-15 18:38:52 -04:00

15 lines
548 B
TypeScript

/* Helps replace t.co links with their originals */
export const linkFixer = (tweet: TweetPartial, text: string): string => {
if (typeof tweet.entities?.urls !== 'undefined') {
tweet.entities?.urls.forEach((url: TcoExpansion) => {
text = text.replace(url.url, url.expanded_url);
});
/* Remove any link with unavailable original.
This means that stuff like the t.co link to pic.twitter.com
will get removed in image/video Tweets */
text = text.replace(/ ?https:\/\/t\.co\/\w{10}/g, '');
}
return text;
};