New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pagination-logic

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination-logic

Pure Javascript pagination logic without UI component

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37
increased by37.04%
Maintainers
1
Weekly downloads
 
Created
Source

pagination-logic

Pure Javascript pagination logic without UI component

Installation

npm install pagination-logic

Usage


var pagination = require('pagination-logic');

/*
Provide a pageObject
(total -- Number of items that will be paginated
 single -- Number of items per page
 pageSize -- Number of pageItem that will be shown
 currentPage -- Number of the page you want to get
 pageLinkRule -- a funtion you link to the page you want, param is pageNumber
)
*/
var paginationResult = pagination(pageObject)

Result Attributes

NameDescription
pagesA list about the elements showed in current page, each elements contains {number, link, isActive}
pageCounttotal page number
currentPagethe currently active page
hasPreviouswhether the current page has previous page
hasNextwhether the current page has next page
pageSizeNumber of elements showing in the current page
previousPagethe previous page object which contains {number, link, isActive}
nextPagethe next page object which contains {number, link, isActive}
firstPagethe first page object which contains {number, link, isEllipsis}. ps: isEllipsis means whether you need '......', like 1...5,6,7,8...100
lastPagethe final page object which contains {number, link, isEllipsis}. ps: isEllipsis means whether you need '......', like 1...5,6,7,8...100

###Example

const test = require('ava');
const logicPaginate = require('../src/pagination-logic');


test('middle', function(t) {
    const input = {
        total: 50,
        single:6,
        pageSize:4,
        currentPage: 6,
        pageLinkRule: (pageNumber) => {
            return `/page/${pageNumber}`;
        }
    };
    const expectedOutput = {
           pages: [
                      {
                          number: 4,
                          link: '/page/4',
                          isActive: false,
                      },
                      {
                          number: 5,
                          link: '/page/5',
                          isActive: false,
                      },
                      {
                          number: 6,
                          link: '/page/6',
                          isActive: true,
                      },
                      {
                          number: 7,
                          link: '/page/7',
                          isActive: false,
                      }
                  ],
                  pageCount: 9,
                  currentPage: 6,
                  hasPrevious: true,
                  hasNext: true,
                  previousPage: {
                      number: 5,
                      link: '/page/5',
                      isActive: false,
                  },
                  nextPage: {
                      number: 7,
                      link: '/page/7',
                      isActive: false,
                  },
                  pageSize: 4,
                  firstPage:{
                      number:1,
                      link: '/page/1',
                      isEllipsis: true
                  },
                  lastPage:{
                      number:9,
                      link: '/page/9',
                      isEllipsis: true
                  },

       };
    t.deepEqual(logicPaginate(input), expectedOutput)
});

FAQs

Package last updated on 08 Oct 2016

Did you know?

Socket

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.

Install

Related posts

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