0.1.1 • Published 3 years ago

@heppokofrontend/pager v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@heppokofrontend/pager

MIT License Published on NPM test Maintainability Test Coverage Known Vulnerabilities @heppokofrontend/pager

Wrapping iterable objects with the pager function.

Usage

Installation:

npm install --save @heppokofrontend/pager

Instance

Properties

property nametypereadonlydescription
valuesT[]trueIterable objects to be managed by the pager.
viewsnumberNumber of items to be displayed per page.
set index()numberPage number to move to.
get index()numberThe current page number.
get lastIndex()numbertrueLast page number.
get page()T[]trueItems on the current page.It is recommended to cache the got values.

Methods

method nametypedescription
current()(index: number) => T[]Switch the current page to any page.
next()() => T[]Switch the current page to the next.
prev()() => T[]Switch the current page to the previous.

Syntax

new Pager(values[, views])

values

Any iterable object.

views

If specified, number of items to be displayed per page.

The default value is 5.

Example:

import { Pager } from '@heppokofrontend/pager';
// const { Pager } = require('@heppokofrontend/pager');

const pager = new Pager([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

pager.current(1); // => [6, 7, 8, 9, 10]
pager.current(-1); // => [1, 2, 3, 4, 5]
pager.current(pager.lastIndex); // => [6, 7, 8, 9, 10]
pager.current(100); // => [6, 7, 8, 9, 10]
pager.lastIndex // => 2

pager.views = 2; // Change the number of views per page.

pager.lastIndex // => 5
pager.current(1); // => [3, 4]
pager.current(200); // => [9, 10]
pager.page // => [9, 10]

pager.index = 3; // Change the current page number

pager.page // => [7, 8]
pager.current(7); // => [7, 8]

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

License

MIT