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.13 to 1.0.14

0

.github/ISSUE_TEMPLATE/bug_report.md

@@ -0,0 +0,0 @@ ---

@@ -0,0 +0,0 @@ # Contributor Covenant Code of Conduct

67

index.js

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

var Promise = require('bluebird');
/**

@@ -20,2 +18,3 @@ * @param {Object} [query={}]

*/
function paginate(query, options, callback) {

@@ -28,3 +27,3 @@ query = query || {};

var sort = options.sort;
var collation = options.collation;
var collation = options.collation || {};
var populate = options.populate;

@@ -50,3 +49,3 @@ var lean = options.lean || false;

} else if (options.hasOwnProperty('page')) {
page = options.page;
page = parseInt(options.page);
skip = (page - 1) * limit;

@@ -59,40 +58,37 @@ } else {

var promises = {
docs: Promise.resolve([]),
count: this.countDocuments(query).exec()
};
const count = this.countDocuments(query).exec()
const model = this.find(query)
model.select(select)
model.sort(sort)
model.collation(collation)
model.lean(lean);
if (limit) {
var query = this.find(query)
.select(select)
.sort(sort)
.collation(collation)
.skip(skip)
.limit(limit)
.lean(lean);
model.skip(skip);
model.limit(limit);
}
if (populate) {
[].concat(populate).forEach(function(item) {
query.populate(item);
});
}
if (populate) {
model.populate(populate)
}
promises.docs = query.exec();
let docs = model.exec();
if (lean && leanWithId) {
promises.docs = promises.docs.then(function(docs) {
docs.forEach(function(doc) {
doc.id = String(doc._id);
});
return docs;
if (lean && leanWithId) {
docs = docs.then(function(docs) {
docs.forEach(function(doc) {
doc.id = String(doc._id);
});
}
return docs;
});
}
return Promise.props(promises)
.then(function(data) {
return Promise.all([count, docs])
.then(function(values) {
var result = {
[labelDocs]: data.docs,
[labelTotal]: data.count,
[labelDocs]: values[1],
[labelTotal]: values[0],
[labelLimit]: limit

@@ -107,3 +103,3 @@ };

const pages = Math.ceil(data.count / limit) || 1;
const pages = Math.ceil(values[0] / limit) || 1;

@@ -133,5 +129,4 @@ result.hasPrevPage = false;

return result;
return Promise.resolve(result);
})
.asCallback(callback);
}

@@ -138,0 +133,0 @@

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

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

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

@@ -39,0 +37,0 @@ "babel-cli": "^6.26.0",

@@ -0,0 +0,0 @@ # mongoose-paginate-v2

@@ -0,0 +0,0 @@ // @author edwardhotchkiss

Sorry, the diff of this file is not supported yet

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