Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

collect.js

Package Overview
Dependencies
Maintainers
1
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collect.js

Convenient and dependency free wrapper for working with arrays and objects.

  • 4.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
244K
decreased by-3.41%
Maintainers
1
Weekly downloads
 
Created

What is collect.js?

Collect.js is a convenient and fluent library for working with arrays and objects in JavaScript. It provides a wide range of methods to manipulate and query collections, making it easier to handle data structures in a more readable and expressive way.

What are collect.js's main functionalities?

Creating Collections

You can create a collection from an array or object. The `all` method returns all items in the collection.

const collect = require('collect.js');
const collection = collect([1, 2, 3, 4, 5]);
console.log(collection.all());

Chaining Methods

Collect.js allows you to chain multiple methods together for more complex operations. In this example, we filter the collection to include only items greater than 2 and then map each item to its double.

const collect = require('collect.js');
const collection = collect([1, 2, 3, 4, 5])
  .filter(item => item > 2)
  .map(item => item * 2);
console.log(collection.all());

Aggregating Data

You can perform aggregation operations like sum, average, min, and max on collections. This example demonstrates how to calculate the sum of all items in the collection.

const collect = require('collect.js');
const collection = collect([1, 2, 3, 4, 5]);
const sum = collection.sum();
console.log(sum);

Transforming Collections

Transformations like map, reduce, and filter can be applied to collections. This example shows how to double each item in the collection using the `map` method.

const collect = require('collect.js');
const collection = collect([1, 2, 3, 4, 5]);
const transformed = collection.map(item => item * 2);
console.log(transformed.all());

Querying Collections

You can query collections to check for the presence of items, find specific items, and more. This example checks if the collection contains the number 3.

const collect = require('collect.js');
const collection = collect([1, 2, 3, 4, 5]);
const containsThree = collection.contains(3);
console.log(containsThree);

Other packages similar to collect.js

Keywords

FAQs

Package last updated on 12 Dec 2017

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