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

pagination-template

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination-template - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

.travis.yml

76

lib/pagination.js

@@ -7,2 +7,7 @@ 'use strict';

var FIRST_BUTTON = 'first';
var NEXT_BUTTON = 'next';
var PREVIOUS_BUTTON = 'previous';
var LAST_BUTTON = 'last';
/**

@@ -47,3 +52,3 @@ Function pagination, create a object

var ini = 1;
var pages = Math.floor((this.totalResults / this.rowsPerPage)) + ((this.totalResults % this.rowsPerPage)>0 ? 1:0);
var pages = getPages(this.totalResults, this.rowsPerPage);
var last = pages;

@@ -74,53 +79,27 @@ var end = pages;

//check domain option
var urlFinish = this.options.domain !== undefined ? (this.options.domain + this.urlOrigin) : (this.urlOrigin);
this.urlFinish = generateRootUrl.apply(this);
//check go first button
if(this.options!==undefined && this.options.showBeginingEnd){
var pagina = {}
pagina.url = generateUrl(urlFinish, 1, this.rowsPerPage);
pagina.actualPage = (this.pageAct===1);
pagina.index = 1;
pagina.specialButton = "first";
if(this.options && this.options.showBeginingEnd){
paginationResult.push(generatePosition.apply(this, [1, 1, FIRST_BUTTON]));
}
paginationResult.push(pagina);
if(this.options && this.options.showPreviousNext){
var page = this.pageAct - (this.pageAct===1 ? 0 : 1);
paginationResult.push(generatePosition.apply(this, [page, page, PREVIOUS_BUTTON]));
}
if(this.options!==undefined && this.options.showPreviousNext){
var pagina = {};
var page = this.pageAct - (this.pageAct===1 ? 0 : 1);
pagina.url = generateUrl(urlFinish, page, this.rowsPerPage);
pagina.actualPage = (this.pageAct===page);
pagina.index = page;
pagina.specialButton = "previous";
paginationResult.push(pagina);
}
for(var i = ini; i<= end; ++i){
var pagina = {};
paginationResult.push(generatePosition.apply(this, [i, i]))
};
pagina.url = generateUrl(urlFinish, i, this.rowsPerPage);
pagina.actualPage = (i===this.pageAct);
pagina.index = i;
paginationResult.push(pagina);
};
if(this.options!==undefined && this.options.showPreviousNext){
var pagina = {};
if(this.options && this.options.showPreviousNext){
var page = this.pageAct + (this.pageAct===last ? 0 : 1);
pagina.url = generateUrl(urlFinish, page, this.rowsPerPage);
pagina.actualPage = (i===page);
pagina.index = page;
pagina.specialButton = "next";
paginationResult.push(pagina);
paginationResult.push(generatePosition.apply(this, [page, page, NEXT_BUTTON]));
}
//check go last button
if(this.options!==undefined && this.options.showBeginingEnd){
var pagina = {};
pagina.url = generateUrl(urlFinish, last, this.rowsPerPage);
pagina.actualPage = (last===this.pageAct);
pagina.index = last;
pagina.specialButton = "last";
paginationResult.push(pagina);
paginationResult.push(generatePosition.apply(this, [last, last, LAST_BUTTON]));
}

@@ -130,4 +109,21 @@ return paginationResult;

function generatePosition(page, index, specialButton) {
return {
url: generateUrl(this.urlFinish, page, this.rowsPerPage),
actualPage: this.pageAct === page,
index: index,
specialButton: specialButton,
};
}
function generateRootUrl() {
return this.options.domain ? (this.options.domain + this.urlOrigin) : (this.urlOrigin);
}
function generateUrl(url, index, rowsPerPage){
return url + '/' + index + '/' + rowsPerPage;
}
}
function getPages(totalResults, rowsPerPage) {
return Math.floor((totalResults / rowsPerPage)) + ((totalResults % rowsPerPage)>0 ? 1:0);
}
{
"name": "pagination-template",
"version": "0.2.1",
"version": "0.3.0",
"description": "Pagination of results for use in a template",
"main": "index.js",
"scripts": {
"test": "mocha"
"test": "mocha",
"test:watch": "mocha -w"
},

@@ -18,3 +19,4 @@ "keywords": [

"chai": "~1.9.2",
"chai-as-promised": "~4.1.1"
"chai-as-promised": "~4.1.1",
"mocha": "^2.5.3"
},

@@ -21,0 +23,0 @@ "repository": {

pagination-template
===================
[![NPM version][npm-image]][npm-url]
[![Build Status](https://travis-ci.org/amadormf/pagination-template.svg?branch=master)](https://travis-ci.org/amadormf/pagination-template)
[![npm download][download-image]][download-url]
[npm-image]: http://img.shields.io/npm/v/pagination-template.svg?style=flat-square
[npm-url]: http://npmjs.org/package/pagination-template
[download-image]: https://img.shields.io/npm/dm/rc-calendar.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-calendar
Pagination of results for use in a templates in node.js. With 2 simple lines of code generate a pagination object to use in a template.

@@ -5,0 +15,0 @@

var Pagination = require('../index.js');
var async = require('async');

@@ -4,0 +3,0 @@ describe('Check all the pages of pagination', function(){

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