js-hub / utils /parseLinkHeader.ts
coyotte508's picture
coyotte508 HF Staff
Add 1 files
21dd449 verified
/**
* Parse Link HTTP header, eg `<https://huggingface.co/api/datasets/bigscience/P3/tree/main?recursive=1&cursor=...>; rel="next"`
*/
export function parseLinkHeader(header: string): Record<string, string> {
const regex = /<(https?:[/][/][^>]+)>;\s+rel="([^"]+)"/g;
return Object.fromEntries([...header.matchAll(regex)].map(([, url, rel]) => [rel, url]));
}