Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

utilsac

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

utilsac - npm Package Compare versions

Comparing version 12.0.1 to 12.1.0

5

changelog.md
# Changelog
## 12.1.0
add
* deepEqualAdded
## 12.0.0

@@ -4,0 +9,0 @@

97

deep.js

@@ -192,6 +192,5 @@ export {

* Work with all primitive types like Number, String, Big Int.
* It also Object, Array, Date and Regex
* It also works when nested structure contains object and array
* @param {Object} obj1 can be either an object or array
* @param {Object} obj2 can be either an object or array
* @param {Object} a can be either an object or array
* @param {Object} b can be either an object or array
* @returns {Boolean}

@@ -204,7 +203,3 @@ */

if (Array.isArray(a)) {
if (!Array.isArray(b)) {
return false;
}
if (Array.isArray(a) && Array.isArray(b)) {
if (a.length !== b.length) {

@@ -214,4 +209,4 @@ return false;

return a.every((value, i) => {
return deepEqual(value, b[i]);
return a.every((value, index) => {
return deepEqual(value, b[index]);
});

@@ -230,10 +225,84 @@ }

}
return false;
};
const deepEqualAdded = (a, b) => {
throw `not yet implemented`;
};
const isObject = x => {
return typeof x === `object` && x !== null;
};
const validateArray = (a,b) => {
if (a === null && b === null) {
return false;
}
if (a.length !== b.length) {
return false;
}
return a.every((value, index) => {
return deepEqualAdded(value, b[index]);
});
};
/**
* Determines whether two objects are equal. Works on nested structures.
* Work with all primitive types like Number, String, Big Int.
* It also Object, Array, Date and Regex
* It also works when nested structure contains object and array
* @param {Object} a can be either an object or array
* @param {Object} b can be either an object or array
* @returns {Boolean}
*/
const deepEqualAdded = (a, b) => {
if (a === b) {
return true;
}
if (a instanceof Date && b instanceof Date) {
return deepEqualAdded(a.getTime(), b.getTime());
}
if (a instanceof RegExp && b instanceof RegExp) {
return new RegExp(a).toString() === new RegExp(b).toString();
}
if (Array.isArray(a) && Array.isArray(b)) {
return validateArray(a, b);
}
if ((a instanceof Uint8Array && b instanceof Uint8Array)
|| (a instanceof Uint16Array && b instanceof Uint16Array)
|| (a instanceof Set && b instanceof Set)) {
const arr1 = Array.from(a);
const arr2 = Array.from(b);
return validateArray(arr1, arr2);
}
if (a instanceof Map && b instanceof Map) {
const keysA = a.keys();
const keysB = b.keys();
if (keysA.length !== keysB.length) {
return false;
}
for (const key of keysA) {
if (!b.has(key) || !deepEqualAdded(a.get(key), b.get(key))) {
return false;
}
}
return true;
}
if (isObject(a) && isObject(b)) {
const keysA = Object.keys(a);
const keysB = Object.keys(b);
return (
deepEqualAdded(keysA, keysB) &&
keysA.every(key => {
return deepEqualAdded(a[key], b[key]);
})
);
}
return false;
};

12

package.json
{
"name": "utilsac",
"version": "12.0.1",
"version": "12.1.0",
"description": "Utility functions",

@@ -28,3 +28,7 @@ "type": "module",

"assign",
"memoize"
"memoize",
"type",
"cast",
"eval",
"global"
],

@@ -44,4 +48,2 @@ "license": "CC0-1.0",

"browser": true
},
"rules": {
}

@@ -54,3 +56,3 @@ },

"devDependencies": {
"ava": "^2.2.0",
"ava": "^2.4.0",
"eslint": "^6.5.1",

@@ -57,0 +59,0 @@ "eslint-config-red": "^1.4.1",

@@ -37,2 +37,3 @@ # Utility functions

deepEqual,
deepEqualAdded,
} from "utilsac/deep.js";

@@ -39,0 +40,0 @@ ```

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc