Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getArrayPages when limit is more than no of pages #38

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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