mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +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');
|
* collection.getAll('username', 'Bob');
|
||||||
*/
|
*/
|
||||||
findAll(key, value) {
|
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 = [];
|
const results = [];
|
||||||
for (const item of this.values()) {
|
for (const item of this.values()) {
|
||||||
if (item[key] === value) {
|
if (item[key] === value) {
|
||||||
@@ -95,6 +97,8 @@ class Collection extends Map {
|
|||||||
* collection.get('id', '123123...');
|
* collection.get('id', '123123...');
|
||||||
*/
|
*/
|
||||||
find(key, value) {
|
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()) {
|
for (const item of this.values()) {
|
||||||
if (item[key] === value) {
|
if (item[key] === value) {
|
||||||
return item;
|
return item;
|
||||||
|
|||||||
Reference in New Issue
Block a user