2.0.0 • Published 6 months ago

@ulisesgascon/array-to-chunks v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

About

A simple way to slice an array into chunks

❤️ Awesome Features:

  • Simple and easy to use 🔥
  • Typescript support 💪
  • Zero dependencies 🚀
  • Easy to use and great test coverage ✅
  • Throw an error for non-array elements 🥷

Installation

npm install @ulisesgascon/array-to-chunks

Usage

Simple example

Importation

const { chunkArray } = require("@ulisesgascon/array-to-chunks");
import { chunkArray } from "@ulisesgascon/array-to-chunks";

Usage

const array = [1, 2, 3, 4, 5, 6, 7, 8, 9];
console.log(hunkArray(array, 1)); // [[1],[2],[3],[4],[5],[6],[7],[8],[9]]
console.log(hunkArray(array, 2)); // [[1,2], [3,4], [5,6], [7,8], [9]]
console.log(hunkArray(array, 3)); // [[1,2,3], [4,5,6], [7,8,9]]
console.log(hunkArray(array, 150)); // [[1,2,3,4,5,6,7,8,9]]

Known limitations

This library is using Array.slice() to shadow copy the items from the original array.

Elements of the original array are copied into the returned array as follows:

For object references (and not the actual object), slice copies object references into the new array. Both the original and new array refer to the same object. If a referenced object changes, the changes are visible to both the new and original arrays.

For strings, numbers and booleans (not String, Number and Boolean objects), slice copies the values into the new array. Changes to the string, number or boolean in one array do not affect the other array. If a new element is added to either array, the other array is not affected.

Explanation about slice method from Naresh Kumar

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

2.0.0

6 months ago

1.0.1

1 year ago

1.0.0

1 year ago