From de43cd8ecbb97b00b696460ec9cf80d5916c5bf4 Mon Sep 17 00:00:00 2001 From: Rajiv Narayana Singaseni Date: Tue, 25 Jul 2017 01:58:13 +0530 Subject: [PATCH] Fix getArrayPages when limit is more than no of pages --- index.js | 2 +- test/index-test.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index ddc76e0..993b8e2 100644 --- a/index.js +++ b/index.js @@ -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++) { diff --git a/test/index-test.js b/test/index-test.js index 81cefde..6cf9526 100644 --- a/test/index-test.js +++ b/test/index-test.js @@ -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);