{"id":25676393,"url":"https://github.com/simonsinclair/pgr","last_synced_at":"2026-04-16T19:04:16.472Z","repository":{"id":50185539,"uuid":"369672173","full_name":"simonsinclair/pgr","owner":"simonsinclair","description":"A tiny pagination range creator for your pagination UI.","archived":false,"fork":false,"pushed_at":"2021-06-12T13:17:50.000Z","size":449,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-06T21:06:16.031Z","etag":null,"topics":["jsx","pager","paginate","pagination","paginator","paging","react","typescript","vue"],"latest_commit_sha":null,"homepage":"https://github.com/simonsinclair/pgr","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonsinclair.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-21T23:04:36.000Z","updated_at":"2021-06-12T13:16:36.000Z","dependencies_parsed_at":"2022-09-14T11:12:46.062Z","dependency_job_id":null,"html_url":"https://github.com/simonsinclair/pgr","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonsinclair%2Fpgr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonsinclair%2Fpgr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonsinclair%2Fpgr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonsinclair%2Fpgr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonsinclair","download_url":"https://codeload.github.com/simonsinclair/pgr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240493305,"owners_count":19810260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["jsx","pager","paginate","pagination","paginator","paging","react","typescript","vue"],"created_at":"2025-02-24T14:26:14.351Z","updated_at":"2025-11-16T19:02:26.178Z","avatar_url":"https://github.com/simonsinclair.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgr\n\n\u003e A tiny pagination range creator for your pagination UI.\n\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/@simonsinclair/pgr)\n\n## Install\n\n```sh\nnpm i @simonsinclair/pgr\n```\n\n## Usage\n\n```js\nconst { default: pgr } = require('@simonsinclair/pgr');\n\nconst ARTICLES_PER_PAGE = 20;\nconst PAGINATION_LENGTH = 7;\n\nconst articles = [\n  { title: 'Article 1' },\n  { title: 'Article 2' },\n  // ...\n];\n\nconst totalPages = Math.ceil(articles.length / ARTICLES_PER_PAGE);\nconst currentPage = 5;\n\nconst pagination = pgr(totalPages, currentPage, PAGINATION_LENGTH);\n\nconsole.log(pagination);\n```\n\n```js\n[2, 3, 4, 5, 6, 7, 8];\n```\n\n## Tips\n\n### Using the callback parameter\n\nFor example, pass a JSX Element as a callback.\n\n```jsx\n\u003col\u003e\n  {pgr(totalPages, currentPage, PAGINATION_LENGTH, (pageNum) =\u003e (\n    \u003cli key={pageNum}\u003e\n      \u003cbutton\u003e{pageNum}\u003c/button\u003e\n    \u003c/li\u003e\n  ))}\n\u003c/ol\u003e\n```\n\n## API\n\n### pgr(totalPages, currentPage, length, callback?)\n\nReturns an array of pages the specified length. `pgr` will attempt to center the array around the current page.\n\n#### totalPages\n\nType: `number`.\n\nThe total number of pages.\n\n#### currentPage\n\nType: `number`.\n\nThe current page.\n\n#### length\n\nType: `number`.\n\nThe length of the pagination array.\n\n#### callback\n\nType: `Function`.\n\nDefault: `(page) =\u003e page`.\n\nA function that is called on each page in the range.\n\n## Supported browsers\n\nIE11, and all modern browsers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonsinclair%2Fpgr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonsinclair%2Fpgr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonsinclair%2Fpgr/lists"}