npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

burl

1.0.1

@yoshuawuyts

npmHomeRepoSnykSocket
Downloads:0
$ npm install burl
DailyWeeklyMonthlyYearly

burl

NPM version build status Test coverage Downloads

Compute hal-json:_links previous and next values. Useful when urls need to be processed before being ready to use.

Installation

npm install burl

Usage

var burl = require('burl');

var links = burl({
  next: function(val) {
    return 'http://mysite.com/api?from=' + val;
  },
  previous: function(val) {
    return 'http://mysite.com/api?until=' + val;
  },
  normalize: function(val) {
    return val.splice(13)[1];
  }
});

links.set({
  previous: 'until=12345677',
  next: 'from=12345677'
});

links.get();
// => {
//   previous: 'http://mysite.com/api?until=12345677',
//   next: 'http://mysite.com/api?from=12345677'
// }

API

var links = burl()

Create a new burl instance. Takes a single option with optional previous, next and normalize functions. The functions must return their containing value.

var burl = require('burl');

var links = burl({
  next: function(val) {
    return 'http://mysite.com/api?from=' + val;
  },
  previous: function(val) {
    return 'http://mysite.com/api?until=' + val;
  },
  normalize: function(val) {
    return val.splice(13)[1];
  }
});

.set()

Save links to burl. Gets passed through the normalize function before performing a comparison to keep the lowest value for previous and the heighest value for next. Uses linkstash under the hood.

links.set({
  previous: 'until=12345677',
  next: 'from=12345677'
});

.get()

Get the composed urls for previous and next back in an object.

links.get();
// => {
//   previous: 'http://mysite.com/api?until=12345677',
//   next: 'http://mysite.com/api?from=12345677'
// }

See also

  • linkstash
  • burl-invert

License

MIT