Giter VIP home page Giter VIP logo

any-pagination's Introduction

Any Pagination ๐Ÿ“„

Useful and easy helper to create pagination components.

Table of contents

Instalation ๐Ÿ“ฆ

$ npm install any-pagination

or

$ yarn add any-pagination

Usage โœจ

import { paginate } from "any-pagination";

const pages = paginate({
  total: 100,
  perPage: 5,
  currentPage: 1,
});

// the output array:

[1, 2, 3, 0, 18, 19, 20];

// now, you can make your custom pagination component using the output array

What does the output array mean? ๐Ÿค”

The output array indicates the structure of the pagination component, for example:

import { paginate } from "any-pagination";

const pages = paginate({
  total: 230,
  perPage: 10,
  currentPage: 15,
});

// [1,0,14,15,16,0,23]

The rendered pagination should have the following structure:

Alt text

You are free to handle all the events, styles and behaviours of your component, the paginate helper only helps you to build the structure of your pagination component.

Output array:

number {n โˆˆ N} (1,2,3...โˆž) indicates a page number

zero (0) indicates the ellipsis separator, (...)

Types ๐Ÿฆบ

Any-Pagination was made with TypeScript โค๏ธ so, you can use the configuration types as you need:

import type { PaginationConfig } from "any-pagination";

const config: PaginationConfig;

API Refernce ๐Ÿ“ƒ

Item Description Type
paginate The helper function to make the pagination structure (config: PaginationConfig) => number[]
config.total The total numbers of items in your database number
config.perPage The number of items showed per page number
config.currentPage The current page in your pagination number

Examples โœ”

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.