Add a few tag functions
This commit is contained in:
@@ -8,9 +8,18 @@ export const getTags = (types: string | string[], tags: string[][]) => {
|
||||
return tags.filter(t => types.includes(t[0]))
|
||||
}
|
||||
|
||||
export const getTag = (types: string | string[], tags: string[][]) => {
|
||||
types = ensurePlural(types)
|
||||
|
||||
return tags.find(t => types.includes(t[0]))
|
||||
}
|
||||
|
||||
export const getTagValues = (types: string | string[], tags: string[][]) =>
|
||||
getTags(types, tags).map(nth(1))
|
||||
|
||||
export const getTagValue = (types: string | string[], tags: string[][]) =>
|
||||
getTag(types, tags)?.[1]
|
||||
|
||||
export const getEventTags = (tags: string[][]) =>
|
||||
tags.filter(t => ["e"].includes(t[0]) && t[1].length === 64)
|
||||
|
||||
@@ -26,9 +35,9 @@ export const getPubkeyTags = (tags: string[][]) =>
|
||||
|
||||
export const getPubkeyTagValues = (tags: string[][]) => getPubkeyTags(tags).map(nth(1))
|
||||
|
||||
export const getTopicTags = (tags: string[][]) => tags.filter(t => ["t"].includes(t[0]))
|
||||
export const getTopicTags = (tags: string[][]) => tags.filter(nthEq(0, "t"))
|
||||
|
||||
export const getTopicTagValues = (tags: string[][]) => getTopicTags(tags).map(nth(1))
|
||||
export const getTopicTagValues = (tags: string[][]) => getTopicTags(tags).map(t => t[1].replace(/^#/, ''))
|
||||
|
||||
export const getRelayTags = (tags: string[][]) =>
|
||||
tags.filter(t => ["r", "relay"].includes(t[0]) && isRelayUrl(t[1] || ""))
|
||||
@@ -88,3 +97,5 @@ export const getRelayHints = (tags: string[][]) =>
|
||||
uniq(tags.flatMap(t => t.slice(2).filter(isShareableRelayUrl)))
|
||||
|
||||
export const uniqTags = (tags: string[][]) => uniqBy(t => t.join(":"), tags)
|
||||
|
||||
export const tagsFromIMeta = (imeta: string[]) => imeta.map((m: string) => m.split(" "))
|
||||
|
||||
Reference in New Issue
Block a user