1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export const paginateAPI = async (
url: string,
options: Parameters<typeof fetch>[1],
) => {
let result: any[] = [];
let nextUrl = url;
while (nextUrl) {
const { data, links } = await fetchJSON(
nextUrl,
options,
);
result = result.concat(data);
nextUrl = links.next;
}
return result;
};