1. parse-link-header
Parses a link header and returns paging information for each contained link.
parse-link-header
Package: parse-link-header
Created by: thlorenz
Last modified: Thu, 23 Jun 2022 10:50:07 GMT
Version: 2.0.0
License: MIT
Downloads: 3,966,531
Repository: https://github.com/thlorenz/parse-link-header

Install

npm install parse-link-header
yarn add parse-link-header

parse-link-header build status

testling badge

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

 var parse = require('parse-link-header');

var 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"'

var parsed = parse(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' } }

Installation

npm install parse-link-header

API

parseLinkHeader(linkHeader : String) : Object

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

Environmental Variables

To avoid redundantly parsing of extremely long (invalid) input, the package uses 2 env variabes:

PARSE_LINK_HEADER_MAXLEN - Sets the number of characters the input should be limited to - longer inputs will not be handled. Defaults to 2000.

PARSE_LINK_HEADER_THROW_ON_MAXLEN_EXCEEDED - Defines behavior for when the PARSE_LINK_HEADER_MAXLEN parameter is exceeded. if defined, an error will be thrown; if it's null, the function fails silently by returning null. Defaults to null.

Formatting a link header

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.

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code