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

pagination

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

performance.js

83

lib/pagination.js

@@ -11,2 +11,6 @@ var util = require('util');

var translationCache = {
CURRENT_PAGE_REPORT : null
};
var translator = function(str) {

@@ -22,7 +26,8 @@ return translations[str];

current : 1,
translator : translator
translator : translator,
translationCache : false
};
for(var key in options) {
for(var keys = Object.keys(options), i = 0, len = keys.length; i < len; i++) {
try {
this.set(key, options[key]);
this.set(keys[i], options[keys[i]]);
} catch(e) {

@@ -155,16 +160,14 @@

SearchPaginator.prototype.render = function() {
var translator = this.options.translator;
var pages = [];
var i, link, className;
var i, className;
var result = this.getPaginationData();
var prelink = this.preparePreLink(result.prelink);
html = '';
html += '<div class="paginator">';
pages.push('<div class="paginator">');
if(result.pageCount < 2) {
pages.push('</div>');
return pages.join('');
html += '</div>';
return html;
}
if(result.previous) {
pages.push('<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + translator('PREVIOUS') + '</a>');
html += '<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + this.options.translator('PREVIOUS') + '</a>';
}

@@ -184,11 +187,10 @@

}
link = '<a href="' + prelink + 'page=' + result.range[i] + '" class="' + className + '">' + result.range[i] + '</a>';
pages.push(link);
html += '<a href="' + prelink + 'page=' + result.range[i] + '" class="' + className + '">' + result.range[i] + '</a>';
}
}
if(result.next) {
pages.push('<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + translator('NEXT') + '</a>');
html += '<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a>';
}
pages.push('</div>');
return pages.join('');
html += '</div>';
return html;
};

@@ -198,2 +200,3 @@ var ItemPaginator = function(options) {

this.set('pageLinks', 1);
};

@@ -204,39 +207,51 @@ module.exports.ItemPaginator = ItemPaginator;

ItemPaginator.prototype.renderCurrentPageReport = function(fromResult, toResult, totalResult) {
if (!this.options.translationCache) {
return this.options.translator('CURRENT_PAGE_REPORT').replace('{FromResult}', fromResult).replace('{ToResult}', toResult).replace('{TotalResult}', totalResult);
}
if (!translationCache.CURRENT_PAGE_REPORT) {
var template = "return '" + (this.options.translator('CURRENT_PAGE_REPORT').replace("'", "\'")
.replace('{FromResult}', "' + fromResult + '")
.replace('{ToResult}', "' + toResult + '")
.replace('{TotalResult}', "' + totalResult + '")) + "';";
translationCache.CURRENT_PAGE_REPORT = new Function('fromResult, toResult, totalResult', template);
}
return translationCache.CURRENT_PAGE_REPORT(fromResult, toResult, totalResult);
}
ItemPaginator.prototype.render = function() {
var translator = this.options.translator;
var result = this.getPaginationData();
var pages = [];
var prelink = this.preparePreLink(result.prelink);
pages.push('<div class="paginator">');
var currentPageReport = '<span class="paginator-current-report">';
currentPageReport += translator('CURRENT_PAGE_REPORT').replace('{FromResult}', result.fromResult).replace('{ToResult}', result.toResult).replace('{TotalResult}', result.totalResult);
currentPageReport += '</span>';
pages.push(currentPageReport);
var html = '';
html += '<div class="paginator">';
html += '<span class="paginator-current-report">';
html += this.renderCurrentPageReport(result.fromResult, result.toResult, result.totalResult);
html += '</span>';
if(result.first) {
pages.push('<a href="' + prelink + 'page=' + result.first + '" class="paginator-first">' + translator('FIRST') + '</a>');
html += '<a href="' + prelink + 'page=' + result.first + '" class="paginator-first">' + this.options.translator('FIRST') + '</a>';
} else {
pages.push('<span class="paginator-first">' + translator('FIRST') + '</span>');
html += '<span class="paginator-first">' + this.options.translator('FIRST') + '</span>';
}
if(result.previous) {
pages.push('<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + translator('PREVIOUS') + '</a>');
html += '<a href="' + prelink + 'page=' + result.previous + '" class="paginator-previous">' + this.options.translator('PREVIOUS') + '</a>';
} else {
pages.push('<span class="paginator-previous">' + translator('PREVIOUS') + '</span>');
html += '<span class="paginator-previous">' + this.options.translator('PREVIOUS') + '</span>';
}
if(result.next) {
pages.push('<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + translator('NEXT') + '</a>');
html += '<a href="' + prelink + 'page=' + result.next + '" class="paginator-next">' + this.options.translator('NEXT') + '</a>';
} else {
pages.push('<span class="paginator-next">' + translator('NEXT') + '</span>');
html += '<span class="paginator-next">' + this.options.translator('NEXT') + '</span>';
}
if(result.last) {
pages.push('<a href="' + prelink + 'page=' + result.last + '" class="paginator-last">' + translator('LAST') + '</a>');
html += '<a href="' + prelink + 'page=' + result.last + '" class="paginator-last">' + this.options.translator('LAST') + '</a>';
} else {
pages.push('<span class="paginator-last">' + translator('LAST') + '</span>');
html += '<span class="paginator-last">' + this.options.translator('LAST') + '</span>';
}
pages.push('</div>');
return pages.join('');
html += '</div>';
return html;
};

@@ -243,0 +258,0 @@

@@ -6,2 +6,3 @@ {

"author": "Nguyen Van Nhu",
"homepage": "https://github.com/vanng822/pagination",
"contributors": [],

@@ -13,3 +14,3 @@ "dependencies": [],

},
"version": "0.2.0"
"version": "0.2.1"
}

@@ -51,2 +51,43 @@ ## pagination

## Options
Object to pass to paginator classes (second argument when using create function)
### totalResult: {Integer}
Number of total items in result set
### prelink: {String}
Link to append the page-param
### rowsPerPage: {Integer}
Number of items per page, default to 10
### pageLinks: {Integer}
Number of links to create in page range, default to 5. This value will be ignored when using item pagination.
### current: {Integer}
Indicate which page is the current one. Page always starts with 1.
### translationCache: {Boolean}
To indicate if the result from CURRENT_PAGE_REPORT translation can be cached or not. Default is false.
The cache is global and will be the same for all instances therefore you should NOT set to true if you want different translations/formats.
### translator: {Function}
For translations of FIRST, NEXT, ... Simple example
var translations = {
'PREVIOUS' : 'Voorgaand',
'NEXT' : 'Volgende',
'FIRST' : 'Eerst',
'LAST' : 'Laatste',
'CURRENT_PAGE_REPORT' : 'Resulten {FromResult} - {ToResult} van {TotalResult}'
};
var item = new ItemPaginator({
prelink : '/',
pageLinks : 5,
current : 5,
totalResult : 100,
translator : function(str) {
return translations[str];
}
});

@@ -206,3 +206,4 @@ var assert = require('assert');

current : 5,
translator : null
translator : null,
translationCache : false
}, item.options);

@@ -209,0 +210,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