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

paginationah

v1.1.2

Published

A simple, efficient TypeScript pagination utility for handling pagination logic in your applications.

Downloads

41

Readme

paginationah

A simple, efficient TypeScript pagination utility for handling pagination logic in your applications.

Table of Contents

Installation

Install the paginationah package via npm:

npm install paginationah or using Yarn: yarn add paginationah

usage

'use client';

import { useState } from 'react';
import { paginationah } from 'paginationah';
import { User } from '../page';

interface UsersListProps {
   users: User[];
}

const UsersList: React.FC<UsersListProps> = ({ users }) => {
   const [currentPage, setCurrentPage] = useState(1);
   const itemsPerPage = 3;
   const pagination = paginationah({
      currentPage,
      totalItems: users.length,
      itemsPerPage,
   });

   const paginatedUsers = users.slice(
      (currentPage - 1) * itemsPerPage,
      currentPage * itemsPerPage
   );

   const pageNumbers = Array.from(
      { length: pagination.totalPages },
      (_, i) => i + 1
   );

   return (
      <div className="max-w-4xl mx-auto py-10">
         <h1 className="text-3xl font-bold text-center mb-8">Users List</h1>
         <ul className="space-y-4">
            {paginatedUsers.length > 0 ? (
               paginatedUsers.map((user, index) => (
                  <li key={index} className="bg-white shadow-lg rounded-lg p-6">
                     <div>
                        <h2 className="text-xl font-semibold">
                           {user.firstname} {user.lastname}
                        </h2>
                        <p className="text-gray-600">
                           {user.age} years old, {user.sex}
                        </p>
                        <p className="text-gray-500 text-sm">
                           Created at:{' '}
                           {new Date(user.createdAt).toLocaleString()}
                        </p>
                     </div>
                  </li>
               ))
            ) : (
               <p className="text-center text-gray-500">No users found.</p>
            )}
         </ul>

         <div className="flex justify-center space-x-4 mt-8">
            <button
               onClick={() => setCurrentPage(currentPage - 1)}
               disabled={pagination.previousPage === null}
               className={`px-4 py-2 rounded ${
                  pagination.previousPage === null
                     ? 'bg-gray-300'
                     : 'bg-blue-500 text-white'
               }`}
            >
               Previous
            </button>
            <div className="flex justify-center space-x-2 ">
               {pageNumbers.map((page) => (
                  <button
                     key={page}
                     onClick={() => setCurrentPage(page)}
                     className={`px-4 py-2 rounded ${
                        currentPage === page
                           ? 'bg-blue-500 text-white'
                           : 'bg-gray-300'
                     }`}
                  >
                     {page}
                  </button>
               ))}
            </div>

            <button
               onClick={() => setCurrentPage(currentPage + 1)}
               disabled={pagination.nextPage === null}
               className={`px-4 py-2 rounded ${
                  pagination.nextPage === null
                     ? 'bg-gray-300'
                     : 'bg-blue-500 text-white'
               }`}
            >
               Next
            </button>
         </div>
      </div>
   );
};

export default UsersList;

API Documentation

paginate({ currentPage, totalItems, itemsPerPage }): PaginationResult

  • currentPage: The current page number.
  • totalItems: The total number of items.
  • itemsPerPage: The number of items per page.

Returns:

  • totalPages: Total number of pages.
  • currentPage: Current page number.
  • nextPage: The next page number or null if it's the last page.
  • previousPage: The previous page number or null if it's the first page.

keywords

  • **paginationah
  • **typescript
  • **npm