Have ideas to improve npm?Join in the discussion! »

    li

    1.3.0 • Public • Published

    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

    Keywords

    Install

    npm i li

    DownloadsWeekly Downloads

    296,940

    Version

    1.3.0

    License

    MIT

    Last publish

    Collaborators

    • avatar