npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

paginatedjs

v1.1.1

Published

A simple JS class to paginate arrays

Downloads

20

Readme

PaginatedJS

Build Status

A simple JS class to paginate arrays.

Getting started

Installation

Browser

You just have to download the minify js file paginate-js.min.js, and import it into your HTML :

<script src="/path/to/paginate-js.min.js"></script>

NodeJS

Install from NPM or Yarn

npm i -S paginatedjs

# OR

yarn add paginatedjs

And import it into your NodeJS project

const Pagination = require("paginatedjs").Pagination

// OR

import { Pagination } from 'paginatedjs'

And... that's it ! :)

Usage

let list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
let perPage = 3

let page = []
const pagination = new Pagination(list, perPage)

// gives you [1,2,3]
pagination.firstPage()
page = pagination.getPaginated(true)

// gives you [13]
pagination.lastPage()
page = pagination.getPaginated(true)

// gives you [10,11,12]
pagination.prevPage()
page = pagination.getPaginated(true)

// gives you [13]
pagination.nextPage() // next page does not exists
page = pagination.getPaginated(true)

// gives you [4,5,6]
pagination.goToPage(2)
page = pagination.getPaginated(true)

// gives you [13]
pagination.goToPage(20) // page 20 does not exists
page = pagination.getPaginated(true)

// gives you [7,8,9]
pagination.firstPage().nextPage().nextPage()
page = pagination.getPaginated(true)

// gives you [1,2,3]
pagination.reset()
page = pagination.getPaginated(true)

// gives you [[1,2,3], [4,5,6], [7,8,9], [10,11,12], [13]]
let chunked_list = pagination.chunkList()

// gives you {1: [1,2,3], 2: [4,5,6], 3: [7,8,9], 4: [10,11,12], 5: [13]}
let chunked_list = pagination.chunkList(true)


API

Pagination class

Properties

Nomenclature : {Return type} Class.property

Get the current page number

{Number} Pagination.pageNumber

Get the number of pages

{Number} Pagination.nbPages

Get the list

{Array} Pagination.list

Get the number of entries per page

{Number} Pagination.perPage

Methods

Nomenclature : {Return type} Class.method(<(optional) arg | type>, [<(optional) arg | type>])

Get list length

{Number} Pagination.count()

Returns true if pagination not ended, false otherwise

{Boolean} Pagination.hasMore()

Set pagination to the previous page

{Pagination} Pagination.prevPage()

Set pagination to the next page

{Pagination} Pagination.nextPage()

Set pagination to the first page

{Pagination} Pagination.firstPage()

Set pagination to the last page

{Pagination} Pagination.lastPage()

Returns chunked list compared to pagination position Returns Chunk class instance if to_array argument is false, array otherwise

{Chunk|Array} Pagination.getPaginated(<(optional) to_array | Boolean>)

Set pagination to the page number passed as argument

{Pagination} Pagination.goToPage(<page_number | Number>)

Reset pagination

{Pagination} Pagination.reset()

Returns a chunked array or page indexed object of the list

{Array|Object} Pagination.chunkList(
    <(optional) indexed_by_page | Boolean>, 
    <(optional) to_array | Boolean>
)

Chunk class

Methods

Nomenclature : {Return type} Class.method(<arg | type>, [<arg | type>])

Get count length

{Number} Chunk.count()
{Boolean} Chunk.empty()
{Boolean} Chunk.notEmpty()

Get the first element

{Mixed} Chunk.first()

Get the last element

{Mixed} Chunk.last()

Get nth element (begins to 1)

{Mixed} Chunk.nth(<n | Number>)

Returns true if list contains value passed as argument, false otherwise

{Boolean} Chunk.contains(<value | mixed>)

Returns chunked list as an array

{Array} Chunk.toArray()

Paginate the chunked list

{Pagination} Chunk.paginate(<perPage | Number>)