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

@careerday-jobs/node-paginator

v0.0.17

Published

Node.js-based custom pagination library

Downloads

86

Readme

npm version npm downloads official website

📚 Why node-paginator?

Every web developer should work on pagination at some point. We were using Mongo DB and node.js, and surprised by the fact that there is no single package we can just install and start using. If you're using Mongoose on Node.js and going to work on pagination? Then node-paginator is worth trying.

📦 Install

npm install @careerday-jobs/node-paginator

🪄 Basic Usage

import { NodePaginator } from '@careerday-jobs/node-paginator';

// Mongoose model you're going to look up
import { UserModel } from '/src/models/user.model.ts';

const paginatedResult = await NodePaginator.paginateByMongoose({
  pageNoParam: 1, // required
  pageSizeParam: 10, // required
  model: UserModel, // required
});

const { pageNo, pageSize, totalItemNo, totalPageNo, items } = paginatedResult;

🪄 Advanced Usage

  1. Use regex feature provided by MongoDB for simple search which is useful enough.
import { NodePaginator } from '@careerday-jobs/node-paginator';

import { UserModel } from '/src/models/user.model.ts';

const paginatedResult = await NodePaginator.paginateByMongoose({
  pageNoParam: 1, // required
  pageSizeParam: 10, // required
  model: UserModel, // required
  filteredFields: [ 
    'username', 
    'email', 
    'address'
  ], // field names you are trying to look up
  filter: 'michael' // search keyword
});

const { pageNo, pageSize, totalItemNo, totalPageNo, items } = paginatedResult;
  1. Add and queries and or queries you want to add on
import { NodePaginator } from '@careerday-jobs/node-paginator';

import { UserModel } from '/src/models/user.model.ts';

const paginatedResult = await NodePaginator.paginateByMongoose({
  pageNoParam: 1,
  pageSizeParam: 10,
  model: UserModel,
  filteredFields: [ 
    'username', 
  ],
  filter: 'michael',
  orQuery: { email: '[email protected]'}, // or query.  (should get user of which email address is '[email protected]', even if username does not include 'michael')
  andQuery: { company: 'google' } // and query (username should include 'michael' and he/she is working for google)
});

const { pageNo, pageSize, totalItemNo, totalPageNo, items } = paginatedResult;
  1. Putting sort option is possible. (Default is { _id: -1 })
import { NodePaginator } from '@careerday-jobs/node-paginator';

// Mongoose model you're going to look up
import { UserModel } from '/src/models/user.model.ts';

const paginatedResult = await NodePaginator.paginateByMongoose({
  pageNoParam: 1,
  pageSizeParam: 10,
  model: UserModel,
  filteredFields: [
    'username',
  ],
  filter: 'michael',
  orQuery: { email: '[email protected]'},
  andQuery: { company: 'google' },
  sortingOption: { createdAt: 1 } // show the oldest one first
});

const { pageNo, pageSize, totalItemNo, totalPageNo, items } = paginatedResult;
  1. Default maximum size of page is 100. But if you want it to exceed the limit, you can put one more parameter at the end.
import { NodePaginator } from '@careerday-jobs/node-paginator';

// Mongoose model you're going to look up
import { UserModel } from '/src/models/user.model.ts';

const paginatedResult = await NodePaginator.paginateByMongoose({
  pageNoParam: 1,
  pageSizeParam: 1000, // PLEASE DON'T DO THIS.....BUT SOMETIMES YOU NEED TO DO IT
  model: UserModel,
  filteredFields: [
    'username',
  ],
  filter: 'michael',
  orQuery: { email: '[email protected]'},
  andQuery: { company: 'google' },
  sortingOption: { createdAt: 1 },
  isNoMinResultLimit: true // If you want the page size to exceed 100, you should set this true
});

const { pageNo, pageSize, totalItemNo, totalPageNo, items } = paginatedResult;

Input Parameters

| parameter | type | description | |:-------------------------------| :------------------ |:--------------------------------------------------------------------| | pageNoParam (required) | number | current page number | | pageSizeParam (required) | numer | maximum number of data to display on a page | | model (required) | Model<any> | Mongoose model instance you want to look up | | filteredFields | string[] | field names of the model you want to look up | | filter | string | search keyword | | orQuery | FilterQuery | custom OR query | | andQuery | FilterQuery | custom AND query | | sortingOption | SortingOption | sort options applied to pagination results. (default: { _id: -1 }) | | isNoMinResultLimit | boolean | If page size can exceed 100 (default: false) |

Output Example

PaginatedResult {
      pageNo: 1,
      pageSize: 20,
      totalItemNo: 100,
      totalPageNo: 5,
      items: [
        {
          _id: new ObjectId("632a8d60d7b81199ad39d674"),
          email: '[email protected]',
          name: 'Hermann80',
          age: 71
        },
        {
          _id: new ObjectId("632a8d60d7b81199ad39d673"),
          email: '[email protected]',
          name: 'Agustina7',
          age: 58
        },
        ...
      ]
    }

⏳ Pagination Library On Frontend

Looking for a library which supports pagination on frontend? Why don't you check out react-paginator? It's way more efficient when you try both packages!

Contributors

@kunhokimcareerday

@starseeder0309

🔑 License

MIT @ 2022 CareerDay