@savks/not-need-lodash
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -1,8 +0,2 @@ | ||
/*! | ||
* Check if two objects or arrays are equal | ||
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com | ||
* @param {*} obj1 The first item | ||
* @param {*} obj2 The second item | ||
* @return {Boolean} Returns true if they're equal in value | ||
*/ | ||
export default function isEqual(obj1: any, obj2: any): boolean; | ||
import { dequal } from 'dequal'; | ||
export default dequal; |
@@ -1,70 +0,3 @@ | ||
/*! | ||
* Check if two objects or arrays are equal | ||
* (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com | ||
* @param {*} obj1 The first item | ||
* @param {*} obj2 The second item | ||
* @return {Boolean} Returns true if they're equal in value | ||
*/ | ||
export default function isEqual(obj1, obj2) { | ||
/** | ||
* More accurately check the type of a JavaScript object | ||
* @param {Object} obj The object | ||
* @return {String} The object type | ||
*/ | ||
function getType(obj) { | ||
return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(); | ||
} | ||
function areArraysEqual() { | ||
// Check length | ||
if (obj1.length !== obj2.length) { | ||
return false; | ||
} | ||
// Check each item in the array | ||
for (let i = 0; i < obj1.length; i++) { | ||
if (!isEqual(obj1[i], obj2[i])) { | ||
return false; | ||
} | ||
} | ||
// If no errors, return true | ||
return true; | ||
} | ||
function areObjectsEqual() { | ||
if (Object.keys(obj1).length !== Object.keys(obj2).length) { | ||
return false; | ||
} | ||
// Check each item in the object | ||
for (const key in obj1) { | ||
if (Object.prototype.hasOwnProperty.call(obj1, key)) { | ||
if (!isEqual(obj1[key], obj2[key])) { | ||
return false; | ||
} | ||
} | ||
} | ||
// If no errors, return true | ||
return true; | ||
} | ||
function areFunctionsEqual() { | ||
return obj1.toString() === obj2.toString(); | ||
} | ||
function arePrimitivesEqual() { | ||
return obj1 === obj2; | ||
} | ||
// Get the object type | ||
const type = getType(obj1); | ||
// If the two items are not the same type, return false | ||
if (type !== getType(obj2)) { | ||
return false; | ||
} | ||
// Compare based on type | ||
if (type === 'array') { | ||
return areArraysEqual(); | ||
} | ||
if (type === 'object') { | ||
return areObjectsEqual(); | ||
} | ||
if (type === 'function') { | ||
return areFunctionsEqual(); | ||
} | ||
return arePrimitivesEqual(); | ||
} | ||
import { dequal } from 'dequal'; | ||
export default dequal; | ||
//# sourceMappingURL=isEqual.js.map |
{ | ||
"name": "@savks/not-need-lodash", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "Lodash functions analogs", | ||
@@ -57,3 +57,6 @@ "license": "MIT", | ||
} | ||
}, | ||
"dependencies": { | ||
"dequal": "^2.0.3" | ||
} | ||
} |
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
8526
1
81
+ Addeddequal@^2.0.3
+ Addeddequal@2.0.3(transitive)