Socket
Socket
Sign inDemoInstall

@web3-storage/parse-link-header

Package Overview
Dependencies
Maintainers
6
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web3-storage/parse-link-header

Parses a link header and returns paging information for each contained link.


Version published
Maintainers
6
Created
Source

Parses a link header and returns paging information for each contained link.

Note: This is a fork of github.com/thlorenz/parse-link-header with zero dependencies, no Node.js globals and ESM.

Install

npm install @web3-storage/parse-link-header

Usage

import { parseLinkHeader } from '@web3-storage/parse-link-header'

const linkHeader =
  '<https://api.github.com/user/9287/repos?page=3&per_page=100>; rel="next", ' +
  '<https://api.github.com/user/9287/repos?page=1&per_page=100>; rel="prev"; pet="cat", ' +
  '<https://api.github.com/user/9287/repos?page=5&per_page=100>; rel="last"'

const parsed = parseLinkHeader(linkHeader)
console.log(parsed)
{ next:
   { page: '3',
     per_page: '100',
     rel: 'next',
     url: 'https://api.github.com/user/9287/repos?page=3&per_page=100' },
  prev:
   { page: '1',
     per_page: '100',
     rel: 'prev',
     pet: 'cat',
     url: 'https://api.github.com/user/9287/repos?page=1&per_page=100' },
  last:
   { page: '5',
     per_page: '100',
     rel: 'last',
     url: 'https://api.github.com/user/9287/repos?page=5&per_page=100' } }

API

parseLinkHeader(linkHeader: String, options?: Object): Object

Parses the given link header containing web links and returns an object keyed by the rel property that contains information about each link.

The following options are available to avoid redundantly parsing of extremely long (invalid) input:

  • maxHeaderLength: number - Sets the number of characters the input should be limited to - longer inputs will not be handled. Defaults to 2000.
  • throwOnMaxHeaderLengthExceeded: boolean - Defines behavior for when the PARSE_LINK_HEADER_MAXLEN parameter is exceeded. if true, an error will be thrown; if it's false/null/undefined, the function fails silently by returning null. Defaults to false.

The purpose of this module is to parse the link header information. To format an object generated by this module back to the link header string, use the format-link-header module.

Keywords

FAQs

Package last updated on 23 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc