Skip to content

Commit

Permalink
fix(Util): add max depth for merge default
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Jun 10, 2021
1 parent fbcbb29 commit 8199fd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/structures/GuildChannel.js
Expand Up @@ -588,6 +588,7 @@ class GuildChannel extends Channel {
reason: null,
},
options,
0,
);
return this.guild.channels.create(options.name, options);
}
Expand Down
6 changes: 4 additions & 2 deletions src/util/Util.js
Expand Up @@ -307,16 +307,18 @@ class Util {
* Sets default properties on an object that aren't already specified.
* @param {Object} def Default properties
* @param {Object} given Object to assign defaults to
* @param {number} [maxDepth=Infinity] The maximum depth to check properties for
* @returns {Object}
* @private
*/
static mergeDefault(def, given) {
static mergeDefault(def, given, maxDepth = Infinity) {
if (maxDepth < 0) return given;
if (!given) return def;
for (const key in def) {
if (!has(given, key) || given[key] === undefined) {
given[key] = def[key];
} else if (given[key] === Object(given[key])) {
given[key] = Util.mergeDefault(def[key], given[key]);
given[key] = Util.mergeDefault(def[key], given[key], maxDepth - 1);
}
}

Expand Down

0 comments on commit 8199fd4

Please sign in to comment.