New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

microdiff

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microdiff - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

11

dist/index.d.ts
interface Difference {
type: "CREATE" | "REMOVE" | "CHANGE";
path: string[];
value?: any;
type: "CREATE" | "REMOVE" | "CHANGE";
path: string[];
value?: any;
}
export default function diff(obj: Record<string, any> | any[], newObj: Record<string, any> | any[]): Difference[];
export default function diff(
obj: Record<string, any> | any[],
newObj: Record<string, any> | any[]
): Difference[];
export {};
export default function diff(obj, newObj) {
let diffs = [];
for (const key in obj) {
if (!(key in newObj)) {
diffs.push({
type: "REMOVE",
path: [key],
});
}
else if (obj[key] && typeof obj[key] === "object") {
const nestedDiffs = diff(obj[key], newObj[key]);
diffs.push(...nestedDiffs.map((difference) => {
difference.path.unshift(key);
return difference;
}));
}
else if (obj[key] !== newObj[key]) {
diffs.push({
path: [key],
type: "CHANGE",
value: newObj[key],
});
}
}
for (const key in newObj) {
if (!(key in obj)) {
diffs.push({
type: "CREATE",
path: [key],
value: newObj[key],
});
}
}
return diffs;
let diffs = [];
for (const key in obj) {
if (!(key in newObj)) {
diffs.push({
type: "REMOVE",
path: [key],
});
} else if (
obj[key] &&
typeof obj[key] === "object" &&
!(obj[key] instanceof Date)
) {
const nestedDiffs = diff(obj[key], newObj[key]);
diffs.push(
...nestedDiffs.map((difference) => {
difference.path.unshift(key);
return difference;
})
);
} else if (
obj[key] !== newObj[key] &&
!(
obj[key] instanceof Date &&
newObj[key] instanceof Date &&
+obj[key] === +newObj[key]
)
) {
diffs.push({
path: [key],
type: "CHANGE",
value: newObj[key],
});
}
}
for (const key in newObj) {
if (!(key in obj)) {
diffs.push({
type: "CREATE",
path: [key],
value: newObj[key],
});
}
}
return diffs;
}
{
"name": "microdiff",
"version": "1.0.0",
"version": "1.0.1",
"description": "Small, fast, zero dependency deep object and array comparison",

@@ -20,2 +20,4 @@ "main": "./dist/index.js",

"deep-object-diff": "^1.1.0",
"diff": "^5.0.0",
"picocolors": "^1.0.0",
"prettier": "^2.4.1",

@@ -33,7 +35,7 @@ "typescript": "^4.4.4",

"scripts": {
"build": "tsc",
"test": "tsc && uvu tests",
"bench": "tsc && node bench.js",
"prepublish": "tsc"
"build": "tsc && prettier -w dist/*",
"test": "npm run build && uvu tests",
"bench": "npm run build && node bench.js",
"prepublish": "npm run build"
}
}
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