Giter VIP home page Giter VIP logo

collections's Introduction



Supercharge is a full-stack Node.js framework.


Docs



Follow @marcuspoehls and @superchargejs for updates!


Quick Start

Scaffold a new Supercharge application on your computer using NPM:

npm init @supercharge/app@latest hello-supercharge

This will create a new Supercharge application in a hello-supercharge folder of your current working directory.

About Supercharge

Supercharge is a full-stack Node.js framework — not just a web-framework.

Supercharge builds on top of the Koa HTTP framework. Supercharge refines all Koa handling by providing a streamlined approach to middlewares and routing. You’ll also benefit from a comprehensive application setup containing configuration and database management, logging, integrating with Objection.js and knex.js for a powerful database interaction.

Learning

Supercharge has an extensive documentation that gives you all the information to get started with the framework.

Did you create a tutorial, video, blog post, plugin, library, or anything else related to Supercharge? Please let me know! Create an issue or tweet me @marcuspoehls. I'm very happy to create a content list and share it with everybody!

License

Supercharge is MIT licensed.


superchargejs.com  ·  GitHub @supercharge  ·  Twitter @superchargejs

collections's People

Contributors

artplan1 avatar atul9 avatar boxjack avatar dependabot-preview[bot] avatar dev-warner avatar dragonstin avatar ilyaryabchinski avatar j-blandford avatar lukas-mertens avatar marcuspoehls avatar mcvladthegoat avatar nargonath avatar rshalman avatar sanskagarwal avatar srinivasu619 avatar stuckd avatar vufly avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

collections's Issues

Add "last" method

The colleciton.last() method returns the last item in the collection. It does not remove the item from the collection:

Example

const collection = Collect([ 1, 2, 3 ])

await collection.last()

// 3

await collection.all()

// [ 1, 2, 3 ]

It wouuld be great to let users pass an (async) testing function as a parameter to the last method:

await Collect([
  { id: 1, name: 'marcus' },
  { id: 3, name: 'marcus' }
]).last(async ({ id }) => {
  return await User.findById(id)
})

// { id: 3, name: 'marcus', username: 'marcus' }

Add "avg" method

The collection.avg() method returns the average of all collection items:

Example

await Collect([1, 2, 3, 4])
  .avg()

// 2,5

Bonus
Create an alias method .average() that calls .avg() internally.

Add "union" method

The collection.union(array) method adds all values from the array and removes duplicates:

Example

await Collect([1, 2, 3])
  .union([2, 3, 4, 5])
  .all()

// [1, 2, 3, 4, 5]

Add "median" method

The collection.median() method returns the median value of the collection:

Example

await Collect([4, 1, 37, 2, 1])
  .median()

// 2

await Collect([1, 2, 3, 4, 5, 6])
  .median()

// 3.5

Add "hasDuplicates" method

The collection.hasDuplicates() method determines whether the collection contains duplicate items.

Example

const collection = Collect([1, 2, 1, 3, 4])

await collection.hasDuplicates()

// true

const collection = Collect([1, 2, 3, 4])

await collection.hasDuplicates()

// false

Add "toJSON" method

The collection.toJSON() method creates a JSON string from the values of the collection:

Example

await Collect([1, 2, 3])
  .toJSON()

// "[1,2,3]"

await Collect([{ name: 'Marcus'}])
  .toJSON()

// "[{"name":"Marcus"}]"

Collections vs lodash

I am not a user of any functional library but I have an idea what they do. Can you @marcuspoehls explain what the difference between this collections and any other library?

"pluck" method improvement

Reference: https://superchargejs.com/docs/master/collections#pluck

I'm going to add tiny feature to .pluck(): search by nested key. But I have one question about key parameter.

Which of the two options for specifying a key is better: key.nested_key_1.nested_key_2 or key[nested_key_1][nested_key_2] ?

It seems that 2nd variant looks better because it covers more variants of key (for ex.: string with spaces)

Add "sum" method

The collection.sum() method returns the sum of all collection items:

Example

await Collect([1, 2, 3, 4])
  .sum()

// 10

Add "pop" method

The collection.pop() method removes and returns the last item from the collection:

Example

const collection = Collect([4, 1, 37, 2, 12])

await collection.pop()

// 12

await collection.all()

// [4, 1, 37, 2]

Add "max" method

The collection.max() method returns the max value in the collection:

Example

await Collect([1, 20, 3, 4])
  .max()

// 20

Add "min" method

The collection.min() method returns the min value in the collection:

Example

await Collect([10, 2, 3, 4])
  .min()

// 2

Add "reverse" method

The collection.reverse() method reverses the collection. The first item becomes the last one, the second item becomes the second to last, and so on:

Example

await Collect([4, 6, 8, 9])
  .reverse()
  .all()

// [9, 8, 6, 4]

Add "sort" method

The collection.sort() method returns the sorted collection:

Example

await Collect([4, 1, 37, 2, 1])
  .sort()
  .all()

// [1, 1, 2, 4, 37]

Hint: this is helpful when implementing #21

Add "diff" method

The collection.diff(array) method removes all values from the collection that are present in the given array.

Example

await Collect([1, 2, 3])
  .diff([2, 3, 4, 5])
  .all()

// [1]

Add "join" method

The collection.join(str) method joins all items in the collection using the given str and returns the resulting string value:

Example

await Collect([10, 2, 3, 4])
  .join('-')

// '10-2-3-4' 

Add "intersect" method

The collection.intersect(array) method removes all values from the collection that are not present in the given array.

Example

await Collect([1, 2, 3])
  .intersect([2, 3, 4, 5])
  .all()

// [2, 3]

Add "includes" method

Add a new .includes(value|predicate-fn) method that determines whether the collection includes a certain value. The .includes() method allows either a dedicated value or a predicate function receiving a collection item (like .find()).

Returns true if the value is found in the collection or the predicate function returns an item from the collection. Returns false otherwise.

Notice: this is basically an alias for the existing .has method.

Example

const collection = Collect([ 1, 2, 3 ])

await collection.includes(2)
// true

await collection.includes((value => {
  return value > 5
})
// false

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.