Introduction
The @supercharge/arrays
package provides chainable array utilities for Node.js and JavaScript. It’s a wrapper around JavaScript arrays providing useful methods like .isEmpty()
, .size()
, .flatMap()
, .contains()
, and many more.
Installation
npm i @supercharge/arrays
Docs
Find all the details for @supercharge/arrays
in the extensive Supercharge docs.
Usage
Using @supercharge/arrays
is pretty straightforward. The package exports a function wrapping an array or individual items as an argument. You can then fluently chain methods interacting with your data:
const { Arr } = require('@supercharge/arrays')
const hasItemsGreaterTen = Arr([1, 2, 3, 4, 5, 6])
.map(value => value * 2)
.filter(value => value > 10)
.isNotEmpty()
Arr([1, 2, 3]).length()
Arr([1, 2, 3]).includes(value => {
return value > 2
})
Every method in the chain returns a @supercharge/array
instance. This way, you can chain further methods without leaving the fluent interface. Call .all()
to retrieve the plain JavaScript array.
Contributing
Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊
- Create a fork
- Create your feature branch:
git checkout -b my-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 🚀
License
MIT © Supercharge
superchargejs.com ·
GitHub @supercharge ·
Twitter @superchargejs