{"id":15766957,"url":"https://github.com/uphold/koa-pagination","last_synced_at":"2025-04-15T20:24:51.563Z","repository":{"id":24060857,"uuid":"27446911","full_name":"uphold/koa-pagination","owner":"uphold","description":"A middleware to handle Range Pagination Headers using Range \u0026 Content-Range entity-headers.","archived":false,"fork":false,"pushed_at":"2023-10-02T19:47:36.000Z","size":2172,"stargazers_count":34,"open_issues_count":22,"forks_count":4,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-12T18:05:21.222Z","etag":null,"topics":["content-range","koa2","middleware","pagination","range"],"latest_commit_sha":null,"homepage":"https://npmjs.com/koa-pagination","language":"JavaScript","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/uphold.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-02T18:28:31.000Z","updated_at":"2025-01-30T22:52:40.000Z","dependencies_parsed_at":"2024-06-19T00:16:28.451Z","dependency_job_id":"85cbc2dd-ba5b-46f9-bdef-0dc0e7322e17","html_url":"https://github.com/uphold/koa-pagination","commit_stats":{"total_commits":94,"total_committers":10,"mean_commits":9.4,"dds":0.7765957446808511,"last_synced_commit":"dcfbf70f6a66d1b1643fed2fa1ce66be7df11f0d"},"previous_names":["seegno/koa-pagination"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uphold%2Fkoa-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uphold","download_url":"https://codeload.github.com/uphold/koa-pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249146682,"owners_count":21220193,"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":["content-range","koa2","middleware","pagination","range"],"created_at":"2024-10-04T13:04:11.304Z","updated_at":"2025-04-15T20:24:51.520Z","avatar_url":"https://github.com/uphold.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koa-pagination\n\n`koa-pagination` is a middleware to handle [Range Pagination Headers](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) using `Range` \u0026 `Content-Range` entity-headers.\n\n## Status\n\n[![npm version][npm-image]][npm-url] [![build status][travis-image]][travis-url]\n\n## Installation\n\nInstall the package via `yarn`:\n\n```sh\n❯ yarn add koa-pagination\n```\n\nor via `npm`:\n\n```sh\n❯ npm install koa-pagination --save\n```\n\n### Configuration\n\nThe middleware can be configured with the following parameters:\n\n- `allowAll`: Whether to accept `*` as range-specifier.\n- `maximum`: Maximum number of items allowed per page (`50` by default).\n- `unit`: Accepted range unit (`items` by default).\n\nYou can change the defaults by doing:\n\n```javascript\nmiddleware({\n  allowAll: true,\n  maximum: 100,\n  unit: 'bytes'\n});\n```\n\n## Usage\n\n```javascript\nconst { middleware } = require('koa-pagination');\nconst Koa = require('koa');\n\nconst app = new Koa();\n\napp.get('/', middleware(), async ctx =\u003e {\n  // `paginate` middleware will inject a `pagination` object in the `koa` context,\n  // which will allow you to use the `pagination.offset` and `pagination.limit`\n  // in your data retrieval methods.\n  ctx.body = await foobar.getData({\n    limit: ctx.pagination.limit,\n    offset: ctx.pagination.offset\n  });\n\n  // This is needed in order to expose the length in `Content-Range` header.\n  ctx.pagination.length = foobar.count();\n});\n\napp.listen(3000);\n```\n\n### Request\n\nYou can provide the `Range` header specifying the items you want to retrieve. For instance to retrieve the first 5 elements:\n\n```javascript\n'Range: items=0-4'\n```\n\nYou can also provide `*` at the end of the range in order to retrieve the all of the available items:\n\n```javascript\n'Range: items=0-*'\n```\n\n### Response\n\nThe first example will generate a response with the following headers:\n\n```javascript\n'Accepted-Ranges': 'items'\n'Content-Range: items 0-4/*'\n```\n\nThe `*` in the `Content-Range` header will be replaced with the total number of items provided in the `length` variable.\n\n#### Codes\n\nCode | Reason\n---- | -------------------------------------------------------------------------\n200  | `Range` header has not been provided.\n206  | `Range` header is valid.\n412  | `Range` header is malformed.\n416  | `Range` header is invalid.\n500  | Incorrect middleware configuration or unexpected value inside middleware.\n\n## Tests\n\n```sh\n❯ yarn test\n```\n\n## Release\n\n```sh\n❯ npm version [\u003cnew version\u003e | major | minor | patch] -m \"Release %s\"\n```\n\n[npm-image]: https://img.shields.io/npm/v/koa-pagination.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/koa-pagination\n[travis-image]: https://img.shields.io/travis/uphold/koa-pagination.svg?style=flat-square\n[travis-url]: https://travis-ci.org/uphold/koa-pagination\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fkoa-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuphold%2Fkoa-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuphold%2Fkoa-pagination/lists"}