GithubHelp home page GithubHelp logo

anilpandiya / collections Goto Github PK

View Code? Open in Web Editor NEW

This project forked from supercharge/collections

1.0 1.0 0.0 162 KB

async/await-ready, chainable Array & Collection utilities

Home Page: https://superchargejs.com/docs/collections

License: MIT License

JavaScript 100.00%

collections's Introduction



Collections

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


InstallationDocsUsage



Build Status 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')

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

    return user
  })
  .all()

// result: [ <list of newly-subscribed users> ]

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.

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 @superchargejs 聽路聽 Twitter @superchargejs

collections's People

Contributors

marcuspoehls avatar stuckd avatar ilyaryabchinski avatar anilpandiya avatar rshalman avatar dependabot-preview[bot] avatar dragonstin avatar srinivasu619 avatar dev-warner avatar j-blandford avatar artplan1 avatar boxjack avatar nargonath avatar mcvladthegoat avatar

Stargazers

Roman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.