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

pagination-helper

v2.1.1

Published

get your page paginations details

Downloads

6

Readme

pagination-helper

CI

a simple pagination for calculating offset, limit and number of pages

Installation and Usage

Server-side usage

Install the library with npm install pagination-helper

yarn

yarn add pagination-helper

No ES6

var paginationHelper = require('pagination-helper');

ES6 - typescript

define the pagination helper class

import pagination, { IPaginationHelper, IPageNumberDetails, ITakeAndSkip } from "pagination-helper";

const pagiantionHelper: IPaginationHelper = new pagination({
    numberOfDataPerPage: 2, // number of data that you want to show them per page
    current_page_number: 8, // the number of page that we are currently in
    short: true
})

get page numbers details and short them

this function gives you the page number details, it also short them for you to can use them in your front end framework

const pageNumberDetails: IPageNumberDetails[] = pagiantionHelper.getDetailsOfTheNumberOfPages(100) /* 100 is the number of all of your data */
console.log(pageNumberDetails)
/* Output:
    [
        { disabled: false, value: 1 },
        { disabled: true, value: '...' },
        { disabled: false, value: 5 },
        { disabled: false, value: 6 },
        { disabled: false, value: 7 },
        { disabled: false, value: 8 },
        { disabled: false, value: 9 },
        { disabled: false, value: 10 },
        { disabled: false, value: 11 },
        { disabled: true, value: '...' },
        { disabled: false, value: 50 }
    ]
*/

get page numbers details without shorting them

if you set short variable to false, pagination-helper dosent short the number of pages EXAMPLE:

pagiantionHelper.short = false

console.log(pagiantionHelper.getDetailsOfTheNumberOfPages(100))
/* 
Output:
        [
            { disabled: false, value: 1 },
            { disabled: false, value: 2 },
            { disabled: false, value: 3 },
            { disabled: false, value: 4 },
            { disabled: false, value: 5 },
            { disabled: false, value: 6 },
            { disabled: false, value: 7 },
            { disabled: false, value: 8 },
            { disabled: false, value: 9 },
            { disabled: false, value: 10 },
            { disabled: false, value: 11 },
            { disabled: false, value: 12 },
            { disabled: false, value: 13 },
            { disabled: false, value: 14 },
            { disabled: false, value: 15 },
            { disabled: false, value: 16 },
            { disabled: false, value: 17 },
            { disabled: false, value: 18 },
            { disabled: false, value: 19 },
            { disabled: false, value: 20 },
            { disabled: false, value: 21 },
            { disabled: false, value: 22 },
            { disabled: false, value: 23 },
            { disabled: false, value: 24 },
            { disabled: false, value: 25 },
            { disabled: false, value: 26 },
            { disabled: false, value: 27 },
            { disabled: false, value: 28 },
            { disabled: false, value: 29 },
            { disabled: false, value: 30 },
            { disabled: false, value: 31 },
            { disabled: false, value: 32 },
            { disabled: false, value: 33 },
            { disabled: false, value: 34 },
            { disabled: false, value: 35 },
            { disabled: false, value: 36 },
            { disabled: false, value: 37 },
            { disabled: false, value: 38 },
            { disabled: false, value: 39 },
            { disabled: false, value: 40 },
            { disabled: false, value: 41 },
            { disabled: false, value: 42 },
            { disabled: false, value: 43 },
            { disabled: false, value: 44 },
            { disabled: false, value: 45 },
            { disabled: false, value: 46 },
            { disabled: false, value: 47 },
            { disabled: false, value: 48 },
            { disabled: false, value: 49 },
            { disabled: false, value: 50 }
        ] 
*/ 

console.log(pagiantionHelper.getNumberOfPages(98))
/*
    Output: 49
        it means that you have 49 pages
*/

console.log(pagiantionHelper.getNumberOfPages(98.5))
/*
    Output: 50
        it means that you have 49 pages, it support the float numbers.
*/

Get Page Number by Offset And Limit

console.log(pagiantionHelper.getPageNumberByOffsetAndLimit(30, 5)) // => 4, it means you are in page 7

Get Offset(Limit) And Limit(Take) by Page Number

this function give you the number of your (take, skip) by page number, it's useful for when you want to write a query to get the data

const takeAndOffset: ITakeAndSkip = pagiantionHelper.getTakeAndSkip(7)
console.log(takeAndOffset)
/*
    => { take: 2, skip: 12 }, it means, if you want to go to page 7 set 
        set take 2 and skip 12 on your database query.
*/

Maintainers