パッケージの詳細

li

jfromaniello1.8mMIT1.3.0

Parse the Links header format and return a javascript object.

links, http

readme

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

更新履歴

1.1.0

  • Fixed issue where links with commas cause unexpected results (Lukepur)
  • Fixed issue where links with semicolons cause unexpected results (Znarkus)
  • Refactor library (Znarkus)