forked from imksoo/nostr-filter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nostr-util.ts
43 lines (39 loc) · 1.14 KB
/
nostr-util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
export const extractHashtags = (tags: string[][]): string[] => {
return tags.filter((tag) => String(tag[0]) === "t").map((tag) => String(tag[1]));
};
export const isActivityPubUser = (tags: string[][]): boolean => {
for (let index = 0; index < tags.length; index++) {
const tag = tags[index];
if (tag.length === 3 && String(tag[0]) === "proxy" && String(tag[2]) === "activitypub") {
return true;;
}
}
return false;
};
export const isRootPost = (tags: string[][]): boolean => {
for (let index = 0; index < tags.length; index++) {
const tag = tags[index];
if (String(tag[0]) === "e") {
return false;
}
}
return true;
};
export const hasContentWarning = (tags: string[][]): boolean => {
for (let index = 0; index < tags.length; index++) {
const tag = tags[index];
if (String(tag[0]) === "content-warning") {
return true;
}
}
return false;
};
export const hasNsfwHashtag = (hashtags: string[]): boolean => {
for (let index = 0; index < hashtags.length; index++) {
const tag = String(hashtags[index]).toLowerCase();
if (tag === "nsfw") {
return true;
}
}
return false;
};