npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ultimate-pagination

v1.0.0

Published

Universal pagination model generation algorithm that can be used to build a UI component

Downloads

134,004

Readme

ultimate-pagination logo

ultimate-pagination

NPM version Downloads Build Status

Universal pagination model generation algorithm that can be used to build a UI component for any JavaScript based platform/framework. The idea behind this module is to move the logic of creating pagination out of the component and place it in a separate module. It allows reusing the same code across different frameworks like Angular, Angular2, React, Ember, etc. Also, the same code can be used to generate pagination on server-side JavaScript frameworks.

Integrations

Here is a list of modules that uses ultimate-pagination to implement pagination components with different frameworks:

Installation

You can install this module via npm:

npm install ultimate-pagination --save

Usage

The main method of ultimate-pagination module is getPaginationModel(options). It accepts an object with properties:

  • currentPage (number) - current page number
  • totalPages (number) - total number of pages
  • boundaryPagesRange (number, optional, default: 1) - number of always visible pages at the beginning and end
  • siblingPagesRange (number, optional, default: 1) - number of always visible pages before and after the current one
  • hideEllipsis (boolean, optional, default: false) - boolean flag to hide ellipsis
  • hidePreviousAndNextPageLinks (boolean, optional, default: false) - boolean flag to hide previous and next page links
  • hideFirstAndLastPageLinks (boolean, optional, default: false) - boolean flag to hide first and last page links
var ultimatePagination = require('ultimate-pagination');

var paginationModel = ultimatePagination.getPaginationModel({
  // Required
  currentPage: 5,
  totalPages: 10,

  // Optional
  boundaryPagesRange: 1,
  siblingPagesRange: 1,
  hideEllipsis: false,
  hidePreviousAndNextPageLinks: false,
  hideFirstAndLastPageLinks: false
});

As a result getPaginationModel(options) returns an array of items that can be used to render a pagination component:

[
  {
    type: ITEM_TYPES.FIRST_PAGE_LINK,
    key: ITEM_KEYS.FIRST_PAGE_LINK,
    value: 1,
    isActive: false
  },
  {
    type: ITEM_TYPES.PREVIOUS_PAGE_LINK,
    key: ITEM_KEYS.PREVIOUS_PAGE_LINK,
    value: 4,
    isActive: false
  },
  {
    type: ITEM_TYPES.PAGE,
    key: 1,
    value: 1,
    isActive: false
  },
  {
    type: ITEM_TYPES.ELLIPSIS,
    key: ITEM_KEYS.FIRST_ELLIPSIS,
    value: 3,
    isActive: false
  },
  {
    type: ITEM_TYPES.PAGE,
    key: 4,
    value: 4,
    isActive: false
  },
  {
    type: ITEM_TYPES.PAGE,
    key: 5,
    value: 5,
    isActive: true
  },
  {
    type: ITEM_TYPES.PAGE,
    key: 6,
    value: 6,
    isActive: false
  },
  {
    type: ITEM_TYPES.ELLIPSIS,
    key: ITEM_KEYS.SECOND_ELLISPIS,
    value: 7,
    isActive: false
  },
  {
    type: ITEM_TYPES.PAGE,
    key: 10,
    value: 10,
    isActive: false
  },
  {
    type: ITEM_TYPES.NEXT_PAGE_LINK,
    key: ITEM_KEYS.NEXT_PAGE_LINK,
    value: 6,
    isActive: false
  },
  {
    type: ITEM_TYPES.LAST_PAGE_LINK,
    key: ITEM_KEYS.LAST_PAGE_LINK,
    value: 10,
    isActive: false
  }
]

In this example ITEM_TYPES and ITEM_KEYS can be imported from ultimate-pagination module, and they contain constants used in the output of the pagination model.

All item has the same structure:

  • type: string - type of item that can be one of ITEM_TYPES
  • key: number - unique number that can be used in libraries that need a key to render a collection of components (key in React, track by in Angular)
  • value: number - number of pages that user should navigate to when item is activated (for items with type PAGE it also can be used as a label in UI)
  • isActive: boolean - show if currentPage if the same as value of an item (can be used to highlight a current page or disable first, previous, next or last page links when user is already on first/last page)

Here is a list that contains all available ITEM_TYPES:

  • PAGE - a link to a page
  • ELLIPSIS - an item that represents groups of pages that currently are not visible in paginator (can be used to navigate to the page in the group that is the nearest to the current page)
  • FIRST_PAGE_LINK - a link to the first page
  • PREVIOUS_PAGE_LINK - a link to the previous page
  • NEXT_PAGE_LINK - a link to the next page
  • LAST_PAGE_LINK - a link to the last page