# @web3-storage/parse-link-header

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

Latest version **3.1.0** (published 2022-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @web3-storage/parse-link-header
pnpm add @web3-storage/parse-link-header
yarn add @web3-storage/parse-link-header
bun add @web3-storage/parse-link-header
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2022-02-23 |
| First published | 2022-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Thorsten Lorenz |
| Maintainers | sefnap, olizilla, hugomrdias, vascosantos, alanshaw, ipfsbot |
| Keywords | parse, link, header, weblink, web, link, rel |

## Links

- npm: https://www.npmjs.com/package/@web3-storage/parse-link-header
- Repository: https://github.com/web3-storage/parse-link-header
- Issues: https://github.com/web3-storage/parse-link-header/issues
- npm.io page: https://npm.io/package/@web3-storage/parse-link-header

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2022-02-23
- 3.0.1 — 2022-02-23
- 3.0.0 — 2022-02-23

## README

# parse-link-header

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

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

## Install

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

## Usage

```js
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)
```

```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' } }
```

## API

`parseLinkHeader(linkHeader: String, options?: Object): 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.

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`.

### 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.

---
_Source: https://npm.io/package/@web3-storage/parse-link-header · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
