npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@studiohyperdrive/pagination

v2.0.0

Published

Pagination tools for Node.js

Downloads

200

Readme

@studiohyperdrive/pagination

General

This repo contains a set of tools for pagination.

It is build with:

  • node: v14.x.x ( ~ lts/fermium)
  • npm: 6.14.11

For a complete list of packages and their version check out the package.json file.

Use

Install

You can install this package by doing:

$ npm install @studiohyperdrive/pagination

or if you use Yarn:

$ yarn add @studiohyperdrive/pagination

In your code

In your code, you can use this package and it's interfaces like this:

import { Pagination, IPagination } from '@studiohyperdrive/pagination';

class ItemController {
  public async findAll(page: number, size: number, query: Record<string, unknown>): Promise<IPagination<IItem>> {
    const [items, total]: [IItem[], number] = await this.itemRepository.findAndCount(page, size);

    return Pagination<IItem>({
      items,
      page,
      path,
      query,
      size,
      total,
    });
  }
}

This 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.

What does it return?

V1

Version 1.0.0 of this package will return the following type or result:

{
    items: T[];
    total: number;
    pages: number;
    page: number;
    size: number;
    self?: string;
    first?: string;
    last?: string;
    next?: string;
    prev?: string;
}

V2

Version 2.0.0 follows the HAL guidelines closer and will return the following type or result:

{
  _embedded: {
    items: T[];
    total: number;
    pages: number;
    page: number;
    size: number;
  };
  _links: {
    self?: string;
    first?: string;
    last?: string;
    next?: string;
    prev?: string;
  };
}

What's in the package?

This package exposes the following functions:

  • calculateTotalPages: Calculate the total amount of pages based on the total amount of elements and the page size
  • formatQuerystring: Format the querystring based on the page, the size and the current request querystring
  • formatLink: Format a link based on the path, the page, the size and the current request querystring
  • Pagination: This function is the main one which will use the above and your input to transform your input to a pagination object

And the following interfaces:

  • IPagination: An interface for the formatted pagination object

Setup for contribution

Clone and install dependencies

To setup this project, clone the repo and run yarn to install the dependencies.

Commands

The available commands for building the project are:

| command | runs | |--------------|-----------------------------------------------------------------------------------------------------------| | build | This script runs rollup to compile your code (target to the dist folder) |

The available commands for testing the project are:

| command | runs | |--------------|-----------------------------------------------------------------------------------------------------------| | lint | This script will run linting | | lint:fix | This script will run linting and fix what it can | | test | This script will run your Jest tests for the library and create a coverage report | | test:watch | This script will run your Jest tests but with the --watch flag. It does not create a coverage report |

Publish

This project can be published to the npm registry. To do so follow these steps:

  1. Run npm version <major | minor | patch> to create a new version and commit + tag it.
  2. Open a Merge Request on Github.
  3. Once your changes have been commited to the main-branch, you can publish to the repo.
  4. Run npm publish.

Team

This project has been created by:

It is currently maintained by: