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

@discordjs/collection

Package Overview
Dependencies
Maintainers
2
Versions
1195
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@discordjs/collection

Utility data structure used in discord.js

  • 2.1.2-dev.1727655144-9aa3b635e
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
415K
decreased by-19.81%
Maintainers
2
Weekly downloads
 
Created

What is @discordjs/collection?

@discordjs/collection is a powerful utility for managing collections of data. It extends JavaScript's native Map class and provides additional methods that are useful for handling and manipulating collections, especially in the context of Discord bots.

What are @discordjs/collection's main functionalities?

Basic Collection Operations

This feature allows you to perform basic operations such as setting, getting, and checking the existence of elements in the collection.

const { Collection } = require('@discordjs/collection');
const collection = new Collection();
collection.set('key1', 'value1');
collection.set('key2', 'value2');
console.log(collection.get('key1')); // Output: value1
console.log(collection.has('key2')); // Output: true
console.log(collection.size); // Output: 2

Filtering and Mapping

This feature allows you to filter and map the elements in the collection, providing a way to transform and query the data.

const { Collection } = require('@discordjs/collection');
const collection = new Collection();
collection.set('key1', 10);
collection.set('key2', 20);
collection.set('key3', 30);
const filtered = collection.filter(value => value > 15);
console.log(filtered); // Output: Collection { 'key2' => 20, 'key3' => 30 }
const mapped = collection.map(value => value * 2);
console.log(mapped); // Output: [ 20, 40, 60 ]

Reducing and Finding

This feature allows you to reduce the collection to a single value and find specific elements based on a condition.

const { Collection } = require('@discordjs/collection');
const collection = new Collection();
collection.set('key1', 1);
collection.set('key2', 2);
collection.set('key3', 3);
const sum = collection.reduce((acc, value) => acc + value, 0);
console.log(sum); // Output: 6
const found = collection.find(value => value === 2);
console.log(found); // Output: 2

Other packages similar to @discordjs/collection

Keywords

FAQs

Package last updated on 30 Sep 2024

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