arrays 3.2.0
Install from the command line:
Learn more about npm packages
$ npm install @supercharge/arrays@3.2.0
Install via package.json:
"@supercharge/arrays": "3.2.0"
About this version
Array utilities for JavaScript and Node.js
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
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()
, .length()
, .flatMap()
, .contains()
, and many more.
npm i @supercharge/arrays
Find all the details for @supercharge/arrays
in the extensive Supercharge docs.
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 users = Arr.from([])
users.isEmpty()
// true
users
.push({ id: 1, name: 'Marcus' })
.push({ id: 2, name: 'Norman' })
.push({ id: 3, name: 'Christian' })
users.isNotEmpty()
// true
users.length()
// 3
const usernamesArray = users
.map(user => user.name)
.toArray()
// [ 'Marcus', 'Norman', 'Christian' ]
const marcus = users.find(user => {
return user.name === 'Marcus'
})
// { id: 1, name: 'Marcus' }
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.
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 🚀
MIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs