{"id":15677657,"url":"https://github.com/ulisesgascon/express-simple-pagination","last_synced_at":"2025-05-07T01:22:15.038Z","repository":{"id":42470876,"uuid":"247653591","full_name":"UlisesGascon/express-simple-pagination","owner":"UlisesGascon","description":"Express middleware for simple pagination. Easy way to handle limit and offset","archived":false,"fork":false,"pushed_at":"2023-01-08T14:14:37.000Z","size":1446,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T23:32:08.521Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/UlisesGascon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-16T08:53:54.000Z","updated_at":"2022-10-22T17:44:21.000Z","dependencies_parsed_at":"2023-02-08T06:15:37.743Z","dependency_job_id":null,"html_url":"https://github.com/UlisesGascon/express-simple-pagination","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fexpress-simple-pagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fexpress-simple-pagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fexpress-simple-pagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Fexpress-simple-pagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UlisesGascon","download_url":"https://codeload.github.com/UlisesGascon/express-simple-pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252794291,"owners_count":21805173,"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":[],"created_at":"2024-10-03T16:10:11.826Z","updated_at":"2025-05-07T01:22:15.012Z","avatar_url":"https://github.com/UlisesGascon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ch1 align=\"center\"\u003e\n  express-simple-pagination\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  Express middleware for simple pagination. Easy way to handle limit and offset\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.org/package/express-simple-pagination\"\u003e\u003cimg src=\"https://badgen.net/npm/v/express-simple-pagination\" alt=\"npm version\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/express-simple-pagination\"\u003e\u003cimg src=\"https://badgen.net/npm/license/express-simple-pagination\" alt=\"license\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/express-simple-pagination\"\u003e\u003cimg src=\"https://badgen.net/npm/dt/express-simple-pagination\" alt=\"downloads\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://snyk.io/test/github/ulisesgascon/express-simple-pagination\"\u003e\u003cimg src=\"https://snyk.io/test/github/ulisesgascon/express-simple-pagination/badge.svg\" alt=\"Known Vulnerabilities\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003c/p\u003e\n\n\n# About\n\nExpress middleware for simple pagination. Easy way to handle limit and offset.\n\nThe pagination middleware will add an object `pagination` to `request`. \n\nBy default it includes:\n\n- The default values for pagination.\n- The current pagination request.\n- If the pagination is active.\n- Default values, Range validation, wrong values validation and sanitization.\n- By default the offset will be 0 and the limit range between (20-500)\n- Full customizable\n- Easy to use and 100% test coverage\n\n```txt\nreq.pagination = {\n    isEnable: Boolean(),               // This indicates if the pagination was requested in the url\n    default: { limit: 20, offset: 0 }, // default values\n    current: { limit: 20, offset: 0 } // In case that the pagination was requested, this estimates the real pagination using ranges and default values.\n}\n```\n\nThis middelware will be triggered by query params `offset` and/or `limit`, like:\n\n- `/route?limit=10`\n- `/route?limit=100\u0026offset=500`\n- `/route?offset=350`\n\n# Usage\n\n## Install\n\n```bash\nnpm install express-simple-pagination\n```\n\n## Simple Usage (Enable All Pagination Requests)\n\n```js\nconst express = require('express')\nconst pagination = require('express-simple-pagination')\nconst app = express()\nconst port = 3000\n\napp.use(pagination())\n\napp.get('/products', (req, res, next) =\u003e {\n  res.json({msg: req.pagination})\n})\n\napp.listen(port, () =\u003e {\n  console.log(`web server listening on ${port}`)\n})\n```\n\noutput:\n\n```txt\n/products\n└──\u003e msg: {req.isEnable: false, default: { limit: 20, offset: 0 }}\n/products?limit=200\n└──\u003e msg: {req.isEnable: false, current: { limit: 200, offset: 0 }, default: { limit: 20, offset: 0 }}\n/products?limit=200\u0026offset=600\n└──\u003e msg: {req.isEnable: false, current: { limit: 200, offset: 600 }, default: { limit: 20, offset: 0 }}\n/products?limit=4000\n└──\u003e msg: {req.isEnable: false, current: { limit: 200, offset: 0 }, default: { limit: 20, offset: 0 }}\n/products?limit=-10\n└──\u003e msg: {req.isEnable: false, current: { limit: 20, offset: 0 }, default: { limit: 20, offset: 0 }}\n/products?offset=-10\n└──\u003e msg: {req.isEnable: false, current: { limit: 20, offset: 0 }, default: { limit: 20, offset: 0 }}\n```\n\n## Enable pagination for a Single Route\n\n```js\nconst express = require('express')\nconst pagination = require('express-simple-pagination')\nconst app = express()\nconst port = 3000\n  \napp.get('/products', pagination(), (req, res, next) =\u003e {\n  res.json({msg: req.pagination})\n})\n\napp.get('/clients', (req, res, next) =\u003e {\n  res.json({msg: req.pagination})\n})\n\napp.listen(port, () =\u003e {\n  console.log(`web server listening on ${port}`)\n})\n```\n\noutput:\n\n```txt\n/products\n└──\u003e msg: {req.isEnable: false, default: { limit: 20, offset: 0 }}\n\n/clients\n└──\u003e msg: undefined\n```\n\n## Configuring Pagination (items per page)\n\n```js\nconst express = require('express')\nconst pagination = require('express-simple-pagination')\nconst app = express()\nconst port = 3000\n\nconst paginationOptions = {\n  min: 5,\n  max: 1000\n}\n\napp.get('/products', pagination(paginationOptions), (req, res, next) =\u003e {\n  res.json({msg: req.pagination})\n})\n\napp.listen(port, () =\u003e {\n  console.log(`web server listening on ${port}`)\n})\n```\n\noutput:\n\n```txt\n/products\n└──\u003e msg: {req.isEnable: false, default: { limit: 5, offset: 0 }}\n/products?limit=1\n└──\u003e msg: {req.isEnable: false, current: { limit: 5, offset: 0 }, default: { limit: 5, offset: 0 }}\n/products?limit=2400000\u0026offset=600\n└──\u003e msg: {req.isEnable: false, current: { limit: 1000, offset: 600 }, default: { limit: 5, offset: 0 }}\n/products?limit=4000\n└──\u003e msg: {req.isEnable: false, current: { limit: 4000, offset: 0 }, default: { limit: 5, offset: 0 }}\n```\n\n\n## Page vs Offset\n\nIt is possible to use `page` argument like `?page=1` in state of `offset` \n\n# Test\n\nYou can run them:\n\n```bash\nnpm run test:coverage\n```\n\n# Contributing\n\nPlease check [CONTRIBUTING](./CONTRIBUTING.md) for guidelines on contributing to this project.\n\n# Author\n\n**express-simple-pagination** © [Ulises Gascón](https://github.com/ulisesgascon), Released under the [MIT](./LICENSE) License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulisesgascon%2Fexpress-simple-pagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fulisesgascon%2Fexpress-simple-pagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fulisesgascon%2Fexpress-simple-pagination/lists"}