Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

format-link-header

2.1.0 • Public • Published

format-link-header

Build Status

Allows to format a given links ref object, to the format as described in RFC 5988. Precisely it achieves the exactly inverse process performed by the parse-link-header.

Installation

  npm install --save format-link-header

Usage

  1. Given a links refs object generated by parse-link-header:
  const link = {
    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'
    }
  }
  1. Format the link header
  const formatter = require('format-link-header');
  const linkHeaderString = formatter(link);
  1. Web link headers generated!
  <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"

install

npm i format-link-header

Downloadsweekly downloads

1,209

version

2.1.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability