feat: read nip-58 badges (#394)

This commit is contained in:
Alejandro
2023-03-09 11:13:10 +01:00
committed by GitHub
parent 2f20d03e2b
commit cd4dcbd0a2
12 changed files with 282 additions and 22 deletions

View File

@ -397,3 +397,22 @@ export function magnetURIDecode(uri: string): Magnet | undefined {
console.warn("Failed to parse magnet link", e);
}
}
export function chunks<T>(arr: T[], length: number) {
const result = [];
let idx = 0;
let n = arr.length / length;
while (n > 0) {
result.push(arr.slice(idx, idx + length));
idx += length;
n -= 1;
}
return result;
}
export function findTag(e: TaggedRawEvent, tag: string) {
const maybeTag = e.tags.find(evTag => {
return evTag[0] === tag;
});
return maybeTag && maybeTag[1];
}