UNPKG

@cutls/megalodon

Version:

Mastodon, Pleroma, Misskey API client for node.js and browser

18 lines (17 loc) 476 B
export function parseLinkHeader(header) { var links = {} if (header.length === 0) { throw new Error('input must not be of zero length') } var parts = header.split(',') parts.forEach((part) => { var section = part.split(';') if (section.length !== 2) { throw new Error("section could not be split on ';'") } var url = section[0].replace(/<(.*)>/, '$1').trim() var name = section[1].replace(/rel="(.*)"/, '$1').trim() links[name] = url }) return links }