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

mongoose-paginater

v0.1.0

Published

A pagination plugin for Mongoose.

Downloads

14

Readme

Mongoose Paginater

A Mongoose paginatation plugin, forked from Paginate for mongoose by song940.

paginater means paginator.

Installation

$ npm install mongoose-paginater

Usage

var mongoose = require('mongoose');
require('mongoose-paginater');

var options = {
  perPage: 10,
  delta  : 3,
  page   : req.query.page
};

var query = MyModel.find({deleted: false}).sort('name', 1);

query.paginater(options, function(err, res) {
  console.log(res); // => res = {
    //  results: [Document, ...],       // mongoose results
    //  current: 5,                     // current page number
    //  last: 12,                       // last page number
    //  prev: 4,                        // prev number or null
    //  next: 6,                        // next number or null
    //  pages: [ 2, 3, 4, 5, 6, 7, 8 ], // page numbers
    //  count: 125                      // document count
    //  render: '<ul>...</ul>'          // rendered pagination
  //};
});

Pagination Render

There is a pagination template in the render, and you can set options via paginater's settings.

The defaults:

{
    firstText: 'First',
    prevText: '&laquo;',
    nextText: '&raquo;',
    lastText: 'Last',
    totalText: 'Page %d of %d',
    path: '',  // path/to
    query: {}, // the page query is `page=n`, you can add other queries `{query1: 'val', q2: 'v2' }`
               // the pagination href will be like: `path/to?query1=val&q2=v2&page=n`
    classNameSpace: '',
    className: {
        wrap: 'pagination',
        active: 'active',
        disable: 'disabled'
    }
}

In the example folder, the render is used like this:

var options = {
    perPage: 10,
    delta  : 3,
    page   : req.query.page,
    classNameSpace: 'am',
    query: {q1: 'v1', q2: 'v2'}
};

var query = User.find().sort({'id': 1});

query.paginater(options, function(err, result) {
    res.render('index', {
        title: 'User List',
        pager: result
    });
});

The HTML is for Amaze UI Pagination:

<ul class="am-pagination">
  <li><span>Page 1 of 11</span></li>
  <li class="am-disabled"><a href="?q1=v1&q2=v2&page=1">« Prev</a></li>
  <li class="am-active"><a href="?q1=v1&q2=v2&page=1">1</a></li>
  <li><a href="?q1=v1&q2=v2&page=2">2</a></li>
  <li><a href="?q1=v1&q2=v2&page=3">3</a></li>
  <li><a href="?q1=v1&q2=v2&page=4">4</a></li>
  <li><a href="?q1=v1&q2=v2&page=5">5</a></li>
  <li><a href="?q1=v1&q2=v2&page=6">6</a></li>
  <li><a href="?q1=v1&q2=v2&page=7">7</a></li>
  <li><a href="?q1=v1&q2=v2&page=2">Next »</a></li>
  <li><a href="?q1=v1&q2=v2&page=11">Last</a></li>
</ul>
  • Bootstrap: just use it with default options.
  • UIKit: set classNameSpace: 'uk'

You can also use rendered HTML to other frameworks, just set classes you want.

Run Example

  1. Clone this project;
  2. Install packages and run it;
  3. Visit localhost:3007.
git clone https://github.com/Minwe/mongoose-paginater.git
cd mongoose-paginater/example
npm install
npm start

NPM

License

The MIT License