paginatorjs
v0.0.2
Published
paginator facade for node
Downloads
18
Readme
#Paginator ##Pagination facade for node
install via npm npm install --save paginatorjs
###Create a paginator object.
paginator = require('paginator')({
get: function (start, numberOfResults, done, error) {
if(start > 8) {
error({
message: 'test getPage error'
});
}
else {
done(_.range(8).splice(start, numberOfResults));
}
},
count: function (done, error) {
if(throwCountError) {
error({
message: 'test getNumberOfPages error'
});
}
else {
done(8);
}
},
resultsPerPage: 3
});
###promise getPage(pageNumber, successCallback, errorCallback)
paginator.getPage(
1,
function (results) {
test.deepEqual(results, [0, 1, 2]);
},
function (err) {
test.deepEqual(err, { message: 'test getPage error' });
}
);
###promise getNumberOfPages(successCallback, errorCallback)
paginator.getNumberOfPages(
function (numberOfPages) {
test.deepEqual(numberOfPages, 3);
},
function (err) {
test.deepEqual(err, { message: 'test getNumberOfPages error' });
}
);
Both methods can alternatively be used with Q promises
paginator.getPage(1)
.then(function (results) {
test.deepEqual(results, [0, 1, 2]);
})
.catch(function (err) {
test.deepEqual(err, { message: 'test getPage error' });
});