{"size": 3170, "ext": "js", "max_stars_repo_path": "public/javascripts/paginate.js", "max_stars_repo_name": "knoldus/knolx-portal", "max_stars_repo_stars_event_min_datetime": "2017-12-05T12:33:30.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-09T08:49:26.000Z", "max_issues_repo_path": "public/javascripts/paginate.js", "max_issues_repo_name": "knoldus/knolx-portal", "max_issues_repo_issues_event_min_datetime": "2017-06-12T08:48:16.000Z", "max_issues_repo_issues_event_max_datetime": "2019-11-27T11:04:18.000Z", "max_forks_repo_path": "public/javascripts/paginate.js", "max_forks_repo_name": "knoldus/knolx-portal", "max_forks_repo_forks_event_min_datetime": "2017-06-06T08:20:01.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-26T16:49:28.000Z"}
{"max_stars_count": 6, "max_issues_count": 109, "max_forks_count": 5, "avg_line_length": 37.2941176471, "max_line_length": 141, "alphanum_fraction": 0.5369085174}
function paginate(pageNumber, pages) {
    var pagination = "";
    if (pages >= pageNumber) {
        switch (true) {
            case (pages > 5 && pageNumber < 5) : {
                pagination += reducedFromIterator(1, 5, pageNumber, 0);
                pagination += dots();
                pagination += inActiveList(pages);
                break;
            }
            case (pages <= 5 && pageNumber <= 5) :
                pagination += reducedFromIterator(1, pages, pageNumber, 0);
                break;
            case (pages > 5 && pageNumber >= 5 && pages == pageNumber) : {
                pagination += reverseIterator(5, 1, pageNumber, pages);
                pagination += dots();
                pagination += pageNumber == pages ? activeList(pages) : inActiveList(pages);
                break;
            }
            case (pages > 5 && pageNumber >= 5 && pageNumber < pages - 2)  : {
                pagination += reverseIterator(2, 0, pageNumber, pageNumber);
                for (var iterator = 1; iterator <= 2; iterator++) {
                    pagination += fromIterator(pageNumber, (pageNumber + iterator));
                }
                pagination += dots();
                pagination += inActiveList(pages);
                break;
            }
            case (pages > 5 && pageNumber >= 5 && pageNumber == pages - 2)      : {
                pagination += reverseIterator(3, 0, pageNumber, pageNumber);
                pagination += pageNumber == (pageNumber + 1) ? activeList((pageNumber + 1)) : inActiveList((pageNumber + 1));
                pagination += dots();
                pagination += inActiveList(pages);
                break;
            }
            case (pages > 5 && pageNumber >= 5 && pageNumber > pages - 2 && pageNumber != pages) : {
                pagination += reverseIterator(4, 0, pageNumber, pageNumber);
                pagination += dots();
                pagination += inActiveList(pages);
                break;
            }
        }
    }

    $('.pagination').html(pagination);
}

function activeList(value) {
    return "<li class='active'><a  class='paginate' id='" + value + "'>" + value + "</a></li>"
}

function inActiveList(value) {
    return "<li class='inactive'><a  class='paginate' id='" + value + "'>" + value + "</a></li>"
}

function dots() {
    return "<li class='inactive'><a>...</a></li>";
}

function reverseIterator(from, till, pageNumber, compareWith) {
    var pagination = "";

    for (var iterator = from; iterator >= till; iterator--) {
        pagination += pageNumber == (compareWith - iterator) ? activeList((compareWith - iterator)) : inActiveList((compareWith - iterator));
    }

    return pagination;
}

function fromIterator(pageNumber, compareWith) {
    var pagination = "";
    pagination += pageNumber == compareWith ? activeList(compareWith) : inActiveList(compareWith);
    return pagination;
}

function reducedFromIterator(from, till, pageNumber, offset) {
    var pagination = "";

    for (var iterator = from; iterator <= till; iterator++) {
        pagination += fromIterator(pageNumber, (offset + iterator));
    }

    return pagination;
}
