The `ultimate-pagination` library provides a universal algorithm for generating pagination models, designed to be framework-agnostic and reusable across various JavaScript environments, including client-side frameworks (React, Angular, Ember, etc.) and server-side Node.js applications. It abstracts the complex logic of determining which page numbers, ellipsis, and navigation links (first, last, previous, next) should be displayed, returning a structured array of item objects. The current stable version is `1.0.0`. It focuses purely on logic generation, decoupling it from UI rendering, allowing developers to implement custom UI components on top of its output. Its primary differentiator is this separation of concerns, enabling consistent pagination behavior across diverse tech stacks and making it suitable for server-side rendering. There is no explicit release cadence mentioned, but it appears to be a stable library with infrequent, feature-driven updates.
npm install ultimate-paginationVerified import paths — ran on the pinned version, not inferred.
Demonstrates generating various pagination models using `getPaginationModel` with different options for page ranges and link visibility, showing the structured output and how to interpret `ITEM_TYPES`.
Always sanitize or validate `currentPage` and `totalPages` to be positive integers, ensuring `1 <= currentPage <= totalPages`. Implement `try...catch` blocks if inputs are untrusted or derived from user input.
When mapping over the `paginationModel` to render components, ensure your component's `key` prop can accept both numbers and strings, or normalize the `key` to a string: `item.key.toString()`.
To display or log the string representation of an item type, use `ITEM_TYPES[item.type]` or create a mapping object from numerical values to string names.
Always ensure `currentPage` is treated as 1-indexed. If converting from a 0-indexed source (e.g., an array index), remember to add `1`.
For CommonJS, explicitly access the function: `const { getPaginationModel } = require('ultimate-pagination');` or `const ultimatePagination = require('ultimate-pagination'); const model = ultimatePagination.getPaginationModel(...);`Ensure `currentPage` is always a positive integer (`>= 1`). If converting from a 0-indexed source, remember to add `1`.
Ensure `currentPage` is less than or equal to `totalPages`. Validate user input or state logic to prevent this scenario.
Use a named import: `import { ITEM_TYPES, ITEM_KEYS } from 'ultimate-pagination';`No dependency data recorded yet.