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

simple-mongoose-pagination

v0.0.3

Published

simple mongoose pagination

Downloads

93

Readme

Simple Mongoose Pagination - Pagination Helper for Mongoose

A lightweight utility for managing pagination in Mongoose-based applications. This helper provides functions to calculate pagination details such as limit, skip, currentPage, and totalPages and totalItemsCount.

Installation

To install the package, use npm or yarn:

$ npm install simple-mongoose-pagination

or

 $ yarn add simple-mongoose-pagination

Usage

import { getPaginationQueryDetails } from 'simple-mongoose-pagination';

Example Usage

import { getPaginationQueryDetails } from 'simple-mongoose-pagination';
// Define your pagination query parameters
const paginationQuery = {
  pageNumber: 4,  // Page number (1-based index, 0 will default to 1)
  itemsPerPage: 2 // Number of items per page (0 will default to 1)
};
// Total number of items in your dataset
const totalItemsCount = 100;
// Get pagination details
const paginationDetails = getPaginationQueryDetails(paginationQuery, totalItemsCount);
console.log(paginationDetails);

Functions

getPaginationQueryDetails(paginationQuery: PaginationQueryInterface, totalItemsCount: number)

Calculates pagination details based on the provided query parameters and total items count.

Parameters

  • paginationQuery (object): Contains pageNumber and itemsPerPage.
  • totalItemsCount (number): Total number of items available.

Returns:

  • currentPage (number): The current page number.
  • limit (number): The number of items per page.
  • skip (number): The number of items to skip for the current page.
  • totalPages (number): The total number of pages.
{
  currentPage: 1,
  limit: 1,
  skip: 0,
  totalPages: 1
}

API Details

  • currentPage: The current page number (1-based index). Defaults to 1 if pageNumber is less than or equal to 0.
  • limit: The number of items per page. Defaults to 1 if itemsPerPage is less than or equal to 0.
  • skip: The number of items to skip.
  • totalPages: The total number of pages. Calculated based on the total number of items and items per page. Defaults to 1 if itemsPerPage is less than or equal to 0.

Technologies Used

  • JavaScript - The core language used for implementing the pagination logic.
  • TypeScript Type annotations are used to ensure type safety and enhance the development experience by providing clear definitions for the parameters and return types.
  • Jest Jest is a JavaScript testing framework maintained by Facebook, Inc. designed and built by Christoph Nakazawa with a focus on simplicity and support for large web applications.

Tests

Run the command below

$ npm run watch

or

  $ npm run test

Author