Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/parse-link-header
Parses a link header and returns paging information for each contained link.
https://github.com/thlorenz/parse-link-header
Last synced: about 14 hours ago
JSON representation
Parses a link header and returns paging information for each contained link.
- Host: GitHub
- URL: https://github.com/thlorenz/parse-link-header
- Owner: thlorenz
- License: mit
- Created: 2013-06-07T11:01:54.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-02-09T19:41:22.000Z (almost 2 years ago)
- Last Synced: 2025-01-18T08:06:37.170Z (8 days ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 301
- Watchers: 6
- Forks: 27
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- project-awesome - thlorenz/parse-link-header - Parses a link header and returns paging information for each contained link. (JavaScript)
README
# parse-link-header [![build status](https://secure.travis-ci.org/thlorenz/parse-link-header.png)](http://travis-ci.org/thlorenz/parse-link-header)
[![testling badge](https://ci.testling.com/thlorenz/parse-link-header.png)](https://ci.testling.com/thlorenz/parse-link-header)
Parses a link header and returns paging information for each contained link.
```js
var parse = require('parse-link-header');var linkHeader =
'; rel="next", ' +
'; rel="prev"; pet="cat", ' +
'; rel="last"'var parsed = parse(linkHeader);
console.log(parsed);
``````js
{ 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](http://tools.ietf.org/html/rfc5988) 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 variables:
`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](https://github.com/jonathansamines/format-link-header) module.