0.0.4 • Published 6 years ago

pagination-parser v0.0.4

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

pagination-parser

A parser for GitHub API v3 style pagination information.


Installing

$ npm install --save pagination-parser 

Example

const link = `
  <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15>; rel="next",
  <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last",
  <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1>; rel="first",
  <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13>; rel="prev"
`;
const parsed = parser(link);

/*
{
  first: {
    num: 1,
    url: 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1',
  },
  last: {
    num: 34,
    url: 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34',
  },
  next: {
    num: 15,
    url: 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15',
  },
  prev: {
    num: 13,
    url: 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13',
  },
}
*/