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

paginator

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paginator

Generic pagination algorithm wrapped in a CommonJS module

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
decreased by-9.13%
Maintainers
2
Weekly downloads
 
Created
Source

Paginator

Generic pagination algorithm wrapped in a CommonJS module.

Overview

When developing any kind of application that involves fetching an arbitrary number of elements from somewhere, you'll almost always want some form of pagination. It's impossible to tell in advance how the rest of the application will work, so a generic module that does -only- the pagination algorithm is useful. Enter Paginator.

Usage

Also see the documentation.

var Paginator = require("paginator");

// Arguments are `per_page` and `length`. `per_page` changes the number of
// results per page, `length` changes the number of links displayed.
var paginator = new Paginator(30, 7);

// Arguments are `total_results` and `current_page`. I hope these are self
// explanatory.
var pagination_info = paginator.build(10000, 50);

// The returned object will look something like this.
{
  total_pages: 334,
  current_page: 50,
  first_page: 46,
  last_page: 53,
  previous_page: 49,
  next_page: 51,
  has_previous_page: true,
  has_next_page: true,
  total_results: 10000,
  results: 30,
  first_result: 1470,
  last_result: 1499,
}

License

Licensed under an MIT license.

Keywords

FAQs

Package last updated on 15 Jan 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