Skip to content
forked from jfromaniello/li

JavaScript utility to parse and generate the Link header according to RFC 5988.

Notifications You must be signed in to change notification settings

mathieudutour/li

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Parse and format Link header according to RFC 5988.

Install

$ npm install li

Also works with bower, component.js, browserify, amd, etc.

Usage

Parse a Link header:

var li = require('li');
var someLinksHeader = '</api/users?page=0&per_page=2>; rel="first", ' +
                      '</api/users?page=1&per_page=2>; rel="next", ' +
                      '</api/users?page=3&per_page=2>; rel="last"';

console.log(li.parse(someLinksHeader));

// This will print:
// {
//   first: '/api/users?page=0&per_page=2',
//   next: '/api/users?page=1&per_page=2',
//   last: '/api/users?page=3&per_page=2'
// }

Generate a Link header as follow with stringify:

var linksObject = {
  first : '/api/users?page=0&per_page=2',
  next  : '/api/users?page=1&per_page=2',
  last  : '/api/users?page=3&per_page=2',
};

console.log(li.stringify(linksObject);

// This will print the string:
// </api/users?page=0&per_page=2>; rel="first",
// </api/users?page=1&per_page=2>; rel="next",
// </api/users?page=3&per_page=2>; rel="last"

Testing

$ npm test

License

MIT 2014 - JOSE F. ROMANIELLO

About

JavaScript utility to parse and generate the Link header according to RFC 5988.

Resources

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages

  • JavaScript 100.0%