Documentation
split-into-pile
This module splits a array, object or map into a specified size of batches!
Features!
- Export array/object/map into array, object or map batches
- Get page of the pile with one simple method
to-do:
- Suggest what to add next at github
Installation
$ npm install split-into-pile
Example
- Here's a example of using this module
const splitintopile = ; let array = 256434; let pages = array 2; console; // Returns [ [ 2, 5 ], [ 6, 43 ], [ 4 ] ]console; // Returns { '1': [ 2, 5 ], '2': [ 6, 43 ], '3': [ 4 ] }
Use document
Using Object
const splitintopile = ; let obj = one: 'first' key: 'door' hi: 'hello'; let pages = obj 2; console; // Returns [ { one: 'first', key: 'door' }, { hi: 'hello' } ]
Using array
const splitintopile = ; let array = 256434; let pages = array 2; console; // Returns [ [ 2, 5 ], [ 6, 43 ], [ 4 ] ]
Using Map
const splitintopile = ; let map = 1 2'three' 5'test' 'example'; let pages = map; console; // Returns [[ { 1 => 2, 'three'=> 5 }], [ 'test' => 'example' ]]
Syntax
- Example of using the plugin methods
const splitintopile = ; let pages = obj/array/map size; pages; // Returns object/array/map formated into array page : [[2,4], [3,5]]pages; // Returns object/array/map formated into object page : {'1':[2,4], '2': [3,5]}pages; // Returns object/array/map formated into map page : { 1 => [2, 4], 2 => [3, 5] }pages; // Gets elements from specified page, (numeric input)pages; // Returns a bool if a specified page exists(true) or not(false)pagesMaxPages; // Returns the amount of pages that are in the array/object
Options for ObjectPages() and MapPages();
- { keyTemplate: string } - template for generating page keys
pages; // Returns {'#1':[2,4], '#2': [3,5]}pages; // Returns {'#1' => [2,4], '#2' => [3,5]}
- { keySchema: array } - A schema of keys for result !Length of the schema array must be same as length of pages!
pages; // Returns {'hello':[2,4], 'example': [3,5]}pages; // Returns {'hello' => [2,4], 'example' => [3,5]}
- keyTemplate and keySchema may not be used together!