mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Return undefined from Collection.find() / findKey() (#2260)
To be compliant with Array.find() / findIndex()
This commit is contained in:
@@ -192,12 +192,12 @@ class Collection extends Map {
|
|||||||
for (const item of this.values()) {
|
for (const item of this.values()) {
|
||||||
if (item[propOrFn] === value) return item;
|
if (item[propOrFn] === value) return item;
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
} else if (typeof propOrFn === 'function') {
|
} else if (typeof propOrFn === 'function') {
|
||||||
for (const [key, val] of this) {
|
for (const [key, val] of this) {
|
||||||
if (propOrFn(val, key, this)) return val;
|
if (propOrFn(val, key, this)) return val;
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('First argument must be a property string or a function.');
|
throw new Error('First argument must be a property string or a function.');
|
||||||
}
|
}
|
||||||
@@ -223,12 +223,12 @@ class Collection extends Map {
|
|||||||
for (const [key, val] of this) {
|
for (const [key, val] of this) {
|
||||||
if (val[propOrFn] === value) return key;
|
if (val[propOrFn] === value) return key;
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
} else if (typeof propOrFn === 'function') {
|
} else if (typeof propOrFn === 'function') {
|
||||||
for (const [key, val] of this) {
|
for (const [key, val] of this) {
|
||||||
if (propOrFn(val, key, this)) return key;
|
if (propOrFn(val, key, this)) return key;
|
||||||
}
|
}
|
||||||
return null;
|
return undefined;
|
||||||
} else {
|
} else {
|
||||||
throw new Error('First argument must be a property string or a function.');
|
throw new Error('First argument must be a property string or a function.');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user