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

skaleb-simple-paginator

v1.0.8

Published

Simple client for client-side pagination making use of generic types and allowing for chainable methods

Downloads

6

Readme

Simple Paginator

NPM Version Build Status Quality Gate Status Bugs Code Smells Coverage

This simple paginator was built to allow for easily paginating through arrays that may be client side. Usually these types of things take place when the data is being sourced from either a database or API but on the odd occasion, it could arise that you already have too much data client side. This paginator provides a simple interface to manipulate these arrays.

This paginator was built specifically with TypeScript in mind.

Contents

Installation

To install this package you can simply use the install command below.

$ npm i --save skaleb-simple-paginator

Usage

Importing

Importing the package into your class.

import { SimplePaginator } from 'skaleb-simple-paginator'

// Variables that will be used below in `Instantiation`
const pageSize: number = 5
const pageNumber: number = 1
const arr: Array<string> = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ]

Instantiating

Instantiating a new instance of the paginator.

const paginator = new SimplePaginator<string>()
  .setArray(arr)
  .setPageSize(pageSize)
  .setPageNumber(pageNumber)

// You can also instantiate the `SimplePaginator` with the variables in the constructor
const paginator = new SimplePaginator(arr, pageNumber, pageSize)

Set Initial Dataset

.setArray(x) sets the array to be paginated. The returned items should retain their types.

// The paginator will use the array defined above to paginate
paginator.setArray(arr)

Get Current Page

.getPage() returns the number of items specified which are on the page specified.

// Will return `PaginatorResponse` with five items being equal to
// [ 'a', 'b', 'c', 'd', 'e' ]
return paginator.getPage()

Increase Page Number

.incrementPage() increases the page number within the paginator by one.

// Will return `PaginatorResponse` with two items being equal to
// [ 'f', 'g' ]
return paginator.incrementPage()
  .getPage()

Decrease Page Number

.decrementPage() decreases the page number within the paginator by one. If the page number is less than one then the page number defaults to one.

// Will return `PaginatorResponse` with five items being equal to
// [ 'a', 'b', 'c', 'd', 'e' ]
return paginator.decrementPage()
  .getPage()

Set Page Number

.setPageNumber(x) sets the page number within the paginator to the value specified. If the value specified is less than one then the page number defaults to one.

// Will return `PaginatorResponse` with two items being equal to
// [ 'f', 'g' ]
return paginator.setPageNumber(2)
  .getPage()

// Will return `PaginatorResponse` with five items being equal to
// [ 'a', 'b', 'c', 'd', 'e' ]
return paginator.setPageNumber(-1)
  .getPage()

Set Page Size

.setPageSize(x) sets the number of items to be returned in the PaginatorResponse for any given page to the value specified. If the value specified is less than one then the page size defaults to one.

// Will return `PaginatorResponse` with three items being equal to
// [ 'a', 'b', 'c' ]
return paginator.setPageSize(3)
  .getPage()

// Will return `PaginatorResponse` with one item being equal to
// [ 'a' ]
return paginator.setPageSize(-1)
  .getPage()

Tests

This project is completely covered by unit tests. Various cases have been accounted for both in the codebase and in the tests covering it. If a bug is picked up regarding the test suite or code, feel free to make a contribution to help correct the bug.

To run the tests, you can simply run the following test command/s.

npm run lint
npm run test
npm run coverage

Issues

If you find any problems while working with this library, please log an issue here so that development can begin to rectify the error.

Contributions

This project is completely open source and as such, you are invited to make contributions. Fork the project, make some changes and make the pull request. Should you have any feedback regarding the functionality, please don't hesitate to open an issue so this can be resolved. Please ensure that any pull requests have unit tests that cover any additional functionality.

License

MIT License

Copyright (c) 2019 Alex Pickering