File size: 364 Bytes
21dd449
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
/**
 * 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]));
}