![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@supercharge/collections
Advanced tools
Changelog
3.2.1 - 2021-11-05
Readme
async/await-ready
array methods for Node.js
Installation · Docs · Usage
Follow @marcuspoehls and @superchargejs for updates!
The @supercharge/collections
package provides a convenient wrapper to work with arrays.
npm i @supercharge/collections
Find all the details and available methods in the extensive Supercharge docs.
The package exports a function accepting an array as a parameter. From there, you can chain all collection methods.
A created collection (Collect([1, 2, 3])
) is synchronous by default. That means it behaves like JavaScript’s array methods.
In contrast to JavaScript’s array methods, collections have a lot more methods available making your code a lot simpler. Here are basic examples using a collection:
const User = require('../models/user')
const Collect = require('@supercharge/collections')
const users = await User.findAll()
const notSubscribedUsers = Collect(users)
.filter(user => {
return user.notSubscribedToNewsletter
})
.all()
// notSubscribedUsers = [ <list of not-yet-subscribed users> ]
Here’s another example outlining how to determine whether the array “has” an item:
// “has” in JS Arrays
const hasNotSubscribedUsers = !![].concat(users).find(user => {
return user.notSubscribedToNewsletter
})
// “has” in Collections
const hasNotSubscribedUsers = Collect(users).has(user => {
return user.notSubscribedToNewsletter
})
All available methods are outlined in the docs.
The package is async/await-ready and supports async callback functions. A collection becomes async (returns a promise) as soon as you provide an async callback method to methods like map
, filter
, find
, and so on. You then need to await
the collection pipeline:
const User = require('../models/user')
const Collect = require('@supercharge/collections')
const users = await User.findAll()
const subscribedUsers = await Collect(users)
.filter(user => {
return user.notSubscribedToNewsletter
})
.map(async user => { // <-- providing an async callback creates an async collection that you need to `await`
await user.subscribeToNewsletter()
return user
})
// subscribedUsers = [ <list of newly-subscribed users> ]
You can directly await async collections without ending the call chain with .all()
. You can still call .all()
though, it works as well.
Do you miss a collection function? We very much appreciate your contribution! Please send in a pull request 😊
git checkout -b my-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © Supercharge
superchargejs.com · GitHub @supercharge · Twitter @superchargejs
FAQs
async/await-ready array methods for JavaScript and Node.js
The npm package @supercharge/collections receives a total of 236 weekly downloads. As such, @supercharge/collections popularity was classified as not popular.
We found that @supercharge/collections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.