jw-paginate provides a standalone, framework-agnostic utility for calculating pagination logic, implemented in both JavaScript and TypeScript. It offers a pure function that, given parameters like total items, current page, page size, and maximum pages to display, returns a comprehensive object containing all necessary pagination details. This includes total pages, start and end item indices, start and end page numbers, and an array of page numbers to render in a UI. The current stable version is 1.0.4. Due to its minimalist 'pure logic' design and comprehensive feature set for its specific domain, the library has a very infrequent release cadence, with its last significant update occurring in 2018. Its primary differentiator is its complete lack of external dependencies and framework agnosticism, allowing seamless integration into any web project without introducing framework-specific couplings or unnecessary bloat. It also ships with first-class TypeScript type definitions, providing an enhanced development experience for TypeScript users.
npm install jw-paginateVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `paginate` function to calculate page numbers and slice a data array for a specific page. It initializes an array of items and then uses the `jw-paginate` function to determine the pagination details for a given page, logging the results.
Always add `+ 1` to the `endIndex` when using `Array.prototype.slice()`: `yourArray.slice(page.startIndex, page.endIndex + 1)`.
Review the source code to ensure it meets your project's standards for modern practices if relying on a long-term unmaintained library. For pure logic, this is often less of a concern.
Always explicitly pass all parameters to `paginate(totalItems, currentPage, pageSize, maxPages)` to ensure predictable behavior, even if some values match the defaults.
Change your import statement to `import paginate from 'jw-paginate';` or `const paginate = require('jw-paginate').default;` for CommonJS.Ensure `totalItems` is a positive integer representing the total count of all items. Verify `maxPages` is set to a reasonable number of page links you want to display, not the total number of pages.
Ensure all numerical parameters passed to `paginate` are valid numbers. If values come from URL query parameters or user input, parse them to integers (e.g., `parseInt(value, 10)`) and handle potential `NaN` results before passing to the function.
No dependency data recorded yet.