# paginationator [![NPM version](https://img.shields.io/npm/v/paginationator.svg?style=flat)](https://www.npmjs.com/package/paginationator) [![NPM downloads](https://img.shields.io/npm/dm/paginationator.svg?style=flat)](https://npmjs.org/package/paginationator) [![Build Status](https://img.shields.io/travis/doowb/paginationator.svg?style=flat)](https://travis-ci.org/doowb/paginationator) Paginate an array into pages of items. ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm install --save paginationator ``` ![image](https://cloud.githubusercontent.com/assets/995160/9802527/ca15f300-57e8-11e5-96db-523ea5a0572e.png) ## Usage ```js var paginationator = require('paginationator'); ``` ## API ### [paginationator](index.js#L34) Paginate an array with given options and return a `Page` object containing an array of `pages` with pagination information. **Params** * `arr` **{Array}**: Array of items to paginate * `options` **{Object}**: Additional options to control pagination * `options.limit` **{Number}**: Number of items per page (defaults to 10) * `returns` **{Object}**: paginated pages **Example** ```js var pages = paginationator([1, 2, 3, 4, 5], {limit: 2}); //=> { pages: [ //=> { idx: 0, total: 3, current: 1, items: [1, 2], first: 1, last: 3, next: 2 }, //=> { idx: 1, total: 3, current: 2, items: [3, 4], first: 1, last: 3, prev: 1, next: 3 }, //=> { idx: 2, total: 3, current: 3, items: [5], first: 1, last: 3, prev: 2 } //=> ]} ``` ### [Page](lib/page.js#L14) Page constructor **Params** * `page` **{Object}**: optional page object to populate initial values. **Example** ```js var page = new Page(); ``` ### [Pages](lib/pages.js#L16) Pages constructor **Params** * `pages` **{Array}**: Optional array of pages to initialize the `pages` array. **Example** ```js var pages = new Pages(); ``` ### [.addPage](lib/pages.js#L37) Add a page to the list. **Params** * `page` **{Object}**: Plain object or instance of a `Page` * `returns` **{Object}**: Returns the instance for chaining **Example** ```js pages.addPage({items: [1, 2, 3]}); ``` ### [.addPages](lib/pages.js#L55) Add an array of pages to the list. **Params** * `pages` **{Object}**: Array of page objects * `returns` **{Object}**: Returns the instance for chaining **Example** ```js pages.addPages([...]); ``` ## About ### Related projects * [assemble](https://www.npmjs.com/package/assemble): Get the rocks out of your socks! Assemble makes you fast at creating web projects… [more](https://github.com/assemble/assemble) | [homepage](https://github.com/assemble/assemble "Get the rocks out of your socks! Assemble makes you fast at creating web projects. Assemble is used by thousands of projects for rapid prototyping, creating themes, scaffolds, boilerplates, e-books, UI components, API documentation, blogs, building websit") * [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine… [more](https://github.com/jonschlinkert/templates) | [homepage](https://github.com/jonschlinkert/templates "System for creating and managing template collections, and rendering templates with any node.js template engine. Can be used as the basis for creating a static site generator or blog framework.") * [verb](https://www.npmjs.com/package/verb): Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… [more](https://github.com/verbose/verb) | [homepage](https://github.com/verbose/verb "Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used on hundreds of projects of all sizes to generate everything from API docs to readmes.") ### Contributing Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). ### Building docs _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_ To generate the readme and API documentation with [verb](https://github.com/verbose/verb): ```sh $ npm install -g verb verb-generate-readme && verb ``` ### Running tests Install dev dependencies: ```sh $ npm install -d && npm test ``` ### Author **Brian Woodward** * [github/doowb](https://github.com/doowb) * [twitter/doowb](http://twitter.com/doowb) ### License Copyright © 2016, [Brian Woodward](https://github.com/doowb). Released under the [MIT license](https://github.com/doowb/paginationator/blob/master/LICENSE). *** _This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on July 19, 2016._