This commit is contained in:
2023-09-19 13:03:29 +01:00
parent 1c52db933f
commit dde730238d
12 changed files with 138 additions and 151 deletions

View File

@ -0,0 +1,26 @@
import { ReqFilter } from "nostr";
/**
* Remove empty filters, filters which would result in no results
*/
export function trimFilters(filters: Array<ReqFilter>) {
const fNew = [];
for(const f of filters) {
let arrays = 0;
for(const [k, v] of Object.entries(f)) {
if(Array.isArray(v)) {
arrays++;
if(v.length === 0) {
delete f[k];
}
}
}
if(arrays > 0 && Object.entries(f).some(v => Array.isArray(v))) {
fNew.push(f);
} else if(arrays === 0) {
fNew.push(f);
}
}
return fNew;
}