JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 245
  • Score
    100M100P100Q88369F
  • License MIT

A minimal library for creating chunks of arrays in JavaScript

Package Exports

  • chunkjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chunkjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ChunkJS

ChunkJS is a minimal library that splits arrays into smaller chunks or batches.

Installation

npm install chunkjs

or using Yarn

yarn add chunkjs

Usage

ChunkJS is comprised of two functions: splitIntoChunks and splitIntoBatches:

splitIntoChunks(array, numberOfChunks);

splitIntoBatches(array, numberOfElementsPerBatch);

Examples

To split an array into an n number of chunks (default size is 2):

const { splitIntoChunks } = require("chunkjs");

splitIntoChunks([ 1, 2, 3, 4, 5, 6 ], 2);
// returns [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]

To split an array into batches with n number of elements (default size is 2):

const { splitIntoBatches } = require("chunkjs");

splitIntoBatches([ 1, 2, 3, 4, 5, 6 ], 2);
// returns [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]