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 🙏

© 2026 – Pkg Stats / Ryan Hefner

type-pagination

v1.1.1

Published

Simple TS Pagination

Readme

type-pagination

Type-Pagination is simple pagination library for TypeScript.

Install

Depending on what package manager do you use:

yarn add type-pagination

or

npm install type-pagination

How to use

Import Pagination class from package

import { Pagination } from 'type-pagination';

Create new intance of Pagination class. First parametr contains array of items, second one total items number. Third parameter holds PaginationOptions object, with options – page and limit.


const items = [
  {
    id: 1,
    name: 'Item 1',
  },
  {
    id: 2,
    name: 'Item 2',
  },
  {
    id: 3,
    name: 'Item 3',
  },
]

const pagination = new Pagination(items, 14, { page: 1, limit: 3 });

To render pagination, use render method.

pagination.render();

Example output:

{
  items: [
    { id: 1, name: 'Item 1' },
    { id: 2, name: 'Item 2' },
    { id: 3, name: 'Item 3' }
  ],
  meta: {
    itemCount: 3,
    totalItems: 14,
    itemsPerPage: 3,
    totalPages: 5,
    currentPage: 1
  },
  links: {
    first: '?page=1&limit=3',
    next: '?page=2&limit=3',
    previous: '',
    last: '?page=5&limit=3'
  }
}

If you would like to add your own base url, use setBaseUrl method:

pagination.setBaseUrl('http://example.com');

Output with set base url:

{
  items: [
    { id: 1, name: 'Item 1' },
    { id: 2, name: 'Item 2' },
    { id: 3, name: 'Item 3' }
  ],
  meta: {
    itemCount: 3,
    totalItems: 14,
    itemsPerPage: 3,
    totalPages: 5,
    currentPage: 1
  },
  links: {
    first: 'http://example.com?page=1&limit=3',
    next: 'http://example.com?page=2&limit=3',
    previous: '',
    last: 'http://example.com?page=5&limit=3'
  }
}

Changing meta fields labels

Since version 1.1.0 it is possible, to change default meta fields labels. There are two methods available. You can change just one label with setMetaFieldLabel method. As fierd argument you must provide what kind of key do you wish to change (itemCount,totalItems, itemsPerPage, totalPages or currentPage), as second argument you must pass new field name. For example:

pagination
  .setMetaFieldLabel('totalItems', 'total')
  .generate();

You can also change all labels at once using setMetaFieldsLabels method. As an argument, you must provide an object which satisfies the MetaFieldsLabels type. For example:

pagination
  .setMetaFieldsLabels({
    itemCount: 'items',
    totalItems: 'total',
    itemsPerPage: 'limit',
    totalPages: 'pages',
    currentPage: 'page',
  })
  .generate();

It is possible to chain methods e.g.:

pagination
  .setBaseUrl('http://example.com')
  .setMetaFieldLabel('totalItems', 'total')
  .setMetaFieldLabel('currentPage', 'page')
  .generate();