Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
pagination
Advanced tools
Pagination for javascript/nodejs
var pagination = require('pagination');
var paginator = pagination.create('search', {prelink:'/', current: 1, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.render());
var pagination = require('pagination');
var paginator = new pagination.SearchPaginator({prelink:'/', current: 10, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.render());
// output (without newlines)
<div class="paginator">
<a href="/?page=9" class="paginator-previous">Previous</a>
<a href="/?page=8" class="paginator-page paginator-page-first">8</a>
<a href="/?page=9" class="paginator-page">9</a>
<a href="/?page=10" class="paginator-current">10</a>
<a href="/?page=11" class="paginator-page">11</a>
<a href="/?page=12" class="paginator-page paginator-page-last">12</a>
<a href="/?page=11" class="paginator-next">Next</a>
</div>
var pagination = require('pagination');
var paginator = new pagination.ItemPaginator({prelink:'/', slashSeparator: true, current: 3, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.render());
// output (without newlines)
<div class="paginator">
<span class="paginator-current-report">Results 401 - 600 of 10020</span>
<a href="/page/1" class="paginator-first">First</a>
<a href="/page/2" class="paginator-previous">Previous</a>
<a href="/page/4" class="paginator-next">Next</a>
<a href="/page/51" class="paginator-last">Last</a>
</div>
var pagination = require('pagination');
var paginator = new pagination.SearchPaginator({prelink:'/', current: 3, rowsPerPage: 200, totalResult: 10020});
console.log(paginator.getPaginationData());
// output
{ prelink: '/',
current: 3,
previous: 2,
next: 4,
first: 1,
last: 51,
range: [ 1, 2, 3, 4, 5 ],
fromResult: 401,
toResult: 600,
totalResult: 10020,
pageCount: 51 }
<html>
<head>
<script src="../release/pagination.full.min.js"></script>
</head>
<body>
<div id="paging"></div>
<script type="text/javascript">
(function() {
var paginator = new pagination.ItemPaginator({prelink:'/', current: 3, rowsPerPage: 200, totalResult: 10020});
var html = paginator.render();
var paginator = pagination.create('search', {prelink:'/', current: 1, rowsPerPage: 200, totalResult: 10020});
html += paginator.render();
document.getElementById("paging").innerHTML = html;
})();
</script>
</body>
</html>
You can browse example folder for more. Release folder contains all mimified versions for browser. To customize your need you can use ./bin/build.js -h
options
See Options bellowSee also http://developer.yahoo.com/ypatterns/navigation/pagination/search.html
options
See Options bellowSee also http://developer.yahoo.com/ypatterns/navigation/pagination/item.html
options
See Options bellowThis class will render the markup as desired. The options must contains property "template" It can be either a template string or a compiled template. The local variables available in the template are
prelink
StringpreparedPreLink
Stringcurrent
Integerprevious
Integernext
Integerfirst
Integerlast
Integerrange
ArrayfromResult
IntegertoResult
IntegertotalResult
IntegerpageCount
Integertranslations
Object with properties NEXT, PREVIOUS, FIRST, LAST, CURRENT_PAGE_REPORTReturn an object contains data for rendering markup. See example above.
Set value to a single for option. See options section bellow
prelink
StringAppend page param to the link
Return the rendered markup
type
Stringoptions
Object see Options section bellowWrapper for create instance of classes above
See pagination.TemplateEngine.compile bellow
str
Template stringoptions
object which can contains .open .close .cache and .idObject to pass to paginator classes (second argument when using create function)
Number of total items in result set
Link to append the page-param
Number of items per page, default to 10
Number of links to create in page range, default to 5. This value will be ignored when using item pagination.
Indicate which page is the current one. Page always starts with 1.
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 which have specified translationCacheKey as bellow.
For supporting multiple versions of translation of CURRENT_PAGE_REPORT. It can use for multilanguages or different formats. Default is "en"
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];
}
});
The name of the page parameter. Default is "page"
Indicate if using slash instead of equal sign, ie /page/2 instead of /?page=2, default is false.
This can be a template string or a compiled template (function). The compiled function will be called with an object as argument.
Template engine is taking mostly from https://github.com/vanng822/ejs which is a fork of https://github.com/visionmedia/ejs
FAQs
Pagination for javascript/nodejs
The npm package pagination receives a total of 2,866 weekly downloads. As such, pagination popularity was classified as popular.
We found that pagination demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.