mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
refactor: comprehensive permissionOverwrites refactor (#2818)
* wip: comprehensive permissionOverwrites refactor * PermissionOverwrites.resolve should Promise.reject() where a promise is the expected return value * On second thought, async rewrite to automatically reject on throw * Fix some docs * Fix a bug * fix 2 more bugs * typings: Updated for latest commit * typings: Add missing method in GuildChannel * typings: Add missing `| null` in PermissionOverwriteOption type * Suggested changes
This commit is contained in:
@@ -2,6 +2,7 @@ const { Colors, DefaultOptions, Endpoints } = require('./Constants');
|
||||
const fetch = require('node-fetch');
|
||||
const { Error: DiscordError, RangeError, TypeError } = require('../errors');
|
||||
const has = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
||||
const isObject = d => typeof d === 'object' && d !== null;
|
||||
const { parse } = require('path');
|
||||
|
||||
/**
|
||||
@@ -19,7 +20,6 @@ class Util {
|
||||
* @returns {Object}
|
||||
*/
|
||||
static flatten(obj, ...props) {
|
||||
const isObject = d => typeof d === 'object' && d !== null;
|
||||
if (!isObject(obj)) return obj;
|
||||
|
||||
props = Object.assign(...Object.keys(obj).filter(k => !k.startsWith('_')).map(k => ({ [k]: true })), ...props);
|
||||
@@ -39,7 +39,7 @@ class Util {
|
||||
// If it's an array, flatten each element
|
||||
else if (Array.isArray(element)) out[newProp] = element.map(e => Util.flatten(e));
|
||||
// If it's an object with a primitive `valueOf`, use that value
|
||||
else if (valueOf && !isObject(valueOf)) out[newProp] = valueOf;
|
||||
else if (typeof valueOf !== 'object') out[newProp] = valueOf;
|
||||
// If it's a primitive
|
||||
else if (!elemIsObj) out[newProp] = element;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user