Socket
Socket
Sign inDemoInstall

@supercharge/collections

Package Overview
Dependencies
1
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @supercharge/collections

Supercharge collections


Version published
Weekly downloads
418
increased by3.72%
Maintainers
3
Install size
85.9 kB
Created
Weekly downloads
 

Changelog

Source

2.2.0 - 2020-07-02

Added

  • filterIf(condition, callback) method: a variant of the the filter method only filtering the collection if the condition evaluates to true

Readme

Source


Collections

async/await-ready array methods for Node.js


Installation · Docs · Usage



Latest Version Monthly downloads

Follow @marcuspoehls and @superchargejs for updates!


Installation

npm i @supercharge/collections

Docs

Find all the details and available methods in the extensive Supercharge docs.

Usage

The package exports a function accepting an array as a parameter. From there, you can chain all collection methods.

The package is async/await-ready and supports async functions for most of the methods.

const User = require('models/user')
const Collect = require('@supercharge/collections')

const users = await Collect(
    await User.all()
  )
  .filter(async user => {
    return user.notSubscribedToNewsletter()
  })
  .map(async user => {
    await user.subscribeToNewsletter()

    return user
  })

// users = [ <list of newly-subscribed users> ]

You can directly await the result for methods returning a definite value. The function returns a new instance of the collection without altering the original input array:

await Collect([ 1, 2, 3 ])
  .map(item => item * 100)
  .reduce((carry, item) => {
    return carry + item
  }, 0)

// result: 600

Contributing

Do you miss a collection function? We very much appreciate your contribution! Please send in a pull request 😊

  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀

License

MIT © Supercharge


superchargejs.com  ·  GitHub @supercharge  ·  Twitter @superchargejs

Keywords

FAQs

Last updated on 02 Jul 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc