Socket
Socket
Sign inDemoInstall

@ssense/node-paginator

Package Overview
Dependencies
1
Maintainers
9
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @ssense/node-paginator

Paginator


Version published
Maintainers
9
Install size
101 kB
Created

Readme

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

Last updated on 16 Dec 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc