mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Add key/value validation to Collection.find/findAll (#569)
* Add key/value validation to Collection.find/findAll * Fix ESLint errors
This commit is contained in:
committed by
Amish Shah
parent
4df7968630
commit
bce3cd2b8b
@@ -77,6 +77,8 @@ class Collection extends Map {
|
||||
* collection.getAll('username', 'Bob');
|
||||
*/
|
||||
findAll(key, value) {
|
||||
if (typeof key !== 'string') throw new TypeError('key must be a string');
|
||||
if (typeof value === 'undefined') throw new Error('value must be specified');
|
||||
const results = [];
|
||||
for (const item of this.values()) {
|
||||
if (item[key] === value) {
|
||||
@@ -95,6 +97,8 @@ class Collection extends Map {
|
||||
* collection.get('id', '123123...');
|
||||
*/
|
||||
find(key, value) {
|
||||
if (typeof key !== 'string') throw new TypeError('key must be a string');
|
||||
if (typeof value === 'undefined') throw new Error('value must be specified');
|
||||
for (const item of this.values()) {
|
||||
if (item[key] === value) {
|
||||
return item;
|
||||
|
||||
Reference in New Issue
Block a user