@notenoughupdates/discord-akairo
Advanced tools
Comparing version 9.0.10-dev.1640803065.e6acb40 to 9.0.10-dev.1640804207.c48216d
{ | ||
"name": "@notenoughupdates/discord-akairo", | ||
"version": "9.0.10-dev.1640803065.e6acb40", | ||
"version": "9.0.10-dev.1640804207.c48216d", | ||
"description": "A highly customizable bot framework for Discord.js.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/src/index.js", |
@@ -54,3 +54,3 @@ /// <reference types="node" /> | ||
*/ | ||
static deepEquals<T>(a: unknown, b: T, ignoreUndefined?: boolean): a is T; | ||
static deepEquals<T>(a: unknown, b: T, options?: DeepEqualsOptions): a is T; | ||
/** | ||
@@ -62,2 +62,14 @@ * Converts a string in snake_case to camelCase. | ||
} | ||
export interface DeepEqualsOptions { | ||
/** | ||
* Whether to ignore undefined properties. | ||
* @default true | ||
*/ | ||
ignoreUndefined?: boolean; | ||
/** | ||
* Whether to ignore the order of the items in arrays | ||
* @default true | ||
*/ | ||
ignoreArrayOrder?: boolean; | ||
} | ||
//# sourceMappingURL=Util.d.ts.map |
@@ -91,3 +91,6 @@ "use strict"; | ||
} | ||
static deepEquals(a, b, ignoreUndefined = true) { | ||
/* eslint-disable no-console */ | ||
// eslint-disable-next-line complexity | ||
static deepEquals(a, b, options) { | ||
const { ignoreUndefined = true, ignoreArrayOrder = true } = options ?? {}; | ||
if (a === b) | ||
@@ -97,21 +100,43 @@ return true; | ||
throw new TypeError("Not objects"); | ||
for (const key in a) { | ||
if (ignoreUndefined && a[key] === undefined && b[key] === undefined) | ||
if ((Array.isArray(a) && !Array.isArray(b)) || (!Array.isArray(a) && Array.isArray(b))) { | ||
console.debug("deepEquals: Array vs non-array"); | ||
return false; | ||
} | ||
const newA = ignoreArrayOrder && Array.isArray(a) && a.length && typeof a[0] === "string" | ||
? [...a].sort((aa, bb) => { | ||
if (aa < bb) | ||
return -1; | ||
if (aa > bb) | ||
return 1; | ||
return 0; | ||
}) | ||
: a; | ||
const newB = ignoreArrayOrder && Array.isArray(b) && b.length && typeof b[0] === "string" | ||
? [...b].sort((aa, bb) => { | ||
if (aa < bb) | ||
return -1; | ||
if (aa > bb) | ||
return 1; | ||
return 0; | ||
}) | ||
: b; | ||
for (const key in newA) { | ||
if (ignoreUndefined && newA[key] === undefined && newB[key] === undefined) | ||
continue; | ||
if (!(key in b)) { | ||
if (!(key in newB)) { | ||
console.log("======================================"); | ||
console.dir(a, { depth: 4 }); | ||
console.dir(b, { depth: 4 }); | ||
console.dir(newA, { depth: 4 }); | ||
console.dir(newB, { depth: 4 }); | ||
return false; | ||
} | ||
if (typeof a[key] === "object" && typeof b[key] === "object") { | ||
if (!this.deepEquals(a[key], b[key], ignoreUndefined)) | ||
if (typeof newA[key] === "object" && typeof newB[key] === "object") { | ||
if (!this.deepEquals(newA[key], newB[key], { ignoreUndefined, ignoreArrayOrder })) | ||
return false; | ||
} | ||
else if (a[key] !== b[key]) { | ||
else if (newA[key] !== newB[key]) { | ||
console.log("======================================"); | ||
console.dir(a[key], { depth: 4 }); | ||
console.dir(a, { depth: 4 }); | ||
console.dir(b[key], { depth: 4 }); | ||
console.dir(b, { depth: 4 }); | ||
console.dir(newA[key], { depth: 4 }); | ||
console.dir(newA, { depth: 4 }); | ||
console.dir(newB[key], { depth: 4 }); | ||
console.dir(newB, { depth: 4 }); | ||
return false; | ||
@@ -122,2 +147,3 @@ } | ||
} | ||
/* eslint-enable no-console */ | ||
/** | ||
@@ -124,0 +150,0 @@ * Converts a string in snake_case to camelCase. |
{ | ||
"name": "@notenoughupdates/discord-akairo", | ||
"version": "9.0.10-dev.1640803065.e6acb40", | ||
"version": "9.0.10-dev.1640804207.c48216d", | ||
"description": "A highly customizable bot framework for Discord.js.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/src/index.js", |
@@ -112,22 +112,46 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
*/ | ||
public static deepEquals<T>(a: unknown, b: T, ignoreUndefined?: boolean): a is T; | ||
public static deepEquals(a: any, b: any, ignoreUndefined = true): boolean { | ||
public static deepEquals<T>(a: unknown, b: T, options?: DeepEqualsOptions): a is T; | ||
/* eslint-disable no-console */ | ||
// eslint-disable-next-line complexity | ||
public static deepEquals(a: any, b: any, options?: DeepEqualsOptions): boolean { | ||
const { ignoreUndefined = true, ignoreArrayOrder = true } = options ?? {}; | ||
if (a === b) return true; | ||
if (typeof a !== "object" || typeof b !== "object") throw new TypeError("Not objects"); | ||
for (const key in a) { | ||
if (ignoreUndefined && a[key] === undefined && b[key] === undefined) continue; | ||
if (!(key in b)) { | ||
if ((Array.isArray(a) && !Array.isArray(b)) || (!Array.isArray(a) && Array.isArray(b))) { | ||
console.debug("deepEquals: Array vs non-array"); | ||
return false; | ||
} | ||
const newA = | ||
ignoreArrayOrder && Array.isArray(a) && a.length && typeof a[0] === "string" | ||
? [...a].sort((aa, bb) => { | ||
if (aa < bb) return -1; | ||
if (aa > bb) return 1; | ||
return 0; | ||
}) | ||
: a; | ||
const newB = | ||
ignoreArrayOrder && Array.isArray(b) && b.length && typeof b[0] === "string" | ||
? [...b].sort((aa, bb) => { | ||
if (aa < bb) return -1; | ||
if (aa > bb) return 1; | ||
return 0; | ||
}) | ||
: b; | ||
for (const key in newA) { | ||
if (ignoreUndefined && newA[key] === undefined && newB[key] === undefined) continue; | ||
if (!(key in newB)) { | ||
console.log("======================================"); | ||
console.dir(a, { depth: 4 }); | ||
console.dir(b, { depth: 4 }); | ||
console.dir(newA, { depth: 4 }); | ||
console.dir(newB, { depth: 4 }); | ||
return false; | ||
} | ||
if (typeof a[key] === "object" && typeof b[key] === "object") { | ||
if (!this.deepEquals(a[key], b[key], ignoreUndefined)) return false; | ||
} else if (a[key] !== b[key]) { | ||
if (typeof newA[key] === "object" && typeof newB[key] === "object") { | ||
if (!this.deepEquals(newA[key], newB[key], { ignoreUndefined, ignoreArrayOrder })) return false; | ||
} else if (newA[key] !== newB[key]) { | ||
console.log("======================================"); | ||
console.dir(a[key], { depth: 4 }); | ||
console.dir(a, { depth: 4 }); | ||
console.dir(b[key], { depth: 4 }); | ||
console.dir(b, { depth: 4 }); | ||
console.dir(newA[key], { depth: 4 }); | ||
console.dir(newA, { depth: 4 }); | ||
console.dir(newB[key], { depth: 4 }); | ||
console.dir(newB, { depth: 4 }); | ||
return false; | ||
@@ -138,2 +162,3 @@ } | ||
} | ||
/* eslint-enable no-console */ | ||
@@ -155,1 +180,15 @@ /** | ||
} | ||
export interface DeepEqualsOptions { | ||
/** | ||
* Whether to ignore undefined properties. | ||
* @default true | ||
*/ | ||
ignoreUndefined?: boolean; | ||
/** | ||
* Whether to ignore the order of the items in arrays | ||
* @default true | ||
*/ | ||
ignoreArrayOrder?: boolean; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
915896
16443