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

deep-eq

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-eq - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

19

index.js

@@ -17,5 +17,18 @@ const prettyFormat = require('pretty-format');

const leftDiff = (keyStr, v2) => `${chalk.bold.red('\n → ' + keyStr)}: ${chalk.magentaBright(format(v2))}`;
const rightDiff = (keyStr, v1) => `${chalk.bold.red('\n ← ' + keyStr)}: ${chalk.magenta(format(v1))}`;
const bothDiff = (keyStr, v1, v2) => `${chalk.bold.red('\n ↔ ' + keyStr)}: ${chalk.magenta(format(v1))} !== ${chalk.magentaBright(format(v2))}`;
const deepEqual = (o1, o2) => {
const diffs = [];
const deepEq = (o1, o2, path = []) => {
const o1IsObj = typeof o1 === 'object' && o1 !== null;
const o2IsObj = typeof o2 === 'object' && o2 !== null;
if (!o1IsObj || !o2IsObj) {
if (o1 !== o2) {
diffs.push(bothDiff(path.join('.'), o1, o2));
}
return;
}
const keys = new Set(Object.keys(o1).concat(Object.keys(o2)));

@@ -28,9 +41,9 @@ keys.forEach(key => {

} else if (v1 === undefined) {
diffs.push(`${chalk.bold.red('\n → ' + keyStr)}: ${chalk.magentaBright(format(v2))}`);
diffs.push(leftDiff(keyStr, v2));
} else if (v2 === undefined) {
diffs.push(`${chalk.bold.red('\n ← ' + keyStr)}: ${chalk.magenta(format(v1))}`);
diffs.push(rightDiff(keyStr, v1));
} else if (v1 && typeof v1 === 'object' && v2 && typeof v2 === 'object') {
deepEq(v1, v2, path.concat(key));
} else if (v1 !== v2) {
diffs.push(`${chalk.bold.red('\n ↔ ' + keyStr)}: ${chalk.magenta(format(v1))} !== ${chalk.magentaBright(format(v2))}`);
diffs.push(bothDiff(keyStr, v1, v2));
}

@@ -37,0 +50,0 @@ });

5

package.json
{
"name": "deep-eq",
"version": "1.1.2",
"version": "1.2.0",
"description": "deepEqual assertion with pretty diff",

@@ -36,4 +36,5 @@ "main": "index.js",

"codecov": "^3.0.0",
"nyc": "^11.3.0"
"nyc": "^11.3.0",
"strip-ansi": "^4.0.0"
}
}

@@ -0,4 +1,29 @@

const strip = require('strip-ansi');
const eq = require('.');
try {
eq(null, undefined);
} catch (e){
console.assert(strip(e.message).includes('null !== undefined'));
}
try {
eq(null, 'lol');
} catch (e){
console.assert(strip(e.message).includes(`null !== "lol"`));
}
try {
eq('foo', 'lol');
} catch (e){
console.assert(strip(e.message).includes(`"foo" !== "lol"`));
}
try {
eq('lol', 'lol');
} catch (e){
console.assert(false);
}
try {
eq({

@@ -35,5 +60,8 @@ foo: {

} catch(e) { // todo full assert with chalk
console.assert(e.message.includes('foo.bar.qux.lolcat.bip.yup'));
console.assert(e.message.includes('56.3'));
console.error(e);
console.assert(strip(e.message).includes(` ↔ foo.bar.qux.lolcat.bip.yup: 56.3 !== 56
← foo.bar.qux.mlop: Object {}
→ foo.bar.qux.mlep: Object {
"cool": "tes",
"flip": 878.964,
}`));
}
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