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

@rizkyalam/pagination

v1.0.0

Published

Simple pagination library

Readme

Pagination

Simple pagination for typescript or javascript project you can use

Installation

  npm install @rizkyalam/pagination

Usage

There are two types of functions that can be used, namely paginate() and paginateUrl()

  • paginate()

    const peoples = [
        { name: 'Asep', age: 21, address: 'Bandung' },
        { name: 'Komar', age: 23, address: 'Jakarta' },
    ];
    
    const options = {
        search: 'a',
        limit: 1,
        currentPage: 1,
        fieldName: 'peoples',
        sort: [
            ['age', 'desc'],
        ],
    };
    
    paginate(peoples, options);
  • paginateUrl()

    const peoples = [
        { name: 'Asep', age: 21, address: 'Bandung' },
        { name: 'Komar', age: 23, address: 'Jakarta' },
    ];
    
    const options = {
        path: 'example.com',
        filterParams: {
            search: 'a',
            limit: 1,
            page: 1,
        },
        fieldName: 'peoples',
        sort: [
            ['age', 'desc'],
        ],
    };
    
    paginateUrl(peoples, options);

Importing

you can use both importing ES6 and CommonJS module

import Pagination from '@rizkyalam/pagination'

// or

const Pagination from '@rizkyalam/pagination'

Directly in HTML

you can build manual this project and then directly import to html

npm run build
<!DOCTYPE html>
<html>
  <head>
    <script src="pagination/dist"></script>
  </head>
  <body>
    <script>
        var peoples = [
            { name: 'Asep', age: 21, address: 'Bandung' },
            { name: 'Komar', age: 23, address: 'Jakarta' },
        ];

        var paginateOptions = {
            fieldName: 'peoples',
        }

        var paginate = Pagination.paginate(peoples, paginateOptions);

        var paginateUrlOptions = {
            path: 'example.com',
            filterParams: {
                search: 'Asep',
            },
        }

        var paginateUrl = Pagination.paginateUrl(peoples, paginateUrlOptions);
    </script>
  </body>
</html>

Interface or Type

Note: this section can use for Typescript project

Options Interface or Type

Setup Pagination Option

OptionOrder

there is 2 ordering mode: asc and desc

type Mode = 'asc' | 'desc';

type KeySort = string;

type OptionOrder = [KeySort, Mode];

PaginateOptions

Note: use for paginate() options

In this interface there are several key with their functions:

  • search used to search the entire data
  • limit used to limit the amount of data per page
  • currentPage used to get data on the specified page
  • fieldName used to determine the key response for the default is data
  • sort used to sorting data based on type OptionOrder
// usage
interface PaginateOptions {
  search?: string | boolean | number;
  limit?: number;
  currentPage?: number;
  fieldName?: string;
  sort?: OptionOrder[];
}

const options: PaginateOptions = {
    search: 'test',
    limit: 1,
    currentPage: 1,
    fieldName: 'defaultData',
    sort: [
        ['order', 'asc'],
    ],
}

PaginateFilterParameter

In this interface there are several key with their functions:

  • search used to search the entire data
  • limit used to limit the amount of data per page
  • page used to get data on the specified page

Note: this interface can use to make print response custom query string with the url

// usage
interface PaginateFilterParameter {
    search?: string | boolean | number;
    limit?: number;
    page?: number;
}

interface CustomFilter extends PaginateFilterParameter {
    test: string,
}

const customFilter: CustomFilter = {
    limit: 2,
    page: 3,
    search: 'slur',
    test: 'euy',
};

PaginateUrlOptions

Note: use for paginateUrl() options

In this interface there are several key with their functions:

  • path used to print the output with your url
  • filterParams used to print url output by adding query string
  • fieldName used to determine the key response for the default is data
  • sort used to sorting data based on type OptionOrder
interface PaginateUrlOptions {
    path: string;
    filterParams: PaginateFilterParameter;
    fieldName?: string;
    sort?: OptionOrder[];
}

const options: PaginateUrlOptions = {
    path: 'example.com',
    filterParams: {
        search: 'test',
        limit: 1,
        currentPage: 1,
    },
    fieldName: 'defaultData',
    sort: [
        ['order', 'asc'],
    ],
};

Response Interface or Type

PaginateRespond

Note: use for paginate() respond

{
    total: 6,
    total_per_page: 3,
    current_page: 2,
    first_page: 1,
    last_page: 2,
    previous_page: 1,
    next_page: null,
    data: [
        {
            // Record...
        },
    ],
}

PaginateUrlRespond

Note: use for paginateUrl() respond

{
    total: 3,
    total_per_page: 3,
    current_page: 1,
    path: 'example.com?search=test&limit=3&page=1',
    first_page_url: 'example.com?search=test&limit=3&page=1',
    last_page_url: 'example.com?search=test&limit=3&page=1',
    previous_page_url: null,
    next_page_url: null,
    data: [
        {
            // Record...
        },
    ],
}

If fieldName and filterParams are used with custom, the output will be customized

const customFilter: PaginateUrlOptions = {
    path: 'example.com',
    filterParams: {
        limit: 2,
        page: 3,
        search: 'slur',
        test: 'euy',
    },
    fieldName: 'peoples',
};

// output
{
    total: 6,
    total_per_page: 2,
    current_page: 3,
    path: 'example.com?test=euy&search=slur&limit=2&page=3',
    first_page_url: 'example.com?test=euy&search=slur&limit=2&page=1',
    last_page_url: 'example.com?test=euy&search=slur&limit=2&page=3',
    previous_page_url: 'example.com?test=euy&search=slur&limit=2&page=2',
    next_page_url: null,
    peoples: [
        {
            // Record...
        },
    ],
}