Socket
Socket
Sign inDemoInstall

@supercharge/collections

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@supercharge/collections

Supercharge collections


Version published
Maintainers
3
Created
Source


Collections

async/await-ready array & collection utilities for Node.js


Installation · Docs · Usage



Build Status Latest Version

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 Collect = require('@supercharge/collections')

await Collect([ 1, 2, 3, 4, 5 ])
  .map(item => item * 100)
  .map(async timeout => {
    await new Promise(resolve => setTimeout(resolve, ms))
    return timeout
  })
  .filter(timeout => timeout > 200)
  .all()

// result: [ 300, 400, 500 ]

Notice: when chaining methods like map or filter, you'll receive a collection instance in return. You must actively end the call chain using the .all() method to process the collection pipeline and retrieve the final result.

Yu can directly await the result for methods returning a definite value:

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 @superchargejs  ·  Twitter @superchargejs

Keywords

FAQs

Package last updated on 25 Jul 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc