Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
parse-link-header
Advanced tools
Parses a link header and returns paging information for each contained link.
The parse-link-header npm package is used to parse HTTP link headers, which are commonly used for pagination in APIs. It converts the link header string into a more manageable JavaScript object.
Parsing Link Headers
This feature allows you to parse a link header string into a JavaScript object. The example demonstrates parsing a GitHub API link header for pagination.
const parse = require('parse-link-header');
const linkHeader = '<https://api.github.com/user/repos?page=2&per_page=100>; rel="next", <https://api.github.com/user/repos?page=5&per_page=100>; rel="last"';
const parsed = parse(linkHeader);
console.log(parsed);
The http-link-header package provides similar functionality to parse-link-header by parsing HTTP link headers into a JavaScript object. It also offers additional methods to manipulate and format link headers.
The link-header-parser package is another alternative that parses HTTP link headers. It focuses on simplicity and ease of use, providing a straightforward API for parsing link headers.
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' } }
npm install parse-link-header
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.
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
.
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.
FAQs
Parses a link header and returns paging information for each contained link.
The npm package parse-link-header receives a total of 848,067 weekly downloads. As such, parse-link-header popularity was classified as popular.
We found that parse-link-header demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.