mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
Equals updates (#987)
* Docs update
Changed the param names and param descriptions to be consistent.
* Added === comparison
Changed Presence.equals and Game.equals to first compare using ===
* Collection.equals fix
Now returns false when collection is undefined, instead of crashing
💯
This commit is contained in:
committed by
Schuyler Cebulskie
parent
906bb3c5f3
commit
264ee8e7f1
@@ -89,7 +89,7 @@ class GroupDMChannel extends Channel {
|
|||||||
* Whether this channel equals another channel. It compares all properties, so for most operations
|
* Whether this channel equals another channel. It compares all properties, so for most operations
|
||||||
* it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often
|
* it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often
|
||||||
* what most users need.
|
* what most users need.
|
||||||
* @param {GroupDMChannel} channel The channel to compare to
|
* @param {GroupDMChannel} channel Channel to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(channel) {
|
equals(channel) {
|
||||||
|
|||||||
@@ -692,7 +692,7 @@ class Guild {
|
|||||||
* Whether this Guild equals another Guild. It compares all properties, so for most operations
|
* Whether this Guild equals another Guild. It compares all properties, so for most operations
|
||||||
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
|
* it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
|
||||||
* what most users need.
|
* what most users need.
|
||||||
* @param {Guild} guild The guild to compare
|
* @param {Guild} guild Guild to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(guild) {
|
equals(guild) {
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ class GuildChannel extends Channel {
|
|||||||
/**
|
/**
|
||||||
* Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel.
|
* Checks if this channel has the same type, topic, position, name, overwrites and ID as another channel.
|
||||||
* In most cases, a simple `channel.id === channel2.id` will do, and is much faster too.
|
* In most cases, a simple `channel.id === channel2.id` will do, and is much faster too.
|
||||||
* @param {GuildChannel} channel The channel to compare this channel to
|
* @param {GuildChannel} channel Channel to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(channel) {
|
equals(channel) {
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ class Presence {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this presence is equal to another
|
* Whether this presence is equal to another
|
||||||
* @param {Presence} other the presence to compare
|
* @param {Presence} presence Presence to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(other) {
|
equals(presence) {
|
||||||
return (
|
return this === presence || (
|
||||||
other &&
|
presence &&
|
||||||
this.status === other.status &&
|
this.status === presence.status &&
|
||||||
this.game ? this.game.equals(other.game) : !other.game
|
this.game ? this.game.equals(presence.game) : !presence.game
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,15 +75,15 @@ class Game {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this game is equal to another game
|
* Whether this game is equal to another game
|
||||||
* @param {Game} other the other game to compare
|
* @param {Game} game Game to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(other) {
|
equals(game) {
|
||||||
return (
|
return this === game || (
|
||||||
other &&
|
game &&
|
||||||
this.name === other.name &&
|
this.name === game.name &&
|
||||||
this.type === other.type &&
|
this.type === game.type &&
|
||||||
this.url === other.url
|
this.url === game.url
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -302,7 +302,7 @@ class Role {
|
|||||||
* Whether this role equals another role. It compares all properties, so for most operations
|
* Whether this role equals another role. It compares all properties, so for most operations
|
||||||
* it is advisable to just compare `role.id === role2.id` as it is much faster and is often
|
* it is advisable to just compare `role.id === role2.id` as it is much faster and is often
|
||||||
* what most users need.
|
* what most users need.
|
||||||
* @param {Role} role The role to compare to
|
* @param {Role} role Role to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(role) {
|
equals(role) {
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ class User {
|
|||||||
/**
|
/**
|
||||||
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
|
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
|
||||||
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
||||||
* @param {User} user The user to compare
|
* @param {User} user User to compare with
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
equals(user) {
|
equals(user) {
|
||||||
|
|||||||
@@ -338,6 +338,7 @@ class Collection extends Map {
|
|||||||
* @returns {boolean} Whether the collections have identical contents
|
* @returns {boolean} Whether the collections have identical contents
|
||||||
*/
|
*/
|
||||||
equals(collection) {
|
equals(collection) {
|
||||||
|
if (!collection) return false;
|
||||||
if (this === collection) return true;
|
if (this === collection) return true;
|
||||||
if (this.size !== collection.size) return false;
|
if (this.size !== collection.size) return false;
|
||||||
return !this.find((value, key) => {
|
return !this.find((value, key) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user