mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
src: Replace instanceof Array checks with Array.isArray and instanceof Buffer with Buffer.isBuffer (#3227)
* src: Replace instanceof Array checks with Array.isArray * src: Buffer.isBuffer instead of instanceof Buffer
This commit is contained in:
@@ -32,7 +32,7 @@ class BitField {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
has(bit) {
|
||||
if (bit instanceof Array) return bit.every(p => this.has(p));
|
||||
if (Array.isArray(bit)) return bit.every(p => this.has(p));
|
||||
bit = this.constructor.resolve(bit);
|
||||
return (this.bitfield & bit) === bit;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class BitField {
|
||||
* @returns {string[]}
|
||||
*/
|
||||
missing(bits, ...hasParams) {
|
||||
if (!(bits instanceof Array)) bits = new this.constructor(bits).toArray(false);
|
||||
if (!Array.isArray(bits)) bits = new this.constructor(bits).toArray(false);
|
||||
return bits.filter(p => !this.has(p, ...hasParams));
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class BitField {
|
||||
static resolve(bit = 0) {
|
||||
if (typeof bit === 'number' && bit >= 0) return bit;
|
||||
if (bit instanceof BitField) return bit.bitfield;
|
||||
if (bit instanceof Array) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, 0);
|
||||
if (Array.isArray(bit)) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, 0);
|
||||
if (typeof bit === 'string') return this.FLAGS[bit];
|
||||
throw new RangeError('BITFIELD_INVALID');
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class DataResolver {
|
||||
* @returns {?string}
|
||||
*/
|
||||
static resolveBase64(data) {
|
||||
if (data instanceof Buffer) return `data:image/jpg;base64,${data.toString('base64')}`;
|
||||
if (Buffer.isBuffer(data)) return `data:image/jpg;base64,${data.toString('base64')}`;
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class DataResolver {
|
||||
* @returns {Promise<Buffer>}
|
||||
*/
|
||||
static resolveFile(resource) {
|
||||
if (!browser && resource instanceof Buffer) return Promise.resolve(resource);
|
||||
if (!browser && Buffer.isBuffer(resource)) return Promise.resolve(resource);
|
||||
if (browser && resource instanceof ArrayBuffer) return Promise.resolve(Util.convertToBuffer(resource));
|
||||
|
||||
if (typeof resource === 'string') {
|
||||
|
||||
@@ -237,7 +237,7 @@ class Util {
|
||||
*/
|
||||
static resolveString(data) {
|
||||
if (typeof data === 'string') return data;
|
||||
if (data instanceof Array) return data.join('\n');
|
||||
if (Array.isArray(data)) return data.join('\n');
|
||||
return String(data);
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ class Util {
|
||||
if (color === 'RANDOM') return Math.floor(Math.random() * (0xFFFFFF + 1));
|
||||
if (color === 'DEFAULT') return 0;
|
||||
color = Colors[color] || parseInt(color.replace('#', ''), 16);
|
||||
} else if (color instanceof Array) {
|
||||
} else if (Array.isArray(color)) {
|
||||
color = (color[0] << 16) + (color[1] << 8) + color[2];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user