Compute hal-json:_links previous and next values. Useful when urls need
to be processed before being ready to use.
npm install burl
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'
// }
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];
}
});
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 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'
// }