ParseLink.js 455 B

12345678910111213141516171819
  1. function parse(linkHeader) {
  2. if (!linkHeader) return {};
  3. const links = linkHeader.split(/,\s*</);
  4. return links.reduce((acc, link) => {
  5. const matcher = link.match(/<?([^>]*)>(.*)/);
  6. if (!matcher) return {};
  7. const linkUrl = matcher[1];
  8. const rel = matcher[2].match(/\s*(.+)\s*=\s*"?([^"]+)"?/);
  9. if (rel) {
  10. acc[rel[2]] = linkUrl;
  11. }
  12. return acc;
  13. }, {});
  14. }
  15. export default parse;
  16. //# sourceMappingURL=ParseLink.js.map