1.0.1 • Published 10 years ago
burl v1.0.1
burl
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'
// }