chunktools
v1.0.6
Published
chunktools is a lightweight tool to create chunk arrays for batch processing.
Downloads
5
Readme
ChunkTools
ChunkTools is a lightweight and intuitive tool for deconstructing large arrays into smaller, more manageable arrays for chunk processing with or without promises.
Installation
Using npm:
npm i chunktools
Importing jsonlitedb to your Node Project:
const chunktools = require(‘chunktools’)
Usage
Chunktools features two functions:
makeChunksFromArray
Returns “chunks”/arrays of your designated size with the contents of your provided array distributed between them.
This function has two mandatory parameters:
- your array
- The size of the “chunks” you’d like to distribute your array into.
Example
let myArray = [0,1,2,3,4,5,6,7,8,9,10]
makeChunksFromArray(myArray, 10) //Expected return: [[0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]`
makeChunksFromRange
Returns “chunks”/arrays of your designated size containing all the integers contained in your provided range.
This function has three mandatory parameters:
- From
- To
- The size of the “chunks” you’d like to distribute your array into.
Parameter 1 & 2 pertain to your range, so for example, if we want an array from 1 - 10 broken down into chunks that each contain one number, this is what it would look like:
makeChunksFromRange(1, 10, 1)
With the expected return being:
[[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]]