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

@ssense/node-paginator

Package Overview
Dependencies
Maintainers
9
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ssense/node-paginator

Paginator

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
9
Created
Source

Paginator

Paginator library in NodeJS to facilitate REST pagination

Build Status Coverage Status Latest Stable Version Known Vulnerabilities

Table of Contents

Installation

npm install --save @ssense/node-paginator

Usage

import { Paginator } from '@ssense/node-paginator';

const items = ['item1', 'item2', 'item3']; // from your DB returned collection...
const perPage = 1;
const currentPage = 2;
const paginator: Paginator = new Paginator(items, items.length, perPage, currentPage);

// Transform paginator to object, use this as rour REST response
const paginated = paginator.transform();

console.log(paginated);
/*
output
{
    total: 3,
    per_page: 1,
    current_page: 2,
    last_page: 3,
    from: 2,
    to: 4,
    links:{
        previous: '/?page=1&foo=bar#foobar',
        current: '/?page=2&foo=bar#foobar',
        next: '/?page=3&foo=bar#foobar'
    },
    data: [ 'item1', 'item2', 'item3' ]
}
*/

Tips and tricks

Append queries string to URL
// Append one query string to URL
paginator.append('key', 'value');

// Appends multiple queries to URL
paginator.appends({
    foo: 'bar'
});
Add fragment to URL
// Add foobar fragment to URL
paginator.fragment('foobar');

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Keywords

FAQs

Package last updated on 16 Dec 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