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

pagination-apis

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pagination-apis

Page your api

  • 1.0.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Pagination-api

You only need to pass the data and the total query

Install

npm i pagination-apis

import


import Paginator from 'pagination-apis';

// or
const Paginator = require('pagination-apis');

Example with typeorm


const Paginator = require('pagination-apis');

const limit = 10;
const page = 1;
const paginate = new Paginator(page, limit);

// query builder
const [data, total] = await getRepository(User)
  .createQueryBuilder('user')
  .where('user.name = :id', { id: 1 })
  .skip(paginate.skip)
  .take(paginate.limit)
  .getManyAndCount();


// or find
const [data, total] = await userRepository.findAndCount({ 
  order: { 
    columnName: 'ASC',
  }, 
  skip: paginate.skip,
  take: paginate.limit, 
});

const result = paginate.paginate(data, total, '/api/example');

/*
output result

{ 
  totalPages: 4,
  countTotalData: 40,
  data: [
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
    { id: 1, name: 'example' },
  ],
  next: '/api/example?limit=10&page=3',
  previous: '/api/example?limit=10&page=1',
}
*/

Change url connector

const result = paginate.paginate(data, total, '/api/example?id=20', '&');

/api/example?id=20&limit=10&page=3

Keywords

FAQs

Package last updated on 15 Oct 2019

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