npm package: @pawan9303/list-pagination
Description: A simple utility to paginate large lists and generate pagination buttons dynamically.
Author: Your Name
Latest version: 1.2.1

# @pawan9303/list-pagination

A simple, lightweight utility to paginate large lists and generate pagination buttons dynamically. Ideal for frontend and backend applications that deal with large datasets.

---

## 🚀 Features

- Paginate large arrays with ease
- Generate visible page number buttons (like [3, 4, 5])
- Get total page button array (like [1, 2, ..., N])
- Works in Node.js, frontend apps, and server-side frameworks

---

## 📦 Installation

```bash
npm install @pawan9303/list-pagination
```

---

## 📚 Usage

```js
const {
  paginate,
  getPageNumbers,
  getPaginationButtons,
} = require('@pawan9303/list-pagination');

const data = Array.from({ length: 100 }, (_, i) => `Item ${i + 1}`);

// Paginate data (page 2, 10 items per page)
const pageData = paginate(data, 2, 10);
console.log(pageData);
// {
//   currentPage: 2,
//   perPage: 10,
//   totalItems: 100,
//   totalPages: 10,
//   data: [ 'Item 11', ..., 'Item 20' ]
// }

// Get visible page numbers near current page
console.log(getPageNumbers(pageData.currentPage, pageData.totalPages, 2));
// [1, 2, 3, 4]

// Get all page numbers for rendering buttons
console.log(getPaginationButtons(data.length, 10));
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
```

---

## 🔧 API Reference

### `paginate(array, currentPage, perPage)`

| Param         | Type   | Description                                              |
|---------------|--------|----------------------------------------------------------|
| `array`       | Array  | Array of items to paginate                               |
| `currentPage` | Number | Page number to return                                    |
| `perPage`     | Number | Number of items per page                                 |
| **Returns**   | Object | `{ currentPage, perPage, totalItems, totalPages, data }` |

---

### `getPageNumbers(currentPage, totalPages, delta = 2)`

Returns a window of pages near the current page.

| Param         | Type   | Description                            |
|---------------|--------|----------------------------------------|
| `currentPage` | Number | Current page                           |
| `totalPages`  | Number | Total number of pages                  |
| `delta`       | Number | Number of pages before/after current   |
| **Returns**   | Array  | Visible page numbers, e.g. `[3, 4, 5]` |

---

### `getPaginationButtons(totalItems, perPage)`

Returns all page numbers as an array based on total items.

| Param        | Type   | Description               |
|--------------|--------|---------------------------|
| `totalItems` | Number | Total number of items     |
| `perPage`    | Number | Items per page            |
| **Returns**  | Array  | Page numbers `[1, 2, ...]` |

---

## ✅ Example

```js
const { paginate } = require('@pawan9303/list-pagination');

const items = [...Array(42).keys()]; // [0, 1, 2, ..., 41]
const result = paginate(items, 5, 10);

console.log(result.data);        // [40, 41]
console.log(result.totalPages);  // 5
```

---

## 👨‍💻 Author

Made by [@pawan9303](https://www.npmjs.com/~pawan9303)

---

## 📄 License

MIT