blob: cb349ef610da46b54d9bd31bab18c8a80b4de0d6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
import type { Tweet } from "react-tweet/api";
export const getRawTweet = (tweet: string) => {
// Get the content inside the last <raw> tag, there can any number of <raw> tags in the tweet (or just one)
const rawTag = /<raw>(.*)<\/raw>/g;
const match = rawTag.exec(tweet);
if (match) {
return match[1];
}
return `{
"error": "No <raw> tag found"
}`;
};
export const getTweet = (tweet: string) => {
const rawTweet = getRawTweet(tweet);
try {
return JSON.parse(rawTweet) as Tweet;
} catch (e) {
return { error: "Error parsing tweet from text" };
}
};
|