{"id":18885945,"url":"https://github.com/studiohyperdrive/pagination","last_synced_at":"2026-02-23T10:30:27.385Z","repository":{"id":43039186,"uuid":"330729616","full_name":"studiohyperdrive/pagination","owner":"studiohyperdrive","description":"Pagination tools for Node.js","archived":false,"fork":false,"pushed_at":"2022-09-12T11:09:29.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-28T06:23:23.274Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/studiohyperdrive.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}},"created_at":"2021-01-18T16:48:33.000Z","updated_at":"2022-03-22T12:40:43.000Z","dependencies_parsed_at":"2022-09-09T17:01:10.362Z","dependency_job_id":null,"html_url":"https://github.com/studiohyperdrive/pagination","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fpagination","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fpagination/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fpagination/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/studiohyperdrive%2Fpagination/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/studiohyperdrive","download_url":"https://codeload.github.com/studiohyperdrive/pagination/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239859016,"owners_count":19708857,"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-11-08T07:23:21.490Z","updated_at":"2026-02-23T10:30:27.333Z","avatar_url":"https://github.com/studiohyperdrive.png","language":"TypeScript","readme":"# @studiohyperdrive/pagination\n\n## General\n\nThis repo contains a set of tools for pagination.\n\nIt is build with:\n- node: `v14.x.x` ( ~ `lts/fermium`)\n- npm: `6.14.11`\n\nFor a complete list of packages and their version check out the `package.json` file.\n\n## Use\n\n### Install\n\nYou can install this package by doing:\n``` bash\n$ npm install @studiohyperdrive/pagination\n```\nor if you use Yarn:\n``` bash\n$ yarn add @studiohyperdrive/pagination\n```\n\n### In your code\nIn your code, you can use this package and it's interfaces like this:\n\n```typescript\nimport { Pagination, IPagination } from '@studiohyperdrive/pagination';\n\nclass ItemController {\n  public async findAll(page: number, size: number, query: Record\u003cstring, unknown\u003e): Promise\u003cIPagination\u003cIItem\u003e\u003e {\n    const [items, total]: [IItem[], number] = await this.itemRepository.findAndCount(page, size);\n\n    return Pagination\u003cIItem\u003e({\n      items,\n      page,\n      path,\n      query,\n      size,\n      total,\n    });\n  }\n}\n```\n\nThis will transform your items and total to a formatted pagination response which you can return to the client. Adding a `path` and `query` is optional. If specified, links to the current, first, last, next and previous page are added to the response.\n\n### What's in the package?\nThis package exposes the following functions:\n- `calculateTotalPages`: Calculate the total amount of pages based on the total amount of elements and the page size\n- `formatQuerystring`: Format the querystring based on the page, the size and the current request querystring\n- `formatLink`: Format a link based on the path, the page, the size and the current request querystring\n- `Pagination`: This function is the main one which will use the above and your input to transform your input to a pagination object\n\nAnd the following interfaces:\n- `IPagination`: An interface for the formatted pagination object\n## Setup for contribution\n\n### Clone and install dependencies\nTo setup this project, clone the repo and run `yarn` to install the dependencies.\n\n### Commands\nThe available commands for building the project are:\n\n| command      | runs                                                                                                      |\n|--------------|-----------------------------------------------------------------------------------------------------------|\n| build        | This script runs rollup to compile your code (target to the `dist` folder)                                |\n\u003cbr\u003e\n\nThe available commands for testing the project are:\n\n| command      | runs                                                                                                      |\n|--------------|-----------------------------------------------------------------------------------------------------------|\n| lint         | This script will run linting                                                                              |\n| lint:fix     | This script will run linting and fix what it can                                                          |\n| test         | This script will run your Jest tests for the library and create a coverage report                         |\n| test:watch   | This script will run your Jest tests but with the `--watch` flag. It does not create a coverage report    |\n\u003cbr\u003e\n\n## Publish\n\nThis project can be published to the npm registry. To do so follow these steps:\n1. Run `npm version \u003cmajor | minor | patch\u003e` to create a new version and commit + tag it.\n2. Open a Merge Request on Github.\n3. Once your changes have been commited to the main-branch, you can publish to the repo.\n4. Run `npm publish`.\n\n**Due to historic reasons v2.0.0 has been unpublished, meaning this version cannot be used for a new release. Make sure to bump to at least v2.0.1 to continue development.**\n\n## Team\n\nThis project has been created by:\n- Niels Bril: niels.bril@studiohyperdrive.be\n\nIt is currently maintained by:\n- Niels Bril: niels.bril@studiohyperdrive.be\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstudiohyperdrive%2Fpagination","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstudiohyperdrive%2Fpagination","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstudiohyperdrive%2Fpagination/lists"}