<commit_before>/*
Create a list of pagination pages. Returns an array of pages, possibly with
a `null` break item:

e.g. Pagination.pages({ currentPageNumber: 0, totalPages: 10, createPageLink })
[
  { pageNumber: 0, isCurrent: true, link: 'http://...' },
  { pageNumber: 1, isCurrent: false, link: 'http://...' },
  { pageNumber: 2, isCurrent: false, link: 'http://...' },
  { pageNumber: 3, isCurrent: false, link: 'http://...' },
  null,
  { pageNumber: 8, isCurrent: false, link: 'http://...' },
  { pageNumber: 9, isCurrent: false, link: 'http://...' }
]

`createPageLink` is a function that is passed the page object
{ pageNumber, isCurrent } and should return the URL to that page.
*/
exports.pages = (currentPageNumber, totalPages, opts) => {
  opts = opts || {};

  const createPageLink = opts.createPageLink;
  const maxLinks = opts.maxLinks || 6;

  if (totalPages - currentPageNumber - 1 < maxLinks) {
    const start = Math.max(0, totalPages - maxLinks);
    const end = Math.min(start + maxLinks, totalPages);

    return range(start, end)
      .map((n) => createPage(n, currentPageNumber, createPageLink));
  }

  return range(currentPageNumber, currentPageNumber + (maxLinks - 2))
    .map((n) => createPage(n, currentPageNumber, createPageLink))
    .concat([
      null,
      createPage(totalPages - 2, currentPageNumber, createPageLink),
      createPage(totalPages - 1, currentPageNumber, createPageLink)
    ]);
};

function createPage (pageNumber, currentPageNumber, createPageLink) {
  const page = { pageNumber, isCurrent: currentPageNumber === pageNumber };
<commit_msg>fix pagination.js documentation and add better numbers to previously go to<commit_after>/*
Create a list of pagination pages. Returns an array of pages, possibly with
a `null` break item:

e.g. Pagination.pages(currentPageNumber = 0, totalPages = 10, createPageLink = 'http://...' })
[
  { pageNumber: 0, isCurrent: true, link: 'http://...' },
  { pageNumber: 1, isCurrent: false, link: 'http://...' },
  { pageNumber: 2, isCurrent: false, link: 'http://...' },
  { pageNumber: 3, isCurrent: false, link: 'http://...' },
  null,
  { pageNumber: 8, isCurrent: false, link: 'http://...' },
  { pageNumber: 9, isCurrent: false, link: 'http://...' }
]

`createPageLink` is a function that is passed the page object
{ pageNumber, isCurrent } and should return the URL to that page.
*/
exports.pages = (currentPageNumber, totalPages, opts) => {
  opts = opts || {};

  const createPageLink = opts.createPageLink;
  const maxLinks = opts.maxLinks || 6;

  if (totalPages - currentPageNumber - 1 < maxLinks) {
    const start = Math.max(0, totalPages - maxLinks);
    const end = Math.min(start + maxLinks, totalPages);

    return range(start, end)
      .map((n) => createPage(n, currentPageNumber, createPageLink));
  }

  var prependedArray;
  if (currentPageNumber === 0) {
    prependedArray = [];
  } else if (currentPageNumber === 1) {
    prependedArray = [createPage(0, currentPageNumber, createPageLink)];
  } else {
    prependedArray = [0, 1].map(function (n) { return createPage(n, currentPageNumber, createPageLink); });
  }
  if (currentPageNumber > 2) {
    prependedArray = prependedArray.concat(null);
  }

  return prependedArray
    .concat(range(currentPageNumber, currentPageNumber + (maxLinks - 2))
    .map((n) => createPage(n, currentPageNumber, createPageLink)))
    .concat([
      null,
      createPage(totalPages - 2, currentPageNumber, createPageLink),
      createPage(totalPages - 1, currentPageNumber, createPageLink)
    ]);
};

function createPage (pageNumber, currentPageNumber, createPageLink) {
  const page = { pageNumber, isCurrent: currentPageNumber === pageNumber };

{'fraction_non_alphanumeric': 0.14702702702702702, 'fraction_numerical': 0.00972972972972973, 'mean_word_length': 3.8379084967320263, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2801040', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1123, 'n_words': 333}