UNPKG

corde

Version:

A simple library for Discord bot tests

58 lines (45 loc) 1.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true, }); exports.deepEqual = void 0; const isNullOrUndefined_1 = require("./isNullOrUndefined"); const typeOf_1 = require("./typeOf"); function deepEqual(obj1, obj2) { if ( (0, isNullOrUndefined_1.isNullOrUndefined)(obj1) && (0, isNullOrUndefined_1.isNullOrUndefined)(obj2) ) { return true; } if ( ((0, isNullOrUndefined_1.isNullOrUndefined)(obj1) && !(0, isNullOrUndefined_1.isNullOrUndefined)(obj2)) || ((0, isNullOrUndefined_1.isNullOrUndefined)(obj2) && !(0, isNullOrUndefined_1.isNullOrUndefined)(obj1)) ) { return false; } if ((0, typeOf_1.typeOf)(obj1) !== "object" && typeof obj2 !== "object") { return obj1 === obj2; } const obj1Properties = Object.getOwnPropertyNames(obj1); const obj2Properties = Object.getOwnPropertyNames(obj2); if (obj1Properties.length !== obj2Properties.length) { return false; } for (const prop of obj1Properties) { if (typeof obj1[prop] === "object") { const newSubObj1 = obj1[prop]; const newSubObj2 = obj2[prop]; const areEqual = deepEqual(newSubObj1, newSubObj2); if (!areEqual) { return false; } } else if (obj1[prop] !== obj2[prop]) { return false; } } return true; } exports.deepEqual = deepEqual;