Skip to content

Commit

Permalink
✨Switch to deepmerge-ts instead of deepmerge (#442)
Browse files Browse the repository at this point in the history
Co-authored-by: Nico105 <63612668+Nico105@users.noreply.github.com>
  • Loading branch information
Lebyy and Nico105 authored Mar 12, 2022
1 parent c06b8bf commit 5648551
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"homepage": "https://discord-giveaways.js.org",
"dependencies": {
"deepmerge": "^4.2.2",
"deepmerge-ts": "^4.0.0",
"serialize-javascript": "^6.0.0"
},
"devDependencies": {
Expand Down
13 changes: 7 additions & 6 deletions src/Giveaway.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { EventEmitter } = require('node:events');
const { setTimeout, clearTimeout } = require('node:timers');
const merge = require('deepmerge');
const { deepmerge, deepmergeCustom } = require('deepmerge-ts');
const customDeepmerge = deepmergeCustom({ mergeArrays: false });
const serialize = require('serialize-javascript');
const Discord = require('discord.js');
const {
Expand Down Expand Up @@ -209,15 +210,15 @@ class Giveaway extends EventEmitter {
* @type {LastChanceOptions}
*/
get lastChance() {
return merge(this.manager.options.default.lastChance, this.options.lastChance ?? {});
return deepmerge(this.manager.options.default.lastChance, this.options.lastChance ?? {});
}

/**
* Pause options for this giveaway
* @type {PauseOptions}
*/
get pauseOptions() {
return merge(PauseOptions, this.options.pauseOptions ?? {});
return deepmerge(PauseOptions, this.options.pauseOptions ?? {});
}

/**
Expand Down Expand Up @@ -571,7 +572,7 @@ class Giveaway extends EventEmitter {

// Update data
if (options.newMessages && typeof options.newMessages === 'object') {
this.messages = merge(this.messages, options.newMessages);
this.messages = customDeepmerge(this.messages, options.newMessages);
}
if (typeof options.newThumbnail === 'string') this.thumbnail = options.newThumbnail;
if (typeof options.newPrize === 'string') this.prize = options.newPrize;
Expand All @@ -592,7 +593,7 @@ class Giveaway extends EventEmitter {
this.options.exemptMembers = options.newExemptMembers;
}
if (options.newLastChance && typeof options.newLastChance === 'object' && !this.isDrop) {
this.options.lastChance = merge(this.options.lastChance || {}, options.newLastChance);
this.options.lastChance = deepmerge(this.options.lastChance || {}, options.newLastChance);
}

await this.manager.editGiveaway(this.messageId, this.data);
Expand Down Expand Up @@ -812,7 +813,7 @@ class Giveaway extends EventEmitter {
if (!this.message) return reject('Unable to fetch message with Id ' + this.messageId + '.');
if (this.isDrop) return reject('Drop giveaways cannot get rerolled!');
if (!options || typeof options !== 'object') return reject(`"options" is not an object (val=${options})`);
options = merge(GiveawayRerollOptions, options);
options = deepmerge(GiveawayRerollOptions, options);
if (options.winnerCount && (!Number.isInteger(options.winnerCount) || options.winnerCount < 1)) {
return reject(`options.winnerCount is not a positive integer. (val=${options.winnerCount})`);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { EventEmitter } = require('node:events');
const { setTimeout, setInterval } = require('node:timers');
const { writeFile, readFile, access } = require('fs/promises');
const merge = require('deepmerge');
const { deepmerge } = require('deepmerge-ts');
const serialize = require('serialize-javascript');
const Discord = require('discord.js');
const {
Expand Down Expand Up @@ -53,7 +53,7 @@ class GiveawaysManager extends EventEmitter {
* The manager options
* @type {GiveawaysManagerOptions}
*/
this.options = merge(GiveawaysManagerOptions, options || {});
this.options = deepmerge(GiveawaysManagerOptions, options || {});

if (init) this._init();
}
Expand Down Expand Up @@ -234,7 +234,7 @@ class GiveawaysManager extends EventEmitter {
hostedBy: options.hostedBy ? options.hostedBy.toString() : undefined,
messages:
options.messages && typeof options.messages === 'object'
? merge(GiveawayMessages, options.messages)
? deepmerge(GiveawayMessages, options.messages)
: GiveawayMessages,
thumbnail: typeof options.thumbnail === 'string' ? options.thumbnail : undefined,
reaction: Discord.Util.resolvePartialEmoji(options.reaction) ? options.reaction : undefined,
Expand Down

0 comments on commit 5648551

Please sign in to comment.