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

@trojs/paginator

v3.0.0

Published

Paginator

Downloads

1,602

Readme

Paginator

NPM version Downloads

With this package you can easy create a pagination object.

Example usage

import Paginator from '@trojs/paginator'

/**
 * @typedef {import('@trojs/paginator').Pagination} Pagination
 */

/** @type {Pagination} */
 const results = Paginator({
    items,
    page,
    size,
    url
})

fields

items

The field items should be an array. It doesnt matter what every item contains, but an object is common.

field page

The field page should be an integer, and it is optional. You can set the current page with the page. The first page is 0, and if you dont set a page, it is the first page.

field size

The field size should be an integer, and it is optional. You can set the maximum of items per page with the size. The minimum is 1, and the default is 10.

field url

The field url should be a string, and it is optional. This will be used for the links, for e.g. the current, previous and next pages.

result

Example:

{
    cursors: {
        self: '/?test=true&size=10&page=1',
        prev: '/?test=true&size=10&page=0',
        next: '/?test=true&size=10&page=2',
        first: '/?test=true&size=10&page=0',
        last: '/?test=true&size=10&page=2',
    },
    count: 21,
    size: 10,
    page: 1,
    pages: 3,
    items: [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
}

cursors

The field cursors should be an object. It returns the current page (self), previous page (prev) and the next page (next) If there is no next or previous page, it returns null If you dont have set an url, it returns for every link null

count

The field count should be an integer. It returns the total of items.

size

The field size should be an integer. The default is 10, and you can override it with the given size.

pages

The field pages should be an integer. It is the total of pages. E.g. If there are 20 items and the page size is 10, there are 2 pages. And if there are 21 items and the page size is 10, there are 3 pages.

items

The field items should be an array. It returns all items for the given page. E.g. in the example you see all items for page 1 (second page). Because there are 21 items, the next page will return just an array with 1 item.