Skip to content

madeinjam/parse-links

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Parse a Links header into a javascript object.

Install

$ npm install parse-links

Usage

var parseLinks = require('parse-links');
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"';
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(parseLinks.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' 
// }

console.log(parseLink.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"

Development

$ npm install -d

Testing

$ npm install -g mocha
$ mocha -u bdd -R spec

License

MIT!

About

Parse a Links header into a JavaScript object.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%