Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-paginate-v2

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-paginate-v2 - npm Package Compare versions

Comparing version 1.0.18 to 1.0.19

4

index.js

@@ -46,2 +46,3 @@ /**

var labelPrevPage = options.customLabels.prevPage ? options.customLabels.prevPage : 'prevPage';
var labelPagingCounter = options.customLabels.pagingCounter ? options.customLabels.pagingCounter : 'pagingCounter';

@@ -60,3 +61,3 @@ if (options.hasOwnProperty('offset')) {

const count = this.estimatedDocumentCount(query).exec();
const count = this.count(query).exec();

@@ -115,2 +116,3 @@ const model = this.find(query);

result[labelTotalPages] = pages;
result[labelPagingCounter] = ((page - 1) * limit) + 1;

@@ -117,0 +119,0 @@ // Set prev page

{
"name": "mongoose-paginate-v2",
"version": "1.0.18",
"version": "1.0.19",
"description": "A cursor based custom pagination library for Mongoose with customizable labels.",

@@ -34,3 +34,4 @@ "main": "index.js",

"homepage": "https://github.com/aravindnc/mongoose-paginate-v2#readme",
"dependencies": {},
"dependencies": {
},
"devDependencies": {

@@ -41,3 +42,4 @@ "babel-cli": "^6.26.0",

"mocha": "^5.2.0",
"mongoose": "^5.2.4"
"mongoose": "^5.2.4",
"chai": "^4.2.0"
},

@@ -44,0 +46,0 @@ "engines": {

@@ -69,2 +69,3 @@ # mongoose-paginate-v2

* `nextPage` {Number} - Next page number if available or NULL
* `pagingCounter` {Number} - The starting sl. number of first document.

@@ -94,2 +95,3 @@ Please note that the above properties can be renamed by setting customLabel attribute.

// result.prevPage = null
// result.pagingCounter = 1

@@ -110,2 +112,3 @@ });

* totalPages
* pagingCounter

@@ -125,2 +128,3 @@ You should pass the names of the properties you wish to changes using `customLabels` object in options.

totalPages: 'pageCount'
pagingCounter: 'slNo'
};

@@ -142,2 +146,3 @@

// result.prev = null [here prevPage becomes prev]
// result.slNo = 1 [here pagingCounter becomes slNo]

@@ -220,5 +225,5 @@ // result.hasNextPage = true [not changeable]

## Thanks
This is a advanced version of mongoose-paginate forked from [Mongoose Paginate](https://www.npmjs.com/package/mongoose-paginate). Thanks to the initial author [Edward Hotchkiss](https://www.npmjs.com/~edwardhotchkiss)
This is a advanced version of mongoose-paginate forked from [Mongoose Paginate](https://www.npmjs.com/package/mongoose-paginate). Credits to the initial author [Edward Hotchkiss](https://www.npmjs.com/~edwardhotchkiss)
## License
[MIT](LICENSE)

@@ -1,3 +0,1 @@

// @author edwardhotchkiss
'use strict';

@@ -17,2 +15,3 @@

date: Date,
price: Number,
author: {

@@ -35,3 +34,3 @@ type: mongoose.Schema.ObjectId,

before(function(done) {
mongoose.connection.db.dropDatabase(done);
mongoose.connection.db.dropDatabase(done);
});

@@ -42,8 +41,11 @@

let date = new Date();
return Author.create({ name: 'Arthur Conan Doyle' }).then(function(author) {
return Author.create({ name: 'Arthur Conan Doyle' }).then(function(author) {
for (let i = 1; i <= 100; i++) {
book = new Book({
title: 'Book #' + i,
date: new Date(date.getTime() + i),
author: author._id
// price: Math.floor(Math.random() * (1000 - 50) ) + 50,
price: (i*5) + i,
title: 'Book #' + i,
date: new Date(date.getTime() + i),
author: author._id
});

@@ -54,115 +56,126 @@ books.push(book);

});
});
afterEach(function() {
delete mongoosePaginate.paginate.options;
});
it('returns promise', function() {
let promise = Book.paginate();
it('promise return test', function() {
let promise = Book.paginate();
expect(promise.then).to.be.an.instanceof(Function);
});
it('calls callback', function(done) {
Book.paginate({}, {}, function(err, result) {
it('callback test', function(done) {
Book.paginate({}, {}, function(err, result) {
expect(err).to.be.null;
expect(result).to.be.an.instanceOf(Object);
done();
});
});
});
describe('paginates', function() {
it('with criteria', function() {
return Book.paginate({ title: 'Book #10' }).then((result) => {
console.log('with criteria logging ==================');
console.log('result:', result);
expect(result.docs).to.have.length(1);
expect(result.docs[0].title).to.equal('Book #10');
});
});
it('with default options (page=1, limit=10, lean=false)', function() {
return Book.paginate().then(function(result) {
it('with limit and page', function() {
var query = {
title: {
$in : [/Book/i]
}
};
var options = {
sort: { _id: 1}
};
return Book.paginate(query, options ).then((result) => {
expect(result.docs).to.have.length(10);
expect(result.docs[0]).to.be.an.instanceof(mongoose.Document);
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(10);
expect(result.page).to.equal(1);
expect(result.totalPages).to.equal(10);
expect(result.offset).to.equal(0);
expect(result.docs[0].title).to.equal('Book #1');
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(10);
expect(result.page).to.equal(1);
expect(result.pagingCounter).to.equal(1);
expect(result.hasPrevPage).to.equal(false);
expect(result.hasNextPage).to.equal(true);
expect(result.prevPage).to.equal(null);
expect(result.nextPage).to.equal(2);
expect(result.totalPages).to.equal(10);
});
});
it('with custom default options', function() {
mongoosePaginate.paginate.options = {
limit: 20,
lean: true
};
return Book.paginate().then(function(result) {
expect(result.docs).to.have.length(20);
expect(result.limit).to.equal(20);
expect(result.docs[0]).to.not.be.an.instanceof(mongoose.Document);
it('with $where condition', function() {
var query = {
title: {
$in : [/Book/i]
} ,
'$where': 'this.price < 100'
};
var options = {
sort: { price: -1},
page: 2
};
return Book.paginate(query, options ).then((result) => {
expect(result.docs).to.have.length(6);
expect(result.docs[0].title).to.equal('Book #6');
expect(result.totalDocs).to.equal(16);
expect(result.limit).to.equal(10);
expect(result.page).to.equal(2);
expect(result.pagingCounter).to.equal(11);
expect(result.hasPrevPage).to.equal(true);
expect(result.hasNextPage).to.equal(false);
expect(result.prevPage).to.equal(1);
expect(result.nextPage).to.equal(null);
expect(result.totalPages).to.equal(2);
});
});
it('with offset and limit', function() {
return Book.paginate({}, { offset: 30, limit: 20 }).then(function(result) {
expect(result.docs).to.have.length(20);
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(20);
expect(result.offset).to.equal(30);
expect(result).to.not.have.property('page');
expect(result).to.not.have.property('pages');
it('with custom labels', function() {
var query = {
title: {
$in : [/Book/i]
}
};
const myCustomLabels = {
totalDocs: 'itemCount',
docs: 'itemsList',
limit: 'perPage',
page: 'currentPage',
nextPage: 'next',
prevPage: 'prev',
totalPages: 'pageCount',
pagingCounter: 'pageCounter'
};
var options = {
sort: { _id: 1},
limit: 10,
page: 5,
customLabels: myCustomLabels
};
return Book.paginate(query,options).then((result) => {
expect(result.itemsList).to.have.length(10);
expect(result.itemsList[0].title).to.equal('Book #41');
expect(result.itemCount).to.equal(100);
expect(result.perPage).to.equal(10);
expect(result.currentPage).to.equal(5);
expect(result.pageCounter).to.equal(41);
expect(result.hasPrevPage).to.equal(true);
expect(result.hasNextPage).to.equal(true);
expect(result.prev).to.equal(4);
expect(result.next).to.equal(6);
expect(result.pageCount).to.equal(10);
});
});
it('with page and limit', function() {
return Book.paginate({}, { page: 1, limit: 20 }).then(function(result) {
expect(result.docs).to.have.length(20);
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(20);
expect(result.page).to.equal(1);
expect(result.totalPages).to.equal(5);
expect(result).to.not.have.property('offset');
});
});
it('with zero limit', function() {
return Book.paginate({}, { page: 1, limit: 0 }).then(function(result) {
expect(result.docs).to.have.length(0);
expect(result.totalDocs).to.equal(100);
expect(result.limit).to.equal(0);
expect(result.page).to.equal(1);
expect(result.totalPages).to.equal(Infinity);
});
});
it('with select', function() {
return Book.paginate({}, { select: 'title' }).then(function(result) {
expect(result.docs[0].title).to.exist;
expect(result.docs[0].date).to.not.exist;
});
});
it('with sort', function() {
return Book.paginate({}, { sort: { date: -1 } }).then(function(result) {
expect(result.docs[0].title).to.equal('Book #100');
});
});
it('with populate', function() {
return Book.paginate({}, { populate: 'author' }).then(function(result) {
expect(result.docs[0].author.name).to.equal('Arthur Conan Doyle');
});
});
describe('with lean', function() {
it('with default leanWithId=true', function() {
return Book.paginate({}, { lean: true }).then(function(result) {
expect(result.docs[0]).to.not.be.an.instanceof(mongoose.Document);
expect(result.docs[0].id).to.equal(String(result.docs[0]._id));
});
});
it('with leanWithId=false', function() {
return Book.paginate({}, { lean: true, leanWithId: false }).then(function(result) {
expect(result.docs[0]).to.not.be.an.instanceof(mongoose.Document);
expect(result.docs[0]).to.not.have.property('id');
});
});
});
});
after(function(done) {
mongoose.connection.db.dropDatabase(done);
mongoose.connection.db.dropDatabase(done);
});

@@ -169,0 +182,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc