Skip to content

Commit

Permalink
Merge pull request #38 from rajivnarayana/master
Browse files Browse the repository at this point in the history
Fix getArrayPages when limit is more than no of pages
  • Loading branch information
niftylettuce authored Jul 25, 2017
2 parents 3d28d8b + de43cd8 commit 53c3a84
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ exports.getArrayPages = function(req) {

if (limit > 0) {
var end = Math.min(Math.max(currentPage + Math.floor(limit / 2), limit), pageCount);
var start = (currentPage < (limit - 1)) ? 1 : (end - limit) + 1;
var start = Math.max(1, (currentPage < (limit - 1)) ? 1 : (end - limit) + 1);

var pages = [];
for (var i = start; i <= end; i++) {
Expand Down
3 changes: 2 additions & 1 deletion test/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ describe('paginate', function () {
})

it('it should contain correct page numbers and page urls', function () {
pages.forEach(function (p, i) {
//Limit is more than total pages
paginate.getArrayPages(this.req)(4,3,3).forEach(function (p, i) {
// index from 1
var idx = i + 1;
p.number.should.equal(idx);
Expand Down

0 comments on commit 53c3a84

Please sign in to comment.